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 | fd2b94a | 2021-12-08 13:05:17 +0200 | [diff] [blame] | 39 | #include "display/intel_display_trace.h" |
Jani Nikula | 1d455f8 | 2019-08-06 14:39:33 +0300 | [diff] [blame] | 40 | #include "display/intel_display_types.h" |
Imre Deak | 0f2922e | 2021-10-20 22:51:33 +0300 | [diff] [blame] | 41 | #include "display/intel_fb.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 42 | #include "display/intel_fbc.h" |
| 43 | #include "display/intel_sprite.h" |
Dave Airlie | 46d12f9 | 2021-02-05 16:48:36 +0200 | [diff] [blame] | 44 | #include "display/skl_universal_plane.h" |
Jani Nikula | df0566a | 2019-06-13 11:44:16 +0300 | [diff] [blame] | 45 | |
Andi Shyti | 0dc3c56 | 2019-10-20 19:41:39 +0100 | [diff] [blame] | 46 | #include "gt/intel_llc.h" |
| 47 | |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 48 | #include "i915_drv.h" |
Jani Nikula | a10510a | 2020-02-27 19:00:47 +0200 | [diff] [blame] | 49 | #include "i915_fixed.h" |
Jani Nikula | 440e2b3 | 2019-04-29 15:29:27 +0300 | [diff] [blame] | 50 | #include "i915_irq.h" |
Jani Nikula | 4dd4375 | 2021-10-14 13:28:57 +0300 | [diff] [blame] | 51 | #include "intel_pcode.h" |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 52 | #include "intel_pm.h" |
Jani Nikula | 1eecf31e | 2021-10-13 13:11:59 +0300 | [diff] [blame] | 53 | #include "vlv_sideband.h" |
Daniel Vetter | eb48eb0 | 2012-04-26 23:28:12 +0200 | [diff] [blame] | 54 | #include "../../../platform/x86/intel_ips.h" |
Eugeni Dodonov | 85208be | 2012-04-16 22:20:34 -0300 | [diff] [blame] | 55 | |
Jani Nikula | a10510a | 2020-02-27 19:00:47 +0200 | [diff] [blame] | 56 | /* Stores plane specific WM parameters */ |
| 57 | struct skl_wm_params { |
| 58 | bool x_tiled, y_tiled; |
| 59 | bool rc_surface; |
| 60 | bool is_planar; |
| 61 | u32 width; |
| 62 | u8 cpp; |
| 63 | u32 plane_pixel_rate; |
| 64 | u32 y_min_scanlines; |
| 65 | u32 plane_bytes_per_line; |
| 66 | uint_fixed_16_16_t plane_blocks_per_line; |
| 67 | uint_fixed_16_16_t y_tile_minimum; |
| 68 | u32 linetime_us; |
| 69 | u32 dbuf_block_size; |
| 70 | }; |
| 71 | |
| 72 | /* used in computing the new watermarks state */ |
| 73 | struct intel_wm_config { |
| 74 | unsigned int num_pipes_active; |
| 75 | bool sprites_enabled; |
| 76 | bool sprites_scaled; |
| 77 | }; |
| 78 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 79 | static void gen9_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 80 | { |
Ville Syrjälä | b2d73de | 2021-09-30 22:09:42 +0300 | [diff] [blame] | 81 | enum pipe pipe; |
| 82 | |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 83 | if (HAS_LLC(dev_priv)) { |
| 84 | /* |
| 85 | * WaCompressedResourceDisplayNewHashMode:skl,kbl |
Lucas De Marchi | e0403cb | 2017-12-05 11:01:17 -0800 | [diff] [blame] | 86 | * Display WA #0390: skl,kbl |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 87 | * |
| 88 | * Must match Sampler, Pixel Back End, and Media. See |
| 89 | * WaCompressedResourceSamplerPbeMediaNewHashMode. |
| 90 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 91 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 92 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR1_1) | |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 93 | SKL_DE_COMPRESSED_HASH_MODE); |
| 94 | } |
| 95 | |
Ville Syrjälä | b2d73de | 2021-09-30 22:09:42 +0300 | [diff] [blame] | 96 | for_each_pipe(dev_priv, pipe) { |
| 97 | /* |
| 98 | * "Plane N strech max must be programmed to 11b (x1) |
| 99 | * when Async flips are enabled on that plane." |
| 100 | */ |
| 101 | if (!IS_GEMINILAKE(dev_priv) && intel_vtd_active()) |
| 102 | intel_uncore_rmw(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe), |
| 103 | SKL_PLANE1_STRETCH_MAX_MASK, SKL_PLANE1_STRETCH_MAX_X1); |
| 104 | } |
| 105 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 106 | /* 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] | 107 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 108 | 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] | 109 | |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 110 | /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 111 | intel_uncore_write(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1, |
| 112 | intel_uncore_read(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM); |
Mika Kuoppala | 0f78dee | 2016-06-07 17:19:16 +0300 | [diff] [blame] | 113 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 114 | /* |
| 115 | * WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl |
| 116 | * Display WA #0859: skl,bxt,kbl,glk,cfl |
| 117 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 118 | 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] | 119 | DISP_FBC_MEMORY_WAKE); |
Mika Kuoppala | b033bb6 | 2016-06-07 17:19:04 +0300 | [diff] [blame] | 120 | } |
| 121 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 122 | static void bxt_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 123 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 124 | gen9_init_clock_gating(dev_priv); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 125 | |
Nick Hoath | a754615 | 2015-06-29 14:07:32 +0100 | [diff] [blame] | 126 | /* WaDisableSDEUnitClockGating:bxt */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 127 | 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] | 128 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
| 129 | |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 130 | /* |
| 131 | * FIXME: |
Ben Widawsky | 868434c | 2015-03-11 10:49:32 +0200 | [diff] [blame] | 132 | * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only. |
Imre Deak | 32608ca | 2015-03-11 11:10:27 +0200 | [diff] [blame] | 133 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 134 | 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] | 135 | GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ); |
Imre Deak | d965e7ac | 2015-12-01 10:23:52 +0200 | [diff] [blame] | 136 | |
| 137 | /* |
| 138 | * Wa: Backlight PWM may stop in the asserted state, causing backlight |
| 139 | * to stay fully on. |
| 140 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 141 | 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] | 142 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
Uma Shankar | 1d85a29 | 2018-08-07 21:15:35 +0530 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * Lower the display internal timeout. |
| 146 | * This is needed to avoid any hard hangs when DSI port PLL |
| 147 | * is off and a MMIO access is attempted by any privilege |
| 148 | * application, using batch buffers or any other means. |
| 149 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 150 | 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] | 151 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 152 | /* |
| 153 | * WaFbcTurnOffFbcWatermark:bxt |
| 154 | * Display WA #0562: bxt |
| 155 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 156 | 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] | 157 | DISP_FBC_WM_DIS); |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 158 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 159 | /* |
| 160 | * WaFbcHighMemBwCorruptionAvoidance:bxt |
| 161 | * Display WA #0883: bxt |
| 162 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 163 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Ville Syrjälä | 73ab6ec | 2021-11-04 16:45:15 +0200 | [diff] [blame] | 164 | DPFC_DISABLE_DUMMY0); |
Imre Deak | a82abe4 | 2015-03-27 14:00:04 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 167 | static void glk_init_clock_gating(struct drm_i915_private *dev_priv) |
| 168 | { |
| 169 | gen9_init_clock_gating(dev_priv); |
| 170 | |
| 171 | /* |
| 172 | * WaDisablePWMClockGating:glk |
| 173 | * Backlight PWM may stop in the asserted state, causing backlight |
| 174 | * to stay fully on. |
| 175 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 176 | 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] | 177 | PWM1_GATING_DIS | PWM2_GATING_DIS); |
| 178 | } |
| 179 | |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 180 | static void pnv_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 181 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 182 | u32 tmp; |
| 183 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 184 | tmp = intel_uncore_read(&dev_priv->uncore, CLKCFG); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 185 | |
| 186 | switch (tmp & CLKCFG_FSB_MASK) { |
| 187 | case CLKCFG_FSB_533: |
| 188 | dev_priv->fsb_freq = 533; /* 133*4 */ |
| 189 | break; |
| 190 | case CLKCFG_FSB_800: |
| 191 | dev_priv->fsb_freq = 800; /* 200*4 */ |
| 192 | break; |
| 193 | case CLKCFG_FSB_667: |
| 194 | dev_priv->fsb_freq = 667; /* 167*4 */ |
| 195 | break; |
| 196 | case CLKCFG_FSB_400: |
| 197 | dev_priv->fsb_freq = 400; /* 100*4 */ |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | switch (tmp & CLKCFG_MEM_MASK) { |
| 202 | case CLKCFG_MEM_533: |
| 203 | dev_priv->mem_freq = 533; |
| 204 | break; |
| 205 | case CLKCFG_MEM_667: |
| 206 | dev_priv->mem_freq = 667; |
| 207 | break; |
| 208 | case CLKCFG_MEM_800: |
| 209 | dev_priv->mem_freq = 800; |
| 210 | break; |
| 211 | } |
| 212 | |
| 213 | /* detect pineview DDR3 setting */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 214 | tmp = intel_uncore_read(&dev_priv->uncore, CSHRDDR3CTL); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 215 | dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0; |
| 216 | } |
| 217 | |
Lucas De Marchi | 9eae5e2 | 2019-12-24 00:40:09 -0800 | [diff] [blame] | 218 | static void ilk_get_mem_freq(struct drm_i915_private *dev_priv) |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 219 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 220 | u16 ddrpll, csipll; |
| 221 | |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 222 | ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1); |
| 223 | csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 224 | |
| 225 | switch (ddrpll & 0xff) { |
| 226 | case 0xc: |
| 227 | dev_priv->mem_freq = 800; |
| 228 | break; |
| 229 | case 0x10: |
| 230 | dev_priv->mem_freq = 1066; |
| 231 | break; |
| 232 | case 0x14: |
| 233 | dev_priv->mem_freq = 1333; |
| 234 | break; |
| 235 | case 0x18: |
| 236 | dev_priv->mem_freq = 1600; |
| 237 | break; |
| 238 | default: |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 239 | drm_dbg(&dev_priv->drm, "unknown memory frequency 0x%02x\n", |
| 240 | ddrpll & 0xff); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 241 | dev_priv->mem_freq = 0; |
| 242 | break; |
| 243 | } |
| 244 | |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 245 | switch (csipll & 0x3ff) { |
| 246 | case 0x00c: |
| 247 | dev_priv->fsb_freq = 3200; |
| 248 | break; |
| 249 | case 0x00e: |
| 250 | dev_priv->fsb_freq = 3733; |
| 251 | break; |
| 252 | case 0x010: |
| 253 | dev_priv->fsb_freq = 4266; |
| 254 | break; |
| 255 | case 0x012: |
| 256 | dev_priv->fsb_freq = 4800; |
| 257 | break; |
| 258 | case 0x014: |
| 259 | dev_priv->fsb_freq = 5333; |
| 260 | break; |
| 261 | case 0x016: |
| 262 | dev_priv->fsb_freq = 5866; |
| 263 | break; |
| 264 | case 0x018: |
| 265 | dev_priv->fsb_freq = 6400; |
| 266 | break; |
| 267 | default: |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 268 | drm_dbg(&dev_priv->drm, "unknown fsb frequency 0x%04x\n", |
| 269 | csipll & 0x3ff); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 270 | dev_priv->fsb_freq = 0; |
| 271 | break; |
| 272 | } |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 275 | static const struct cxsr_latency cxsr_latency_table[] = { |
| 276 | {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */ |
| 277 | {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */ |
| 278 | {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */ |
| 279 | {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */ |
| 280 | {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */ |
| 281 | |
| 282 | {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */ |
| 283 | {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */ |
| 284 | {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */ |
| 285 | {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */ |
| 286 | {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */ |
| 287 | |
| 288 | {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */ |
| 289 | {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */ |
| 290 | {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */ |
| 291 | {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */ |
| 292 | {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */ |
| 293 | |
| 294 | {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */ |
| 295 | {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */ |
| 296 | {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */ |
| 297 | {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */ |
| 298 | {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */ |
| 299 | |
| 300 | {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */ |
| 301 | {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */ |
| 302 | {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */ |
| 303 | {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */ |
| 304 | {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */ |
| 305 | |
| 306 | {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */ |
| 307 | {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */ |
| 308 | {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */ |
| 309 | {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */ |
| 310 | {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */ |
| 311 | }; |
| 312 | |
Tvrtko Ursulin | 44a655c | 2016-10-13 11:09:23 +0100 | [diff] [blame] | 313 | static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop, |
| 314 | bool is_ddr3, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 315 | int fsb, |
| 316 | int mem) |
| 317 | { |
| 318 | const struct cxsr_latency *latency; |
| 319 | int i; |
| 320 | |
| 321 | if (fsb == 0 || mem == 0) |
| 322 | return NULL; |
| 323 | |
| 324 | for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) { |
| 325 | latency = &cxsr_latency_table[i]; |
| 326 | if (is_desktop == latency->is_desktop && |
| 327 | is_ddr3 == latency->is_ddr3 && |
| 328 | fsb == latency->fsb_freq && mem == latency->mem_freq) |
| 329 | return latency; |
| 330 | } |
| 331 | |
| 332 | DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); |
| 333 | |
| 334 | return NULL; |
| 335 | } |
| 336 | |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 337 | static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable) |
| 338 | { |
| 339 | u32 val; |
| 340 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 341 | vlv_punit_get(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 342 | |
| 343 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 344 | if (enable) |
| 345 | val &= ~FORCE_DDR_HIGH_FREQ; |
| 346 | else |
| 347 | val |= FORCE_DDR_HIGH_FREQ; |
| 348 | val &= ~FORCE_DDR_LOW_FREQ; |
| 349 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 350 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 351 | |
| 352 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 353 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 354 | drm_err(&dev_priv->drm, |
| 355 | "timed out waiting for Punit DDR DVFS request\n"); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 356 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 357 | vlv_punit_put(dev_priv); |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 360 | static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable) |
| 361 | { |
| 362 | u32 val; |
| 363 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 364 | vlv_punit_get(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 365 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 366 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 367 | if (enable) |
| 368 | val |= DSP_MAXFIFO_PM5_ENABLE; |
| 369 | else |
| 370 | val &= ~DSP_MAXFIFO_PM5_ENABLE; |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 371 | vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 372 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 373 | vlv_punit_put(dev_priv); |
Ville Syrjälä | cfb4141 | 2015-03-05 21:19:51 +0200 | [diff] [blame] | 374 | } |
| 375 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 376 | #define FW_WM(value, plane) \ |
| 377 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK) |
| 378 | |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 379 | 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] | 380 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 381 | bool was_enabled; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 382 | u32 val; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 383 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 384 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 385 | was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF_VLV) & FW_CSPWRDWNEN; |
| 386 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0); |
| 387 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF_VLV); |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 388 | } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 389 | was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF) & FW_BLC_SELF_EN; |
| 390 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0); |
| 391 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF); |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 392 | } else if (IS_PINEVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 393 | val = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 394 | was_enabled = val & PINEVIEW_SELF_REFRESH_EN; |
| 395 | if (enable) |
| 396 | val |= PINEVIEW_SELF_REFRESH_EN; |
| 397 | else |
| 398 | val &= ~PINEVIEW_SELF_REFRESH_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 399 | intel_uncore_write(&dev_priv->uncore, DSPFW3, val); |
| 400 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW3); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 401 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 402 | 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] | 403 | val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) : |
| 404 | _MASKED_BIT_DISABLE(FW_BLC_SELF_EN); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 405 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, val); |
| 406 | intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF); |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 407 | } else if (IS_I915GM(dev_priv)) { |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 408 | /* |
| 409 | * FIXME can't find a bit like this for 915G, and |
| 410 | * and yet it does have the related watermark in |
| 411 | * FW_BLC_SELF. What's going on? |
| 412 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 413 | was_enabled = intel_uncore_read(&dev_priv->uncore, INSTPM) & INSTPM_SELF_EN; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 414 | val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) : |
| 415 | _MASKED_BIT_DISABLE(INSTPM_SELF_EN); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 416 | intel_uncore_write(&dev_priv->uncore, INSTPM, val); |
| 417 | intel_uncore_posting_read(&dev_priv->uncore, INSTPM); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 418 | } else { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 419 | return false; |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 420 | } |
| 421 | |
Ville Syrjälä | 1489bba | 2017-03-02 19:15:07 +0200 | [diff] [blame] | 422 | trace_intel_memory_cxsr(dev_priv, was_enabled, enable); |
| 423 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 424 | drm_dbg_kms(&dev_priv->drm, "memory self-refresh is %s (was %s)\n", |
| 425 | enableddisabled(enable), |
| 426 | enableddisabled(was_enabled)); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 427 | |
| 428 | return was_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 429 | } |
| 430 | |
Ville Syrjälä | 62571fc | 2017-04-21 21:14:23 +0300 | [diff] [blame] | 431 | /** |
| 432 | * intel_set_memory_cxsr - Configure CxSR state |
| 433 | * @dev_priv: i915 device |
| 434 | * @enable: Allow vs. disallow CxSR |
| 435 | * |
| 436 | * Allow or disallow the system to enter a special CxSR |
| 437 | * (C-state self refresh) state. What typically happens in CxSR mode |
| 438 | * is that several display FIFOs may get combined into a single larger |
| 439 | * FIFO for a particular plane (so called max FIFO mode) to allow the |
| 440 | * system to defer memory fetches longer, and the memory will enter |
| 441 | * self refresh. |
| 442 | * |
| 443 | * Note that enabling CxSR does not guarantee that the system enter |
| 444 | * this special mode, nor does it guarantee that the system stays |
| 445 | * in that mode once entered. So this just allows/disallows the system |
| 446 | * to autonomously utilize the CxSR mode. Other factors such as core |
| 447 | * C-states will affect when/if the system actually enters/exits the |
| 448 | * CxSR mode. |
| 449 | * |
| 450 | * Note that on VLV/CHV this actually only controls the max FIFO mode, |
| 451 | * and the system is free to enter/exit memory self refresh at any time |
| 452 | * even when the use of CxSR has been disallowed. |
| 453 | * |
| 454 | * While the system is actually in the CxSR/max FIFO mode, some plane |
| 455 | * control registers will not get latched on vblank. Thus in order to |
| 456 | * guarantee the system will respond to changes in the plane registers |
| 457 | * we must always disallow CxSR prior to making changes to those registers. |
| 458 | * Unfortunately the system will re-evaluate the CxSR conditions at |
| 459 | * frame start which happens after vblank start (which is when the plane |
| 460 | * registers would get latched), so we can't proceed with the plane update |
| 461 | * during the same frame where we disallowed CxSR. |
| 462 | * |
| 463 | * Certain platforms also have a deeper HPLL SR mode. Fortunately the |
| 464 | * HPLL SR mode depends on CxSR itself, so we don't have to hand hold |
| 465 | * the hardware w.r.t. HPLL SR when writing to plane registers. |
| 466 | * Disallowing just CxSR is sufficient. |
| 467 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 468 | 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] | 469 | { |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 470 | bool ret; |
| 471 | |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 472 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 473 | ret = _intel_set_memory_cxsr(dev_priv, enable); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 474 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 475 | dev_priv->wm.vlv.cxsr = enable; |
| 476 | else if (IS_G4X(dev_priv)) |
| 477 | dev_priv->wm.g4x.cxsr = enable; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 478 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 479 | |
| 480 | return ret; |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 481 | } |
Ville Syrjälä | fc1ac8d | 2015-03-05 21:19:52 +0200 | [diff] [blame] | 482 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 483 | /* |
| 484 | * Latency for FIFO fetches is dependent on several factors: |
| 485 | * - memory configuration (speed, channels) |
| 486 | * - chipset |
| 487 | * - current MCH state |
| 488 | * It can be fairly high in some situations, so here we assume a fairly |
| 489 | * pessimal value. It's a tradeoff between extra memory fetches (if we |
| 490 | * set this value too high, the FIFO will fetch frequently to stay full) |
| 491 | * and power consumption (set it too low to save power and we might see |
| 492 | * FIFO underruns and display "flicker"). |
| 493 | * |
| 494 | * A value of 5us seems to be a good balance; safe for very low end |
| 495 | * platforms but not overly aggressive on lower latency configs. |
| 496 | */ |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 497 | static const int pessimal_latency_ns = 5000; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 498 | |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 499 | #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \ |
| 500 | ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8)) |
| 501 | |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 502 | 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] | 503 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 504 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 505 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 506 | 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] | 507 | enum pipe pipe = crtc->pipe; |
| 508 | int sprite0_start, sprite1_start; |
Kees Cook | 2713eb4 | 2020-02-20 16:05:17 -0800 | [diff] [blame] | 509 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 510 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 511 | switch (pipe) { |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 512 | case PIPE_A: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 513 | dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
| 514 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 515 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0); |
| 516 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4); |
| 517 | break; |
| 518 | case PIPE_B: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 519 | dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
| 520 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 521 | sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8); |
| 522 | sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12); |
| 523 | break; |
| 524 | case PIPE_C: |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 525 | dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2); |
| 526 | dsparb3 = intel_uncore_read(&dev_priv->uncore, DSPARB3); |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 527 | sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16); |
| 528 | sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20); |
| 529 | break; |
| 530 | default: |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 531 | MISSING_CASE(pipe); |
| 532 | return; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 533 | } |
| 534 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 535 | fifo_state->plane[PLANE_PRIMARY] = sprite0_start; |
| 536 | fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start; |
| 537 | fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start; |
| 538 | fifo_state->plane[PLANE_CURSOR] = 63; |
Ville Syrjälä | b500472 | 2015-03-05 21:19:47 +0200 | [diff] [blame] | 539 | } |
| 540 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 541 | static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv, |
| 542 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 543 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 544 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 545 | int size; |
| 546 | |
| 547 | size = dsparb & 0x7f; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 548 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 549 | size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size; |
| 550 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 551 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 552 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 553 | |
| 554 | return size; |
| 555 | } |
| 556 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 557 | static int i830_get_fifo_size(struct drm_i915_private *dev_priv, |
| 558 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 559 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 560 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 561 | int size; |
| 562 | |
| 563 | size = dsparb & 0x1ff; |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 564 | if (i9xx_plane == PLANE_B) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 565 | size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size; |
| 566 | size >>= 1; /* Convert to cachelines */ |
| 567 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 568 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 569 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 570 | |
| 571 | return size; |
| 572 | } |
| 573 | |
Ville Syrjälä | bdaf843 | 2017-11-17 21:19:11 +0200 | [diff] [blame] | 574 | static int i845_get_fifo_size(struct drm_i915_private *dev_priv, |
| 575 | enum i9xx_plane_id i9xx_plane) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 576 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 577 | u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 578 | int size; |
| 579 | |
| 580 | size = dsparb & 0x7f; |
| 581 | size >>= 2; /* Convert to cachelines */ |
| 582 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 583 | drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n", |
| 584 | dsparb, plane_name(i9xx_plane), size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 585 | |
| 586 | return size; |
| 587 | } |
| 588 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 589 | /* Pineview has different values for various configs */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 590 | static const struct intel_watermark_params pnv_display_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 591 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 592 | .max_wm = PINEVIEW_MAX_WM, |
| 593 | .default_wm = PINEVIEW_DFT_WM, |
| 594 | .guard_size = PINEVIEW_GUARD_WM, |
| 595 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 596 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 597 | |
| 598 | static const struct intel_watermark_params pnv_display_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 599 | .fifo_size = PINEVIEW_DISPLAY_FIFO, |
| 600 | .max_wm = PINEVIEW_MAX_WM, |
| 601 | .default_wm = PINEVIEW_DFT_HPLLOFF_WM, |
| 602 | .guard_size = PINEVIEW_GUARD_WM, |
| 603 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 604 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 605 | |
| 606 | static const struct intel_watermark_params pnv_cursor_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 607 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 608 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 609 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 610 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 611 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 612 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 613 | |
| 614 | static const struct intel_watermark_params pnv_cursor_hplloff_wm = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 615 | .fifo_size = PINEVIEW_CURSOR_FIFO, |
| 616 | .max_wm = PINEVIEW_CURSOR_MAX_WM, |
| 617 | .default_wm = PINEVIEW_CURSOR_DFT_WM, |
| 618 | .guard_size = PINEVIEW_CURSOR_GUARD_WM, |
| 619 | .cacheline_size = PINEVIEW_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 620 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 621 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 622 | static const struct intel_watermark_params i965_cursor_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 623 | .fifo_size = I965_CURSOR_FIFO, |
| 624 | .max_wm = I965_CURSOR_MAX_WM, |
| 625 | .default_wm = I965_CURSOR_DFT_WM, |
| 626 | .guard_size = 2, |
| 627 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 628 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 629 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 630 | static const struct intel_watermark_params i945_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 631 | .fifo_size = I945_FIFO_SIZE, |
| 632 | .max_wm = I915_MAX_WM, |
| 633 | .default_wm = 1, |
| 634 | .guard_size = 2, |
| 635 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 636 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 637 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 638 | static const struct intel_watermark_params i915_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 639 | .fifo_size = I915_FIFO_SIZE, |
| 640 | .max_wm = I915_MAX_WM, |
| 641 | .default_wm = 1, |
| 642 | .guard_size = 2, |
| 643 | .cacheline_size = I915_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 644 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 645 | |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 646 | static const struct intel_watermark_params i830_a_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 647 | .fifo_size = I855GM_FIFO_SIZE, |
| 648 | .max_wm = I915_MAX_WM, |
| 649 | .default_wm = 1, |
| 650 | .guard_size = 2, |
| 651 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 652 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 653 | |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 654 | static const struct intel_watermark_params i830_bc_wm_info = { |
| 655 | .fifo_size = I855GM_FIFO_SIZE, |
| 656 | .max_wm = I915_MAX_WM/2, |
| 657 | .default_wm = 1, |
| 658 | .guard_size = 2, |
| 659 | .cacheline_size = I830_FIFO_LINE_SIZE, |
| 660 | }; |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 661 | |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 662 | static const struct intel_watermark_params i845_wm_info = { |
Ville Syrjälä | e0f0273 | 2014-06-05 19:15:50 +0300 | [diff] [blame] | 663 | .fifo_size = I830_FIFO_SIZE, |
| 664 | .max_wm = I915_MAX_WM, |
| 665 | .default_wm = 1, |
| 666 | .guard_size = 2, |
| 667 | .cacheline_size = I830_FIFO_LINE_SIZE, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 668 | }; |
| 669 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 670 | /** |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 671 | * intel_wm_method1 - Method 1 / "small buffer" watermark formula |
| 672 | * @pixel_rate: Pipe pixel rate in kHz |
| 673 | * @cpp: Plane bytes per pixel |
| 674 | * @latency: Memory wakeup latency in 0.1us units |
| 675 | * |
| 676 | * Compute the watermark using the method 1 or "small buffer" |
| 677 | * formula. The caller may additonally add extra cachelines |
| 678 | * to account for TLB misses and clock crossings. |
| 679 | * |
| 680 | * This method is concerned with the short term drain rate |
| 681 | * of the FIFO, ie. it does not account for blanking periods |
| 682 | * which would effectively reduce the average drain rate across |
| 683 | * a longer period. The name "small" refers to the fact the |
| 684 | * FIFO is relatively small compared to the amount of data |
| 685 | * fetched. |
| 686 | * |
| 687 | * The FIFO level vs. time graph might look something like: |
| 688 | * |
| 689 | * |\ |\ |
| 690 | * | \ | \ |
| 691 | * __---__---__ (- plane active, _ blanking) |
| 692 | * -> time |
| 693 | * |
| 694 | * or perhaps like this: |
| 695 | * |
| 696 | * |\|\ |\|\ |
| 697 | * __----__----__ (- plane active, _ blanking) |
| 698 | * -> time |
| 699 | * |
| 700 | * Returns: |
| 701 | * The watermark in bytes |
| 702 | */ |
| 703 | static unsigned int intel_wm_method1(unsigned int pixel_rate, |
| 704 | unsigned int cpp, |
| 705 | unsigned int latency) |
| 706 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 707 | u64 ret; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 708 | |
Ville Syrjälä | d492a29 | 2019-04-08 18:27:01 +0300 | [diff] [blame] | 709 | ret = mul_u32_u32(pixel_rate, cpp * latency); |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 710 | ret = DIV_ROUND_UP_ULL(ret, 10000); |
| 711 | |
| 712 | return ret; |
| 713 | } |
| 714 | |
| 715 | /** |
| 716 | * intel_wm_method2 - Method 2 / "large buffer" watermark formula |
| 717 | * @pixel_rate: Pipe pixel rate in kHz |
| 718 | * @htotal: Pipe horizontal total |
| 719 | * @width: Plane width in pixels |
| 720 | * @cpp: Plane bytes per pixel |
| 721 | * @latency: Memory wakeup latency in 0.1us units |
| 722 | * |
| 723 | * Compute the watermark using the method 2 or "large buffer" |
| 724 | * formula. The caller may additonally add extra cachelines |
| 725 | * to account for TLB misses and clock crossings. |
| 726 | * |
| 727 | * This method is concerned with the long term drain rate |
| 728 | * of the FIFO, ie. it does account for blanking periods |
| 729 | * which effectively reduce the average drain rate across |
| 730 | * a longer period. The name "large" refers to the fact the |
| 731 | * FIFO is relatively large compared to the amount of data |
| 732 | * fetched. |
| 733 | * |
| 734 | * The FIFO level vs. time graph might look something like: |
| 735 | * |
| 736 | * |\___ |\___ |
| 737 | * | \___ | \___ |
| 738 | * | \ | \ |
| 739 | * __ --__--__--__--__--__--__ (- plane active, _ blanking) |
| 740 | * -> time |
| 741 | * |
| 742 | * Returns: |
| 743 | * The watermark in bytes |
| 744 | */ |
| 745 | static unsigned int intel_wm_method2(unsigned int pixel_rate, |
| 746 | unsigned int htotal, |
| 747 | unsigned int width, |
| 748 | unsigned int cpp, |
| 749 | unsigned int latency) |
| 750 | { |
| 751 | unsigned int ret; |
| 752 | |
| 753 | /* |
| 754 | * FIXME remove once all users are computing |
| 755 | * watermarks in the correct place. |
| 756 | */ |
| 757 | if (WARN_ON_ONCE(htotal == 0)) |
| 758 | htotal = 1; |
| 759 | |
| 760 | ret = (latency * pixel_rate) / (htotal * 10000); |
| 761 | ret = (ret + 1) * width * cpp; |
| 762 | |
| 763 | return ret; |
| 764 | } |
| 765 | |
| 766 | /** |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 767 | * intel_calculate_wm - calculate watermark level |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 768 | * @pixel_rate: pixel clock |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 769 | * @wm: chip FIFO params |
Chris Wilson | 3138341 | 2018-02-14 14:03:03 +0000 | [diff] [blame] | 770 | * @fifo_size: size of the FIFO buffer |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 771 | * @cpp: bytes per pixel |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 772 | * @latency_ns: memory latency for the platform |
| 773 | * |
| 774 | * Calculate the watermark level (the level at which the display plane will |
| 775 | * start fetching from memory again). Each chip has a different display |
| 776 | * FIFO size and allocation, so the caller needs to figure that out and pass |
| 777 | * in the correct intel_watermark_params structure. |
| 778 | * |
| 779 | * As the pixel clock runs, the FIFO will be drained at a rate that depends |
| 780 | * on the pixel size. When it reaches the watermark level, it'll start |
| 781 | * fetching FIFO line sized based chunks from memory until the FIFO fills |
| 782 | * past the watermark point. If the FIFO drains completely, a FIFO underrun |
| 783 | * will occur, and a display engine hang could result. |
| 784 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 785 | static unsigned int intel_calculate_wm(int pixel_rate, |
| 786 | const struct intel_watermark_params *wm, |
| 787 | int fifo_size, int cpp, |
| 788 | unsigned int latency_ns) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 789 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 790 | int entries, wm_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 791 | |
| 792 | /* |
| 793 | * Note: we need to make sure we don't overflow for various clock & |
| 794 | * latency values. |
| 795 | * clocks go from a few thousand to several hundred thousand. |
| 796 | * latency is usually a few thousand |
| 797 | */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 798 | entries = intel_wm_method1(pixel_rate, cpp, |
| 799 | latency_ns / 100); |
| 800 | entries = DIV_ROUND_UP(entries, wm->cacheline_size) + |
| 801 | wm->guard_size; |
| 802 | DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 803 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 804 | wm_size = fifo_size - entries; |
| 805 | DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 806 | |
| 807 | /* Don't promote wm_size to unsigned... */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 808 | if (wm_size > wm->max_wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 809 | wm_size = wm->max_wm; |
| 810 | if (wm_size <= 0) |
| 811 | wm_size = wm->default_wm; |
Ville Syrjälä | d6feb19 | 2014-09-05 21:54:13 +0300 | [diff] [blame] | 812 | |
| 813 | /* |
| 814 | * Bspec seems to indicate that the value shouldn't be lower than |
| 815 | * 'burst size + 1'. Certainly 830 is quite unhappy with low values. |
| 816 | * Lets go for 8 which is the burst size since certain platforms |
| 817 | * already use a hardcoded 8 (which is what the spec says should be |
| 818 | * done). |
| 819 | */ |
| 820 | if (wm_size <= 8) |
| 821 | wm_size = 8; |
| 822 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 823 | return wm_size; |
| 824 | } |
| 825 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 826 | static bool is_disabling(int old, int new, int threshold) |
| 827 | { |
| 828 | return old >= threshold && new < threshold; |
| 829 | } |
| 830 | |
| 831 | static bool is_enabling(int old, int new, int threshold) |
| 832 | { |
| 833 | return old < threshold && new >= threshold; |
| 834 | } |
| 835 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 836 | static int intel_wm_num_levels(struct drm_i915_private *dev_priv) |
| 837 | { |
| 838 | return dev_priv->wm.max_level + 1; |
| 839 | } |
| 840 | |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 841 | static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state, |
| 842 | const struct intel_plane_state *plane_state) |
| 843 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 844 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 845 | |
| 846 | /* FIXME check the 'enable' instead */ |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 847 | if (!crtc_state->hw.active) |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 848 | return false; |
| 849 | |
| 850 | /* |
| 851 | * Treat cursor with fb as always visible since cursor updates |
| 852 | * can happen faster than the vrefresh rate, and the current |
| 853 | * watermark code doesn't handle that correctly. Cursor updates |
| 854 | * which set/clear the fb or change the cursor size are going |
| 855 | * to get throttled by intel_legacy_cursor_update() to work |
| 856 | * around this problem with the watermark code. |
| 857 | */ |
| 858 | if (plane->id == PLANE_CURSOR) |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 859 | return plane_state->hw.fb != NULL; |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 860 | else |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 861 | return plane_state->uapi.visible; |
Ville Syrjälä | 24304d81 | 2017-03-14 17:10:49 +0200 | [diff] [blame] | 862 | } |
| 863 | |
Ville Syrjälä | 04da7b9 | 2019-11-27 22:12:11 +0200 | [diff] [blame] | 864 | static bool intel_crtc_active(struct intel_crtc *crtc) |
| 865 | { |
| 866 | /* Be paranoid as we can arrive here with only partial |
| 867 | * state retrieved from the hardware during setup. |
| 868 | * |
| 869 | * We can ditch the adjusted_mode.crtc_clock check as soon |
| 870 | * as Haswell has gained clock readout/fastboot support. |
| 871 | * |
| 872 | * We can ditch the crtc->primary->state->fb check as soon as we can |
| 873 | * properly reconstruct framebuffers. |
| 874 | * |
| 875 | * FIXME: The intel_crtc->active here should be switched to |
| 876 | * crtc->state->active once we have proper CRTC states wired up |
| 877 | * for atomic. |
| 878 | */ |
| 879 | return crtc->active && crtc->base.primary->state->fb && |
| 880 | crtc->config->hw.adjusted_mode.crtc_clock; |
| 881 | } |
| 882 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 883 | 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] | 884 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 885 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 886 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 887 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 888 | if (intel_crtc_active(crtc)) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 889 | if (enabled) |
| 890 | return NULL; |
| 891 | enabled = crtc; |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | return enabled; |
| 896 | } |
| 897 | |
Dave Airlie | ef9c66a | 2021-09-29 01:57:47 +0300 | [diff] [blame] | 898 | static void pnv_update_wm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 899 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 900 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 901 | const struct cxsr_latency *latency; |
| 902 | u32 reg; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 903 | unsigned int wm; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 904 | |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 905 | latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 906 | dev_priv->is_ddr3, |
| 907 | dev_priv->fsb_freq, |
| 908 | dev_priv->mem_freq); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 909 | if (!latency) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 910 | drm_dbg_kms(&dev_priv->drm, |
| 911 | "Unknown FSB/MEM found, disable CxSR\n"); |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 912 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 913 | return; |
| 914 | } |
| 915 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 916 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 917 | if (crtc) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 918 | const struct drm_display_mode *pipe_mode = |
| 919 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 920 | const struct drm_framebuffer *fb = |
| 921 | crtc->base.primary->state->fb; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 922 | int cpp = fb->format->cpp[0]; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 923 | int clock = pipe_mode->crtc_clock; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 924 | |
| 925 | /* Display SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 926 | wm = intel_calculate_wm(clock, &pnv_display_wm, |
| 927 | pnv_display_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 928 | cpp, latency->display_sr); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 929 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 930 | reg &= ~DSPFW_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 931 | reg |= FW_WM(wm, SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 932 | intel_uncore_write(&dev_priv->uncore, DSPFW1, reg); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 933 | drm_dbg_kms(&dev_priv->drm, "DSPFW1 register is %x\n", reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 934 | |
| 935 | /* cursor SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 936 | wm = intel_calculate_wm(clock, &pnv_cursor_wm, |
| 937 | pnv_display_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 938 | 4, latency->cursor_sr); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 939 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 940 | reg &= ~DSPFW_CURSOR_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 941 | reg |= FW_WM(wm, CURSOR_SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 942 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 943 | |
| 944 | /* Display HPLL off SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 945 | wm = intel_calculate_wm(clock, &pnv_display_hplloff_wm, |
| 946 | pnv_display_hplloff_wm.fifo_size, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 947 | cpp, latency->display_hpll_disable); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 948 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 949 | reg &= ~DSPFW_HPLL_SR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 950 | reg |= FW_WM(wm, HPLL_SR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 951 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 952 | |
| 953 | /* cursor HPLL off SR */ |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 954 | wm = intel_calculate_wm(clock, &pnv_cursor_hplloff_wm, |
| 955 | pnv_display_hplloff_wm.fifo_size, |
Ville Syrjälä | 99834b1 | 2017-04-21 21:14:24 +0300 | [diff] [blame] | 956 | 4, latency->cursor_hpll_disable); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 957 | reg = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 958 | reg &= ~DSPFW_HPLL_CURSOR_MASK; |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 959 | reg |= FW_WM(wm, HPLL_CURSOR); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 960 | intel_uncore_write(&dev_priv->uncore, DSPFW3, reg); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 961 | drm_dbg_kms(&dev_priv->drm, "DSPFW3 register is %x\n", reg); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 962 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 963 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 964 | } else { |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 965 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
Ville Syrjälä | 0f95ff8 | 2017-04-21 21:14:26 +0300 | [diff] [blame] | 969 | /* |
| 970 | * Documentation says: |
| 971 | * "If the line size is small, the TLB fetches can get in the way of the |
| 972 | * data fetches, causing some lag in the pixel data return which is not |
| 973 | * accounted for in the above formulas. The following adjustment only |
| 974 | * needs to be applied if eight whole lines fit in the buffer at once. |
| 975 | * The WM is adjusted upwards by the difference between the FIFO size |
| 976 | * and the size of 8 whole lines. This adjustment is always performed |
| 977 | * in the actual pixel depth regardless of whether FBC is enabled or not." |
| 978 | */ |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 979 | 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] | 980 | { |
| 981 | int tlb_miss = fifo_size * 64 - width * cpp * 8; |
| 982 | |
| 983 | return max(0, tlb_miss); |
| 984 | } |
| 985 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 986 | static void g4x_write_wm_values(struct drm_i915_private *dev_priv, |
| 987 | const struct g4x_wm_values *wm) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 988 | { |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 989 | enum pipe pipe; |
| 990 | |
| 991 | for_each_pipe(dev_priv, pipe) |
Jani Nikula | 7794b6d | 2021-12-01 15:57:04 +0200 | [diff] [blame] | 992 | trace_g4x_wm(intel_crtc_for_pipe(dev_priv, pipe), wm); |
Ville Syrjälä | e93329a | 2017-04-21 21:14:31 +0300 | [diff] [blame] | 993 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 994 | intel_uncore_write(&dev_priv->uncore, DSPFW1, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 995 | FW_WM(wm->sr.plane, SR) | |
| 996 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 997 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 998 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 999 | intel_uncore_write(&dev_priv->uncore, DSPFW2, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1000 | (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) | |
| 1001 | FW_WM(wm->sr.fbc, FBC_SR) | |
| 1002 | FW_WM(wm->hpll.fbc, FBC_HPLL_SR) | |
| 1003 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) | |
| 1004 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1005 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1006 | intel_uncore_write(&dev_priv->uncore, DSPFW3, |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1007 | (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) | |
| 1008 | FW_WM(wm->sr.cursor, CURSOR_SR) | |
| 1009 | FW_WM(wm->hpll.cursor, HPLL_CURSOR) | |
| 1010 | FW_WM(wm->hpll.plane, HPLL_SR)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1011 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1012 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW1); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 1013 | } |
| 1014 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1015 | #define FW_WM_VLV(value, plane) \ |
| 1016 | (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV) |
| 1017 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1018 | 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] | 1019 | const struct vlv_wm_values *wm) |
| 1020 | { |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1021 | enum pipe pipe; |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1022 | |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1023 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 7794b6d | 2021-12-01 15:57:04 +0200 | [diff] [blame] | 1024 | trace_vlv_wm(intel_crtc_for_pipe(dev_priv, pipe), wm); |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 1025 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1026 | intel_uncore_write(&dev_priv->uncore, VLV_DDL(pipe), |
Ville Syrjälä | 50f4cae | 2016-11-28 19:37:15 +0200 | [diff] [blame] | 1027 | (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) | |
| 1028 | (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) | |
| 1029 | (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) | |
| 1030 | (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT)); |
| 1031 | } |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1032 | |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 1033 | /* |
| 1034 | * Zero the (unused) WM1 watermarks, and also clear all the |
| 1035 | * high order bits so that there are no out of bounds values |
| 1036 | * present in the registers during the reprogramming. |
| 1037 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1038 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, 0); |
| 1039 | intel_uncore_write(&dev_priv->uncore, DSPHOWM1, 0); |
| 1040 | intel_uncore_write(&dev_priv->uncore, DSPFW4, 0); |
| 1041 | intel_uncore_write(&dev_priv->uncore, DSPFW5, 0); |
| 1042 | intel_uncore_write(&dev_priv->uncore, DSPFW6, 0); |
Ville Syrjälä | 6fe6a7f | 2016-11-28 19:37:14 +0200 | [diff] [blame] | 1043 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1044 | intel_uncore_write(&dev_priv->uncore, DSPFW1, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1045 | FW_WM(wm->sr.plane, SR) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1046 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) | |
| 1047 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) | |
| 1048 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1049 | intel_uncore_write(&dev_priv->uncore, DSPFW2, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1050 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) | |
| 1051 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) | |
| 1052 | FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1053 | intel_uncore_write(&dev_priv->uncore, DSPFW3, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1054 | FW_WM(wm->sr.cursor, CURSOR_SR)); |
Ville Syrjälä | ae80152 | 2015-03-05 21:19:49 +0200 | [diff] [blame] | 1055 | |
| 1056 | if (IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1057 | intel_uncore_write(&dev_priv->uncore, DSPFW7_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1058 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1059 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1060 | intel_uncore_write(&dev_priv->uncore, DSPFW8_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1061 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) | |
| 1062 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1063 | intel_uncore_write(&dev_priv->uncore, DSPFW9_CHV, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1064 | FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) | |
| 1065 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1066 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1067 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1068 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) | |
| 1069 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) | |
| 1070 | FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) | |
| 1071 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1072 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1073 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1074 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1075 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1076 | 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] | 1077 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1078 | intel_uncore_write(&dev_priv->uncore, DSPFW7, |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1079 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) | |
| 1080 | FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1081 | intel_uncore_write(&dev_priv->uncore, DSPHOWM, |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1082 | FW_WM(wm->sr.plane >> 9, SR_HI) | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 1083 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) | |
| 1084 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) | |
| 1085 | FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) | |
| 1086 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) | |
| 1087 | FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) | |
| 1088 | 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] | 1089 | } |
| 1090 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 1091 | intel_uncore_posting_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 0018fda | 2015-03-05 21:19:45 +0200 | [diff] [blame] | 1092 | } |
| 1093 | |
Ville Syrjälä | 1566597 | 2015-03-10 16:16:28 +0200 | [diff] [blame] | 1094 | #undef FW_WM_VLV |
| 1095 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1096 | static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv) |
| 1097 | { |
| 1098 | /* all latencies in usec */ |
| 1099 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5; |
| 1100 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12; |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1101 | dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1102 | |
Ville Syrjälä | 79d9430 | 2017-04-21 21:14:30 +0300 | [diff] [blame] | 1103 | dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | static int g4x_plane_fifo_size(enum plane_id plane_id, int level) |
| 1107 | { |
| 1108 | /* |
| 1109 | * DSPCNTR[13] supposedly controls whether the |
| 1110 | * primary plane can use the FIFO space otherwise |
| 1111 | * reserved for the sprite plane. It's not 100% clear |
| 1112 | * what the actual FIFO size is, but it looks like we |
| 1113 | * can happily set both primary and sprite watermarks |
| 1114 | * up to 127 cachelines. So that would seem to mean |
| 1115 | * that either DSPCNTR[13] doesn't do anything, or that |
| 1116 | * the total FIFO is >= 256 cachelines in size. Either |
| 1117 | * way, we don't seem to have to worry about this |
| 1118 | * repartitioning as the maximum watermark value the |
| 1119 | * register can hold for each plane is lower than the |
| 1120 | * minimum FIFO size. |
| 1121 | */ |
| 1122 | switch (plane_id) { |
| 1123 | case PLANE_CURSOR: |
| 1124 | return 63; |
| 1125 | case PLANE_PRIMARY: |
| 1126 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 511; |
| 1127 | case PLANE_SPRITE0: |
| 1128 | return level == G4X_WM_LEVEL_NORMAL ? 127 : 0; |
| 1129 | default: |
| 1130 | MISSING_CASE(plane_id); |
| 1131 | return 0; |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | static int g4x_fbc_fifo_size(int level) |
| 1136 | { |
| 1137 | switch (level) { |
| 1138 | case G4X_WM_LEVEL_SR: |
| 1139 | return 7; |
| 1140 | case G4X_WM_LEVEL_HPLL: |
| 1141 | return 15; |
| 1142 | default: |
| 1143 | MISSING_CASE(level); |
| 1144 | return 0; |
| 1145 | } |
| 1146 | } |
| 1147 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1148 | static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state, |
| 1149 | const struct intel_plane_state *plane_state, |
| 1150 | int level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1151 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1152 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1153 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1154 | const struct drm_display_mode *pipe_mode = |
| 1155 | &crtc_state->hw.pipe_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1156 | unsigned int latency = dev_priv->wm.pri_latency[level] * 10; |
| 1157 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1158 | |
| 1159 | if (latency == 0) |
| 1160 | return USHRT_MAX; |
| 1161 | |
| 1162 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 1163 | return 0; |
| 1164 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1165 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1166 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1167 | /* |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1168 | * WaUse32BppForSRWM:ctg,elk |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1169 | * |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1170 | * The spec fails to list this restriction for the |
| 1171 | * HPLL watermark, which seems a little strange. |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1172 | * Let's use 32bpp for the HPLL watermark as well. |
| 1173 | */ |
Ville Syrjälä | 5291362 | 2021-05-14 15:57:41 +0300 | [diff] [blame] | 1174 | if (plane->id == PLANE_PRIMARY && |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1175 | level != G4X_WM_LEVEL_NORMAL) |
Ville Syrjälä | d56e823 | 2019-07-03 23:08:22 +0300 | [diff] [blame] | 1176 | cpp = max(cpp, 4u); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1177 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1178 | clock = pipe_mode->crtc_clock; |
| 1179 | htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1180 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1181 | width = drm_rect_width(&plane_state->uapi.dst); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1182 | |
| 1183 | if (plane->id == PLANE_CURSOR) { |
| 1184 | wm = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1185 | } else if (plane->id == PLANE_PRIMARY && |
| 1186 | level == G4X_WM_LEVEL_NORMAL) { |
| 1187 | wm = intel_wm_method1(clock, cpp, latency); |
| 1188 | } else { |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1189 | unsigned int small, large; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1190 | |
| 1191 | small = intel_wm_method1(clock, cpp, latency); |
| 1192 | large = intel_wm_method2(clock, htotal, width, cpp, latency); |
| 1193 | |
| 1194 | wm = min(small, large); |
| 1195 | } |
| 1196 | |
| 1197 | wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level), |
| 1198 | width, cpp); |
| 1199 | |
| 1200 | wm = DIV_ROUND_UP(wm, 64) + 2; |
| 1201 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1202 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state, |
| 1206 | int level, enum plane_id plane_id, u16 value) |
| 1207 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1208 | 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] | 1209 | bool dirty = false; |
| 1210 | |
| 1211 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1212 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1213 | |
| 1214 | dirty |= raw->plane[plane_id] != value; |
| 1215 | raw->plane[plane_id] = value; |
| 1216 | } |
| 1217 | |
| 1218 | return dirty; |
| 1219 | } |
| 1220 | |
| 1221 | static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state, |
| 1222 | int level, u16 value) |
| 1223 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1224 | 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] | 1225 | bool dirty = false; |
| 1226 | |
| 1227 | /* NORMAL level doesn't have an FBC watermark */ |
| 1228 | level = max(level, G4X_WM_LEVEL_SR); |
| 1229 | |
| 1230 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
| 1231 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1232 | |
| 1233 | dirty |= raw->fbc != value; |
| 1234 | raw->fbc = value; |
| 1235 | } |
| 1236 | |
| 1237 | return dirty; |
| 1238 | } |
| 1239 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 1240 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 1241 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1242 | u32 pri_val); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1243 | |
| 1244 | static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1245 | const struct intel_plane_state *plane_state) |
| 1246 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1247 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1248 | 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] | 1249 | int num_levels = intel_wm_num_levels(to_i915(plane->base.dev)); |
| 1250 | enum plane_id plane_id = plane->id; |
| 1251 | bool dirty = false; |
| 1252 | int level; |
| 1253 | |
| 1254 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
| 1255 | dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1256 | if (plane_id == PLANE_PRIMARY) |
| 1257 | dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0); |
| 1258 | goto out; |
| 1259 | } |
| 1260 | |
| 1261 | for (level = 0; level < num_levels; level++) { |
| 1262 | struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1263 | int wm, max_wm; |
| 1264 | |
| 1265 | wm = g4x_compute_wm(crtc_state, plane_state, level); |
| 1266 | max_wm = g4x_plane_fifo_size(plane_id, level); |
| 1267 | |
| 1268 | if (wm > max_wm) |
| 1269 | break; |
| 1270 | |
| 1271 | dirty |= raw->plane[plane_id] != wm; |
| 1272 | raw->plane[plane_id] = wm; |
| 1273 | |
| 1274 | if (plane_id != PLANE_PRIMARY || |
| 1275 | level == G4X_WM_LEVEL_NORMAL) |
| 1276 | continue; |
| 1277 | |
| 1278 | wm = ilk_compute_fbc_wm(crtc_state, plane_state, |
| 1279 | raw->plane[plane_id]); |
| 1280 | max_wm = g4x_fbc_fifo_size(level); |
| 1281 | |
| 1282 | /* |
| 1283 | * FBC wm is not mandatory as we |
| 1284 | * can always just disable its use. |
| 1285 | */ |
| 1286 | if (wm > max_wm) |
| 1287 | wm = USHRT_MAX; |
| 1288 | |
| 1289 | dirty |= raw->fbc != wm; |
| 1290 | raw->fbc = wm; |
| 1291 | } |
| 1292 | |
| 1293 | /* mark watermarks as invalid */ |
| 1294 | dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX); |
| 1295 | |
| 1296 | if (plane_id == PLANE_PRIMARY) |
| 1297 | dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 1298 | |
| 1299 | out: |
| 1300 | if (dirty) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1301 | drm_dbg_kms(&dev_priv->drm, |
| 1302 | "%s watermarks: normal=%d, SR=%d, HPLL=%d\n", |
| 1303 | plane->base.name, |
| 1304 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id], |
| 1305 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id], |
| 1306 | 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] | 1307 | |
| 1308 | if (plane_id == PLANE_PRIMARY) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1309 | drm_dbg_kms(&dev_priv->drm, |
| 1310 | "FBC watermarks: SR=%d, HPLL=%d\n", |
| 1311 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc, |
| 1312 | crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | return dirty; |
| 1316 | } |
| 1317 | |
| 1318 | static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1319 | enum plane_id plane_id, int level) |
| 1320 | { |
| 1321 | const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level]; |
| 1322 | |
| 1323 | return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level); |
| 1324 | } |
| 1325 | |
| 1326 | static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1327 | int level) |
| 1328 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1329 | 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] | 1330 | |
| 1331 | if (level > dev_priv->wm.max_level) |
| 1332 | return false; |
| 1333 | |
| 1334 | return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1335 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1336 | g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
| 1337 | } |
| 1338 | |
| 1339 | /* mark all levels starting from 'level' as invalid */ |
| 1340 | static void g4x_invalidate_wms(struct intel_crtc *crtc, |
| 1341 | struct g4x_wm_state *wm_state, int level) |
| 1342 | { |
| 1343 | if (level <= G4X_WM_LEVEL_NORMAL) { |
| 1344 | enum plane_id plane_id; |
| 1345 | |
| 1346 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1347 | wm_state->wm.plane[plane_id] = USHRT_MAX; |
| 1348 | } |
| 1349 | |
| 1350 | if (level <= G4X_WM_LEVEL_SR) { |
| 1351 | wm_state->cxsr = false; |
| 1352 | wm_state->sr.cursor = USHRT_MAX; |
| 1353 | wm_state->sr.plane = USHRT_MAX; |
| 1354 | wm_state->sr.fbc = USHRT_MAX; |
| 1355 | } |
| 1356 | |
| 1357 | if (level <= G4X_WM_LEVEL_HPLL) { |
| 1358 | wm_state->hpll_en = false; |
| 1359 | wm_state->hpll.cursor = USHRT_MAX; |
| 1360 | wm_state->hpll.plane = USHRT_MAX; |
| 1361 | wm_state->hpll.fbc = USHRT_MAX; |
| 1362 | } |
| 1363 | } |
| 1364 | |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1365 | static bool g4x_compute_fbc_en(const struct g4x_wm_state *wm_state, |
| 1366 | int level) |
| 1367 | { |
| 1368 | if (level < G4X_WM_LEVEL_SR) |
| 1369 | return false; |
| 1370 | |
| 1371 | if (level >= G4X_WM_LEVEL_SR && |
| 1372 | wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR)) |
| 1373 | return false; |
| 1374 | |
| 1375 | if (level >= G4X_WM_LEVEL_HPLL && |
| 1376 | wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL)) |
| 1377 | return false; |
| 1378 | |
| 1379 | return true; |
| 1380 | } |
| 1381 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1382 | static int g4x_compute_pipe_wm(struct intel_atomic_state *state, |
| 1383 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1384 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1385 | struct intel_crtc_state *crtc_state = |
| 1386 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1387 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 0cf771b | 2021-05-14 15:57:39 +0300 | [diff] [blame] | 1388 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1389 | const struct g4x_pipe_wm *raw; |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1390 | const struct intel_plane_state *old_plane_state; |
| 1391 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1392 | struct intel_plane *plane; |
| 1393 | enum plane_id plane_id; |
| 1394 | int i, level; |
| 1395 | unsigned int dirty = 0; |
| 1396 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1397 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1398 | old_plane_state, |
| 1399 | new_plane_state, i) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1400 | if (new_plane_state->hw.crtc != &crtc->base && |
| 1401 | old_plane_state->hw.crtc != &crtc->base) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1402 | continue; |
| 1403 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1404 | if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1405 | dirty |= BIT(plane->id); |
| 1406 | } |
| 1407 | |
| 1408 | if (!dirty) |
| 1409 | return 0; |
| 1410 | |
| 1411 | level = G4X_WM_LEVEL_NORMAL; |
| 1412 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1413 | goto out; |
| 1414 | |
| 1415 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1416 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1417 | wm_state->wm.plane[plane_id] = raw->plane[plane_id]; |
| 1418 | |
| 1419 | level = G4X_WM_LEVEL_SR; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1420 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1421 | goto out; |
| 1422 | |
| 1423 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1424 | wm_state->sr.plane = raw->plane[PLANE_PRIMARY]; |
| 1425 | wm_state->sr.cursor = raw->plane[PLANE_CURSOR]; |
| 1426 | wm_state->sr.fbc = raw->fbc; |
| 1427 | |
Ville Syrjälä | 0cf771b | 2021-05-14 15:57:39 +0300 | [diff] [blame] | 1428 | wm_state->cxsr = active_planes == BIT(PLANE_PRIMARY); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1429 | |
| 1430 | level = G4X_WM_LEVEL_HPLL; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1431 | if (!g4x_raw_crtc_wm_is_valid(crtc_state, level)) |
| 1432 | goto out; |
| 1433 | |
| 1434 | raw = &crtc_state->wm.g4x.raw[level]; |
| 1435 | wm_state->hpll.plane = raw->plane[PLANE_PRIMARY]; |
| 1436 | wm_state->hpll.cursor = raw->plane[PLANE_CURSOR]; |
| 1437 | wm_state->hpll.fbc = raw->fbc; |
| 1438 | |
| 1439 | wm_state->hpll_en = wm_state->cxsr; |
| 1440 | |
| 1441 | level++; |
| 1442 | |
| 1443 | out: |
| 1444 | if (level == G4X_WM_LEVEL_NORMAL) |
| 1445 | return -EINVAL; |
| 1446 | |
| 1447 | /* invalidate the higher levels */ |
| 1448 | g4x_invalidate_wms(crtc, wm_state, level); |
| 1449 | |
| 1450 | /* |
| 1451 | * Determine if the FBC watermark(s) can be used. IF |
| 1452 | * this isn't the case we prefer to disable the FBC |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1453 | * watermark(s) rather than disable the SR/HPLL |
| 1454 | * level(s) entirely. 'level-1' is the highest valid |
| 1455 | * level here. |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1456 | */ |
Ville Syrjälä | fd7a9d8 | 2020-04-29 13:10:33 +0300 | [diff] [blame] | 1457 | 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] | 1458 | |
| 1459 | return 0; |
| 1460 | } |
| 1461 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1462 | static int g4x_compute_intermediate_wm(struct intel_atomic_state *state, |
| 1463 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1464 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1465 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1466 | struct intel_crtc_state *new_crtc_state = |
| 1467 | intel_atomic_get_new_crtc_state(state, crtc); |
| 1468 | const struct intel_crtc_state *old_crtc_state = |
| 1469 | intel_atomic_get_old_crtc_state(state, crtc); |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1470 | struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate; |
| 1471 | const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal; |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1472 | 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] | 1473 | enum plane_id plane_id; |
| 1474 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1475 | if (!new_crtc_state->hw.active || |
| 1476 | drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) { |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1477 | *intermediate = *optimal; |
| 1478 | |
| 1479 | intermediate->cxsr = false; |
| 1480 | intermediate->hpll_en = false; |
| 1481 | goto out; |
| 1482 | } |
| 1483 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1484 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1485 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1486 | intermediate->hpll_en = optimal->hpll_en && active->hpll_en && |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1487 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1488 | intermediate->fbc_en = optimal->fbc_en && active->fbc_en; |
| 1489 | |
| 1490 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1491 | intermediate->wm.plane[plane_id] = |
| 1492 | max(optimal->wm.plane[plane_id], |
| 1493 | active->wm.plane[plane_id]); |
| 1494 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1495 | drm_WARN_ON(&dev_priv->drm, intermediate->wm.plane[plane_id] > |
| 1496 | g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1497 | } |
| 1498 | |
| 1499 | intermediate->sr.plane = max(optimal->sr.plane, |
| 1500 | active->sr.plane); |
| 1501 | intermediate->sr.cursor = max(optimal->sr.cursor, |
| 1502 | active->sr.cursor); |
| 1503 | intermediate->sr.fbc = max(optimal->sr.fbc, |
| 1504 | active->sr.fbc); |
| 1505 | |
| 1506 | intermediate->hpll.plane = max(optimal->hpll.plane, |
| 1507 | active->hpll.plane); |
| 1508 | intermediate->hpll.cursor = max(optimal->hpll.cursor, |
| 1509 | active->hpll.cursor); |
| 1510 | intermediate->hpll.fbc = max(optimal->hpll.fbc, |
| 1511 | active->hpll.fbc); |
| 1512 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1513 | drm_WARN_ON(&dev_priv->drm, |
| 1514 | (intermediate->sr.plane > |
| 1515 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) || |
| 1516 | intermediate->sr.cursor > |
| 1517 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) && |
| 1518 | intermediate->cxsr); |
| 1519 | drm_WARN_ON(&dev_priv->drm, |
| 1520 | (intermediate->sr.plane > |
| 1521 | g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) || |
| 1522 | intermediate->sr.cursor > |
| 1523 | g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) && |
| 1524 | intermediate->hpll_en); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1525 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1526 | drm_WARN_ON(&dev_priv->drm, |
| 1527 | intermediate->sr.fbc > g4x_fbc_fifo_size(1) && |
| 1528 | intermediate->fbc_en && intermediate->cxsr); |
| 1529 | drm_WARN_ON(&dev_priv->drm, |
| 1530 | intermediate->hpll.fbc > g4x_fbc_fifo_size(2) && |
| 1531 | intermediate->fbc_en && intermediate->hpll_en); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1532 | |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1533 | out: |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1534 | /* |
| 1535 | * If our intermediate WM are identical to the final WM, then we can |
| 1536 | * omit the post-vblank programming; only update if it's different. |
| 1537 | */ |
| 1538 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 248c243 | 2017-11-15 17:31:57 +0100 | [diff] [blame] | 1539 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1540 | |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | static void g4x_merge_wm(struct drm_i915_private *dev_priv, |
| 1545 | struct g4x_wm_values *wm) |
| 1546 | { |
| 1547 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1548 | int num_active_pipes = 0; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1549 | |
| 1550 | wm->cxsr = true; |
| 1551 | wm->hpll_en = true; |
| 1552 | wm->fbc_en = true; |
| 1553 | |
| 1554 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1555 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1556 | |
| 1557 | if (!crtc->active) |
| 1558 | continue; |
| 1559 | |
| 1560 | if (!wm_state->cxsr) |
| 1561 | wm->cxsr = false; |
| 1562 | if (!wm_state->hpll_en) |
| 1563 | wm->hpll_en = false; |
| 1564 | if (!wm_state->fbc_en) |
| 1565 | wm->fbc_en = false; |
| 1566 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1567 | num_active_pipes++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1568 | } |
| 1569 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 1570 | if (num_active_pipes != 1) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1571 | wm->cxsr = false; |
| 1572 | wm->hpll_en = false; |
| 1573 | wm->fbc_en = false; |
| 1574 | } |
| 1575 | |
| 1576 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 1577 | const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x; |
| 1578 | enum pipe pipe = crtc->pipe; |
| 1579 | |
| 1580 | wm->pipe[pipe] = wm_state->wm; |
| 1581 | if (crtc->active && wm->cxsr) |
| 1582 | wm->sr = wm_state->sr; |
| 1583 | if (crtc->active && wm->hpll_en) |
| 1584 | wm->hpll = wm_state->hpll; |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | static void g4x_program_watermarks(struct drm_i915_private *dev_priv) |
| 1589 | { |
| 1590 | struct g4x_wm_values *old_wm = &dev_priv->wm.g4x; |
| 1591 | struct g4x_wm_values new_wm = {}; |
| 1592 | |
| 1593 | g4x_merge_wm(dev_priv, &new_wm); |
| 1594 | |
| 1595 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
| 1596 | return; |
| 1597 | |
| 1598 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1599 | _intel_set_memory_cxsr(dev_priv, false); |
| 1600 | |
| 1601 | g4x_write_wm_values(dev_priv, &new_wm); |
| 1602 | |
| 1603 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
| 1604 | _intel_set_memory_cxsr(dev_priv, true); |
| 1605 | |
| 1606 | *old_wm = new_wm; |
| 1607 | } |
| 1608 | |
| 1609 | static void g4x_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1610 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1611 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1612 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1613 | const struct intel_crtc_state *crtc_state = |
| 1614 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1615 | |
| 1616 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 1617 | crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate; |
| 1618 | g4x_program_watermarks(dev_priv); |
| 1619 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1620 | } |
| 1621 | |
| 1622 | static void g4x_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1623 | struct intel_crtc *crtc) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1624 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 1625 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1626 | const struct intel_crtc_state *crtc_state = |
| 1627 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1628 | |
| 1629 | if (!crtc_state->wm.need_postvbl_update) |
| 1630 | return; |
| 1631 | |
| 1632 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 1633 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 1634 | g4x_program_watermarks(dev_priv); |
| 1635 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 1636 | } |
| 1637 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1638 | /* latency must be in 0.1us units. */ |
| 1639 | static unsigned int vlv_wm_method2(unsigned int pixel_rate, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1640 | unsigned int htotal, |
| 1641 | unsigned int width, |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1642 | unsigned int cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1643 | unsigned int latency) |
| 1644 | { |
| 1645 | unsigned int ret; |
| 1646 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 1647 | ret = intel_wm_method2(pixel_rate, htotal, |
| 1648 | width, cpp, latency); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1649 | ret = DIV_ROUND_UP(ret, 64); |
| 1650 | |
| 1651 | return ret; |
| 1652 | } |
| 1653 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 1654 | 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] | 1655 | { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1656 | /* all latencies in usec */ |
| 1657 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3; |
| 1658 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1659 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM2; |
| 1660 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1661 | if (IS_CHERRYVIEW(dev_priv)) { |
| 1662 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12; |
| 1663 | dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33; |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 1664 | |
| 1665 | dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1666 | } |
| 1667 | } |
| 1668 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 1669 | static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state, |
| 1670 | const struct intel_plane_state *plane_state, |
| 1671 | int level) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1672 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1673 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1674 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1675 | const struct drm_display_mode *pipe_mode = |
| 1676 | &crtc_state->hw.pipe_mode; |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1677 | unsigned int clock, htotal, cpp, width, wm; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1678 | |
| 1679 | if (dev_priv->wm.pri_latency[level] == 0) |
| 1680 | return USHRT_MAX; |
| 1681 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1682 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1683 | return 0; |
| 1684 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1685 | cpp = plane_state->hw.fb->format->cpp[0]; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 1686 | clock = pipe_mode->crtc_clock; |
| 1687 | htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | e339d67 | 2016-11-28 19:37:17 +0200 | [diff] [blame] | 1688 | width = crtc_state->pipe_src_w; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1689 | |
Ville Syrjälä | 709f3fc | 2017-03-03 17:19:26 +0200 | [diff] [blame] | 1690 | if (plane->id == PLANE_CURSOR) { |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1691 | /* |
| 1692 | * FIXME the formula gives values that are |
| 1693 | * too big for the cursor FIFO, and hence we |
| 1694 | * would never be able to use cursors. For |
| 1695 | * now just hardcode the watermark. |
| 1696 | */ |
| 1697 | wm = 63; |
| 1698 | } else { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 1699 | wm = vlv_wm_method2(clock, htotal, width, cpp, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1700 | dev_priv->wm.pri_latency[level] * 10); |
| 1701 | } |
| 1702 | |
Chris Wilson | 1a1f128 | 2017-11-07 14:03:38 +0000 | [diff] [blame] | 1703 | return min_t(unsigned int, wm, USHRT_MAX); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1704 | } |
| 1705 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1706 | static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes) |
| 1707 | { |
| 1708 | return (active_planes & (BIT(PLANE_SPRITE0) | |
| 1709 | BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1); |
| 1710 | } |
| 1711 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1712 | static int vlv_compute_fifo(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1713 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1714 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1715 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1716 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1717 | &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2]; |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 1718 | 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] | 1719 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
Ville Syrjälä | 0b14d96 | 2019-08-21 20:30:33 +0300 | [diff] [blame] | 1720 | int num_active_planes = hweight8(active_planes); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1721 | const int fifo_size = 511; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1722 | int fifo_extra, fifo_left = fifo_size; |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1723 | int sprite0_fifo_extra = 0; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1724 | unsigned int total_rate; |
| 1725 | enum plane_id plane_id; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1726 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1727 | /* |
| 1728 | * When enabling sprite0 after sprite1 has already been enabled |
| 1729 | * we tend to get an underrun unless sprite0 already has some |
| 1730 | * FIFO space allcoated. Hence we always allocate at least one |
| 1731 | * cacheline for sprite0 whenever sprite1 is enabled. |
| 1732 | * |
| 1733 | * All other plane enable sequences appear immune to this problem. |
| 1734 | */ |
| 1735 | if (vlv_need_sprite0_fifo_workaround(active_planes)) |
| 1736 | sprite0_fifo_extra = 1; |
| 1737 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1738 | total_rate = raw->plane[PLANE_PRIMARY] + |
| 1739 | raw->plane[PLANE_SPRITE0] + |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1740 | raw->plane[PLANE_SPRITE1] + |
| 1741 | sprite0_fifo_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1742 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1743 | if (total_rate > fifo_size) |
| 1744 | return -EINVAL; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1745 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1746 | if (total_rate == 0) |
| 1747 | total_rate = 1; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1748 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1749 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1750 | unsigned int rate; |
| 1751 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1752 | if ((active_planes & BIT(plane_id)) == 0) { |
| 1753 | fifo_state->plane[plane_id] = 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1754 | continue; |
| 1755 | } |
| 1756 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1757 | rate = raw->plane[plane_id]; |
| 1758 | fifo_state->plane[plane_id] = fifo_size * rate / total_rate; |
| 1759 | fifo_left -= fifo_state->plane[plane_id]; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1760 | } |
| 1761 | |
Ville Syrjälä | 1a10ae6 | 2017-03-02 19:15:03 +0200 | [diff] [blame] | 1762 | fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra; |
| 1763 | fifo_left -= sprite0_fifo_extra; |
| 1764 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1765 | fifo_state->plane[PLANE_CURSOR] = 63; |
| 1766 | |
| 1767 | fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1768 | |
| 1769 | /* spread the remainder evenly */ |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1770 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1771 | int plane_extra; |
| 1772 | |
| 1773 | if (fifo_left == 0) |
| 1774 | break; |
| 1775 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1776 | if ((active_planes & BIT(plane_id)) == 0) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1777 | continue; |
| 1778 | |
| 1779 | plane_extra = min(fifo_extra, fifo_left); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1780 | fifo_state->plane[plane_id] += plane_extra; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1781 | fifo_left -= plane_extra; |
| 1782 | } |
| 1783 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1784 | 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] | 1785 | |
| 1786 | /* give it all to the first plane if none are active */ |
| 1787 | if (active_planes == 0) { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 1788 | drm_WARN_ON(&dev_priv->drm, fifo_left != fifo_size); |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1789 | fifo_state->plane[PLANE_PRIMARY] = fifo_left; |
| 1790 | } |
| 1791 | |
| 1792 | return 0; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 1793 | } |
| 1794 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1795 | /* mark all levels starting from 'level' as invalid */ |
| 1796 | static void vlv_invalidate_wms(struct intel_crtc *crtc, |
| 1797 | struct vlv_wm_state *wm_state, int level) |
| 1798 | { |
| 1799 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1800 | |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1801 | for (; level < intel_wm_num_levels(dev_priv); level++) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1802 | enum plane_id plane_id; |
| 1803 | |
| 1804 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 1805 | wm_state->wm[level].plane[plane_id] = USHRT_MAX; |
| 1806 | |
| 1807 | wm_state->sr[level].cursor = USHRT_MAX; |
| 1808 | wm_state->sr[level].plane = USHRT_MAX; |
| 1809 | } |
| 1810 | } |
| 1811 | |
Ville Syrjälä | 26cca0e | 2016-11-28 19:37:09 +0200 | [diff] [blame] | 1812 | static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size) |
| 1813 | { |
| 1814 | if (wm > fifo_size) |
| 1815 | return USHRT_MAX; |
| 1816 | else |
| 1817 | return fifo_size - wm; |
| 1818 | } |
| 1819 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1820 | /* |
| 1821 | * Starting from 'level' set all higher |
| 1822 | * levels to 'value' in the "raw" watermarks. |
| 1823 | */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1824 | 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] | 1825 | int level, enum plane_id plane_id, u16 value) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1826 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1827 | 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] | 1828 | int num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1829 | bool dirty = false; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1830 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1831 | for (; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1832 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1833 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1834 | dirty |= raw->plane[plane_id] != value; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1835 | raw->plane[plane_id] = value; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1836 | } |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1837 | |
| 1838 | return dirty; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1839 | } |
| 1840 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1841 | static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state, |
| 1842 | const struct intel_plane_state *plane_state) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1843 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 1844 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1845 | 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] | 1846 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1847 | 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] | 1848 | int level; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1849 | bool dirty = false; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1850 | |
Ville Syrjälä | a07102f | 2017-03-03 17:19:27 +0200 | [diff] [blame] | 1851 | if (!intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1852 | dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0); |
| 1853 | goto out; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | for (level = 0; level < num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1857 | struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1858 | int wm = vlv_compute_wm_level(crtc_state, plane_state, level); |
| 1859 | int max_wm = plane_id == PLANE_CURSOR ? 63 : 511; |
| 1860 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1861 | if (wm > max_wm) |
| 1862 | break; |
| 1863 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1864 | dirty |= raw->plane[plane_id] != wm; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1865 | raw->plane[plane_id] = wm; |
| 1866 | } |
| 1867 | |
| 1868 | /* mark all higher levels as invalid */ |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1869 | 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] | 1870 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1871 | out: |
| 1872 | if (dirty) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 1873 | drm_dbg_kms(&dev_priv->drm, |
| 1874 | "%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n", |
| 1875 | plane->base.name, |
| 1876 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id], |
| 1877 | crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id], |
| 1878 | 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] | 1879 | |
| 1880 | return dirty; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1881 | } |
| 1882 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1883 | static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state, |
| 1884 | enum plane_id plane_id, int level) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1885 | { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1886 | const struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1887 | &crtc_state->wm.vlv.raw[level]; |
| 1888 | const struct vlv_fifo_state *fifo_state = |
| 1889 | &crtc_state->wm.vlv.fifo_state; |
| 1890 | |
| 1891 | return raw->plane[plane_id] <= fifo_state->plane[plane_id]; |
| 1892 | } |
| 1893 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1894 | 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] | 1895 | { |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1896 | return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) && |
| 1897 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) && |
| 1898 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) && |
| 1899 | vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1900 | } |
| 1901 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1902 | static int vlv_compute_pipe_wm(struct intel_atomic_state *state, |
| 1903 | struct intel_crtc *crtc) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1904 | { |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 1905 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 1906 | struct intel_crtc_state *crtc_state = |
| 1907 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 855c79f | 2017-03-02 19:14:54 +0200 | [diff] [blame] | 1908 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1909 | const struct vlv_fifo_state *fifo_state = |
| 1910 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | 8f27dbf | 2021-05-14 15:57:40 +0300 | [diff] [blame] | 1911 | u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR); |
| 1912 | int num_active_planes = hweight8(active_planes); |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 1913 | bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->uapi); |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1914 | const struct intel_plane_state *old_plane_state; |
| 1915 | const struct intel_plane_state *new_plane_state; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1916 | struct intel_plane *plane; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1917 | enum plane_id plane_id; |
| 1918 | int level, ret, i; |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1919 | unsigned int dirty = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1920 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1921 | for_each_oldnew_intel_plane_in_state(state, plane, |
| 1922 | old_plane_state, |
| 1923 | new_plane_state, i) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 1924 | if (new_plane_state->hw.crtc != &crtc->base && |
| 1925 | old_plane_state->hw.crtc != &crtc->base) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1926 | continue; |
| 1927 | |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1928 | if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state)) |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1929 | dirty |= BIT(plane->id); |
| 1930 | } |
| 1931 | |
| 1932 | /* |
| 1933 | * DSPARB registers may have been reset due to the |
| 1934 | * power well being turned off. Make sure we restore |
| 1935 | * them to a consistent state even if no primary/sprite |
| 1936 | * planes are initially active. |
| 1937 | */ |
| 1938 | if (needs_modeset) |
| 1939 | crtc_state->fifo_changed = true; |
| 1940 | |
| 1941 | if (!dirty) |
| 1942 | return 0; |
| 1943 | |
| 1944 | /* cursor changes don't warrant a FIFO recompute */ |
| 1945 | if (dirty & ~BIT(PLANE_CURSOR)) { |
| 1946 | const struct intel_crtc_state *old_crtc_state = |
Ville Syrjälä | 7b510451 | 2017-08-23 18:22:22 +0300 | [diff] [blame] | 1947 | intel_atomic_get_old_crtc_state(state, crtc); |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 1948 | const struct vlv_fifo_state *old_fifo_state = |
| 1949 | &old_crtc_state->wm.vlv.fifo_state; |
| 1950 | |
| 1951 | ret = vlv_compute_fifo(crtc_state); |
| 1952 | if (ret) |
| 1953 | return ret; |
| 1954 | |
| 1955 | if (needs_modeset || |
| 1956 | memcmp(old_fifo_state, fifo_state, |
| 1957 | sizeof(*fifo_state)) != 0) |
| 1958 | crtc_state->fifo_changed = true; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1959 | } |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1960 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1961 | /* initially allow all levels */ |
Ville Syrjälä | 6d5019b | 2017-04-21 21:14:20 +0300 | [diff] [blame] | 1962 | wm_state->num_levels = intel_wm_num_levels(dev_priv); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1963 | /* |
| 1964 | * Note that enabling cxsr with no primary/sprite planes |
| 1965 | * enabled can wedge the pipe. Hence we only allow cxsr |
| 1966 | * with exactly one enabled primary/sprite plane. |
| 1967 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 1968 | wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1969 | |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1970 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 1971 | const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level]; |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 1972 | 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] | 1973 | |
Ville Syrjälä | 77d14ee | 2017-04-21 21:14:18 +0300 | [diff] [blame] | 1974 | if (!vlv_raw_crtc_wm_is_valid(crtc_state, level)) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1975 | break; |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1976 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1977 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 1978 | wm_state->wm[level].plane[plane_id] = |
| 1979 | vlv_invert_wm_value(raw->plane[plane_id], |
| 1980 | fifo_state->plane[plane_id]); |
| 1981 | } |
| 1982 | |
| 1983 | wm_state->sr[level].plane = |
| 1984 | vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY], |
Ville Syrjälä | 5012e60 | 2017-03-02 19:14:56 +0200 | [diff] [blame] | 1985 | raw->plane[PLANE_SPRITE0], |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1986 | raw->plane[PLANE_SPRITE1]), |
| 1987 | sr_fifo_size); |
| 1988 | |
| 1989 | wm_state->sr[level].cursor = |
| 1990 | vlv_invert_wm_value(raw->plane[PLANE_CURSOR], |
| 1991 | 63); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1992 | } |
| 1993 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1994 | if (level == 0) |
| 1995 | return -EINVAL; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 1996 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 1997 | /* limit to only levels we can actually handle */ |
| 1998 | wm_state->num_levels = level; |
| 1999 | |
| 2000 | /* invalidate the higher levels */ |
| 2001 | vlv_invalidate_wms(crtc, wm_state, level); |
| 2002 | |
| 2003 | return 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2004 | } |
| 2005 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2006 | #define VLV_FIFO(plane, value) \ |
| 2007 | (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV) |
| 2008 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2009 | static void vlv_atomic_update_fifo(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2010 | struct intel_crtc *crtc) |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2011 | { |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2012 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2013 | struct intel_uncore *uncore = &dev_priv->uncore; |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2014 | const struct intel_crtc_state *crtc_state = |
| 2015 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 814e7f0 | 2017-03-02 19:14:55 +0200 | [diff] [blame] | 2016 | const struct vlv_fifo_state *fifo_state = |
| 2017 | &crtc_state->wm.vlv.fifo_state; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2018 | int sprite0_start, sprite1_start, fifo_size; |
Kees Cook | 2713eb4 | 2020-02-20 16:05:17 -0800 | [diff] [blame] | 2019 | u32 dsparb, dsparb2, dsparb3; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2020 | |
Ville Syrjälä | 236c48e | 2017-03-02 19:14:58 +0200 | [diff] [blame] | 2021 | if (!crtc_state->fifo_changed) |
| 2022 | return; |
| 2023 | |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 2024 | sprite0_start = fifo_state->plane[PLANE_PRIMARY]; |
| 2025 | sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start; |
| 2026 | fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start; |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2027 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 2028 | drm_WARN_ON(&dev_priv->drm, fifo_state->plane[PLANE_CURSOR] != 63); |
| 2029 | drm_WARN_ON(&dev_priv->drm, fifo_size != 511); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2030 | |
Ville Syrjälä | c137d66 | 2017-03-02 19:15:06 +0200 | [diff] [blame] | 2031 | trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size); |
| 2032 | |
Ville Syrjälä | 44e921d | 2017-03-09 17:44:34 +0200 | [diff] [blame] | 2033 | /* |
| 2034 | * uncore.lock serves a double purpose here. It allows us to |
| 2035 | * use the less expensive I915_{READ,WRITE}_FW() functions, and |
| 2036 | * it protects the DSPARB registers from getting clobbered by |
| 2037 | * parallel updates from multiple pipes. |
| 2038 | * |
| 2039 | * intel_pipe_update_start() has already disabled interrupts |
| 2040 | * for us, so a plain spin_lock() is sufficient here. |
| 2041 | */ |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2042 | spin_lock(&uncore->lock); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2043 | |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2044 | switch (crtc->pipe) { |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2045 | case PIPE_A: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2046 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2047 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2048 | |
| 2049 | dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) | |
| 2050 | VLV_FIFO(SPRITEB, 0xff)); |
| 2051 | dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) | |
| 2052 | VLV_FIFO(SPRITEB, sprite1_start)); |
| 2053 | |
| 2054 | dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) | |
| 2055 | VLV_FIFO(SPRITEB_HI, 0x1)); |
| 2056 | dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) | |
| 2057 | VLV_FIFO(SPRITEB_HI, sprite1_start >> 8)); |
| 2058 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2059 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2060 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2061 | break; |
| 2062 | case PIPE_B: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2063 | dsparb = intel_uncore_read_fw(uncore, DSPARB); |
| 2064 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2065 | |
| 2066 | dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) | |
| 2067 | VLV_FIFO(SPRITED, 0xff)); |
| 2068 | dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) | |
| 2069 | VLV_FIFO(SPRITED, sprite1_start)); |
| 2070 | |
| 2071 | dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) | |
| 2072 | VLV_FIFO(SPRITED_HI, 0xff)); |
| 2073 | dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) | |
| 2074 | VLV_FIFO(SPRITED_HI, sprite1_start >> 8)); |
| 2075 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2076 | intel_uncore_write_fw(uncore, DSPARB, dsparb); |
| 2077 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2078 | break; |
| 2079 | case PIPE_C: |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2080 | dsparb3 = intel_uncore_read_fw(uncore, DSPARB3); |
| 2081 | dsparb2 = intel_uncore_read_fw(uncore, DSPARB2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2082 | |
| 2083 | dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) | |
| 2084 | VLV_FIFO(SPRITEF, 0xff)); |
| 2085 | dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) | |
| 2086 | VLV_FIFO(SPRITEF, sprite1_start)); |
| 2087 | |
| 2088 | dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) | |
| 2089 | VLV_FIFO(SPRITEF_HI, 0xff)); |
| 2090 | dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) | |
| 2091 | VLV_FIFO(SPRITEF_HI, sprite1_start >> 8)); |
| 2092 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2093 | intel_uncore_write_fw(uncore, DSPARB3, dsparb3); |
| 2094 | intel_uncore_write_fw(uncore, DSPARB2, dsparb2); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2095 | break; |
| 2096 | default: |
| 2097 | break; |
| 2098 | } |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2099 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2100 | intel_uncore_posting_read_fw(uncore, DSPARB); |
Ville Syrjälä | 467a14d | 2016-12-05 16:13:28 +0200 | [diff] [blame] | 2101 | |
Tvrtko Ursulin | e33a4be | 2019-06-11 11:45:44 +0100 | [diff] [blame] | 2102 | spin_unlock(&uncore->lock); |
Ville Syrjälä | 54f1b6e | 2015-06-24 22:00:05 +0300 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | #undef VLV_FIFO |
| 2106 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2107 | static int vlv_compute_intermediate_wm(struct intel_atomic_state *state, |
| 2108 | struct intel_crtc *crtc) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2109 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2110 | struct intel_crtc_state *new_crtc_state = |
| 2111 | intel_atomic_get_new_crtc_state(state, crtc); |
| 2112 | const struct intel_crtc_state *old_crtc_state = |
| 2113 | intel_atomic_get_old_crtc_state(state, crtc); |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2114 | struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate; |
| 2115 | const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal; |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2116 | 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] | 2117 | int level; |
| 2118 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 2119 | if (!new_crtc_state->hw.active || |
| 2120 | drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) { |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2121 | *intermediate = *optimal; |
| 2122 | |
| 2123 | intermediate->cxsr = false; |
| 2124 | goto out; |
| 2125 | } |
| 2126 | |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2127 | intermediate->num_levels = min(optimal->num_levels, active->num_levels); |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2128 | intermediate->cxsr = optimal->cxsr && active->cxsr && |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2129 | !new_crtc_state->disable_cxsr; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2130 | |
| 2131 | for (level = 0; level < intermediate->num_levels; level++) { |
| 2132 | enum plane_id plane_id; |
| 2133 | |
| 2134 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 2135 | intermediate->wm[level].plane[plane_id] = |
| 2136 | min(optimal->wm[level].plane[plane_id], |
| 2137 | active->wm[level].plane[plane_id]); |
| 2138 | } |
| 2139 | |
| 2140 | intermediate->sr[level].plane = min(optimal->sr[level].plane, |
| 2141 | active->sr[level].plane); |
| 2142 | intermediate->sr[level].cursor = min(optimal->sr[level].cursor, |
| 2143 | active->sr[level].cursor); |
| 2144 | } |
| 2145 | |
| 2146 | vlv_invalidate_wms(crtc, intermediate, level); |
| 2147 | |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2148 | out: |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2149 | /* |
| 2150 | * If our intermediate WM are identical to the final WM, then we can |
| 2151 | * omit the post-vblank programming; only update if it's different. |
| 2152 | */ |
Ville Syrjälä | 5eeb798 | 2017-03-02 19:15:00 +0200 | [diff] [blame] | 2153 | if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0) |
Maarten Lankhorst | 5b9489c | 2017-11-15 17:31:56 +0100 | [diff] [blame] | 2154 | new_crtc_state->wm.need_postvbl_update = true; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2155 | |
| 2156 | return 0; |
| 2157 | } |
| 2158 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2159 | static void vlv_merge_wm(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2160 | struct vlv_wm_values *wm) |
| 2161 | { |
| 2162 | struct intel_crtc *crtc; |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2163 | int num_active_pipes = 0; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2164 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2165 | wm->level = dev_priv->wm.max_level; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2166 | wm->cxsr = true; |
| 2167 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2168 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2169 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2170 | |
| 2171 | if (!crtc->active) |
| 2172 | continue; |
| 2173 | |
| 2174 | if (!wm_state->cxsr) |
| 2175 | wm->cxsr = false; |
| 2176 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2177 | num_active_pipes++; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2178 | wm->level = min_t(int, wm->level, wm_state->num_levels - 1); |
| 2179 | } |
| 2180 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2181 | if (num_active_pipes != 1) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2182 | wm->cxsr = false; |
| 2183 | |
Ville Syrjälä | c08e913 | 2019-08-21 20:30:32 +0300 | [diff] [blame] | 2184 | if (num_active_pipes > 1) |
Ville Syrjälä | 6f9c784 | 2015-06-24 22:00:08 +0300 | [diff] [blame] | 2185 | wm->level = VLV_WM_LEVEL_PM2; |
| 2186 | |
Ville Syrjälä | 7c951c0 | 2016-11-28 19:37:10 +0200 | [diff] [blame] | 2187 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 7eb4941 | 2017-03-02 19:14:53 +0200 | [diff] [blame] | 2188 | const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2189 | enum pipe pipe = crtc->pipe; |
| 2190 | |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2191 | wm->pipe[pipe] = wm_state->wm[wm->level]; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2192 | if (crtc->active && wm->cxsr) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2193 | wm->sr = wm_state->sr[wm->level]; |
| 2194 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 2195 | wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2; |
| 2196 | wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2; |
| 2197 | wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2; |
| 2198 | wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2202 | static void vlv_program_watermarks(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2203 | { |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2204 | struct vlv_wm_values *old_wm = &dev_priv->wm.vlv; |
| 2205 | struct vlv_wm_values new_wm = {}; |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2206 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2207 | vlv_merge_wm(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2208 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2209 | if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0) |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2210 | return; |
| 2211 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2212 | 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] | 2213 | chv_set_memory_dvfs(dev_priv, false); |
| 2214 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2215 | 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] | 2216 | chv_set_memory_pm5(dev_priv, false); |
| 2217 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2218 | if (is_disabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2219 | _intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2220 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2221 | vlv_write_wm_values(dev_priv, &new_wm); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2222 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2223 | if (is_enabling(old_wm->cxsr, new_wm.cxsr, true)) |
Ville Syrjälä | 3d90e64 | 2016-11-28 19:37:11 +0200 | [diff] [blame] | 2224 | _intel_set_memory_cxsr(dev_priv, true); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 2225 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2226 | 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] | 2227 | chv_set_memory_pm5(dev_priv, true); |
| 2228 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2229 | 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] | 2230 | chv_set_memory_dvfs(dev_priv, true); |
| 2231 | |
Ville Syrjälä | fa292a4 | 2016-11-28 19:37:16 +0200 | [diff] [blame] | 2232 | *old_wm = new_wm; |
Ville Syrjälä | 3c2777f | 2014-06-26 17:03:06 +0300 | [diff] [blame] | 2233 | } |
| 2234 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2235 | static void vlv_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2236 | struct intel_crtc *crtc) |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2237 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2238 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 2239 | const struct intel_crtc_state *crtc_state = |
| 2240 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2241 | |
| 2242 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2243 | crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate; |
| 2244 | vlv_program_watermarks(dev_priv); |
| 2245 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2246 | } |
| 2247 | |
| 2248 | static void vlv_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2249 | struct intel_crtc *crtc) |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2250 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 2251 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 2252 | const struct intel_crtc_state *crtc_state = |
| 2253 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 2254 | |
| 2255 | if (!crtc_state->wm.need_postvbl_update) |
| 2256 | return; |
| 2257 | |
| 2258 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 2259 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 2260 | vlv_program_watermarks(dev_priv); |
| 2261 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 2262 | } |
| 2263 | |
Dave Airlie | ef9c66a | 2021-09-29 01:57:47 +0300 | [diff] [blame] | 2264 | static void i965_update_wm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2265 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2266 | struct intel_crtc *crtc; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2267 | int srwm = 1; |
| 2268 | int cursor_sr = 16; |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2269 | bool cxsr_enabled; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2270 | |
| 2271 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2272 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2273 | if (crtc) { |
| 2274 | /* self-refresh has much higher latency */ |
| 2275 | static const int sr_latency_ns = 12000; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2276 | const struct drm_display_mode *pipe_mode = |
| 2277 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2278 | const struct drm_framebuffer *fb = |
| 2279 | crtc->base.primary->state->fb; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2280 | int clock = pipe_mode->crtc_clock; |
| 2281 | int htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2282 | int hdisplay = crtc->config->pipe_src_w; |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2283 | int cpp = fb->format->cpp[0]; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2284 | int entries; |
| 2285 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2286 | entries = intel_wm_method2(clock, htotal, |
| 2287 | hdisplay, cpp, sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2288 | entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE); |
| 2289 | srwm = I965_FIFO_SIZE - entries; |
| 2290 | if (srwm < 0) |
| 2291 | srwm = 1; |
| 2292 | srwm &= 0x1ff; |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2293 | drm_dbg_kms(&dev_priv->drm, |
| 2294 | "self-refresh entries: %d, wm: %d\n", |
| 2295 | entries, srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2296 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2297 | entries = intel_wm_method2(clock, htotal, |
| 2298 | crtc->base.cursor->state->crtc_w, 4, |
| 2299 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2300 | entries = DIV_ROUND_UP(entries, |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2301 | i965_cursor_wm_info.cacheline_size) + |
| 2302 | i965_cursor_wm_info.guard_size; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2303 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2304 | cursor_sr = i965_cursor_wm_info.fifo_size - entries; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2305 | if (cursor_sr > i965_cursor_wm_info.max_wm) |
| 2306 | cursor_sr = i965_cursor_wm_info.max_wm; |
| 2307 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2308 | drm_dbg_kms(&dev_priv->drm, |
| 2309 | "self-refresh watermark: display plane %d " |
| 2310 | "cursor %d\n", srwm, cursor_sr); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2311 | |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2312 | cxsr_enabled = true; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2313 | } else { |
Imre Deak | 9858425 | 2014-06-13 14:54:20 +0300 | [diff] [blame] | 2314 | cxsr_enabled = false; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2315 | /* Turn off self refresh if both pipes are enabled */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2316 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2317 | } |
| 2318 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2319 | drm_dbg_kms(&dev_priv->drm, |
| 2320 | "Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n", |
| 2321 | srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2322 | |
| 2323 | /* 965 has limitations... */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2324 | intel_uncore_write(&dev_priv->uncore, DSPFW1, FW_WM(srwm, SR) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2325 | FW_WM(8, CURSORB) | |
| 2326 | FW_WM(8, PLANEB) | |
| 2327 | FW_WM(8, PLANEA)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2328 | intel_uncore_write(&dev_priv->uncore, DSPFW2, FW_WM(8, CURSORA) | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2329 | FW_WM(8, PLANEC_OLD)); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2330 | /* update cursor SR watermark */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2331 | 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] | 2332 | |
| 2333 | if (cxsr_enabled) |
| 2334 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2335 | } |
| 2336 | |
Ville Syrjälä | f499896 | 2015-03-10 17:02:21 +0200 | [diff] [blame] | 2337 | #undef FW_WM |
| 2338 | |
Ville Syrjälä | 927167f | 2021-12-03 13:20:28 +0200 | [diff] [blame^] | 2339 | static struct intel_crtc *intel_crtc_for_plane(struct drm_i915_private *i915, |
| 2340 | enum i9xx_plane_id i9xx_plane) |
| 2341 | { |
| 2342 | struct intel_plane *plane; |
| 2343 | |
| 2344 | for_each_intel_plane(&i915->drm, plane) { |
| 2345 | if (plane->id == PLANE_PRIMARY && |
| 2346 | plane->i9xx_plane == i9xx_plane) |
| 2347 | return intel_crtc_for_pipe(i915, plane->pipe); |
| 2348 | } |
| 2349 | |
| 2350 | return NULL; |
| 2351 | } |
| 2352 | |
Dave Airlie | ef9c66a | 2021-09-29 01:57:47 +0300 | [diff] [blame] | 2353 | static void i9xx_update_wm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2354 | { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2355 | const struct intel_watermark_params *wm_info; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2356 | u32 fwater_lo; |
| 2357 | u32 fwater_hi; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2358 | int cwm, srwm = 1; |
| 2359 | int fifo_size; |
| 2360 | int planea_wm, planeb_wm; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2361 | struct intel_crtc *crtc, *enabled = NULL; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2362 | |
Ville Syrjälä | a9097be | 2016-10-31 22:37:20 +0200 | [diff] [blame] | 2363 | if (IS_I945GM(dev_priv)) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2364 | wm_info = &i945_wm_info; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2365 | else if (DISPLAY_VER(dev_priv) != 2) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2366 | wm_info = &i915_wm_info; |
| 2367 | else |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2368 | wm_info = &i830_a_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2369 | |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 2370 | if (DISPLAY_VER(dev_priv) == 2) |
| 2371 | fifo_size = i830_get_fifo_size(dev_priv, PLANE_A); |
| 2372 | else |
| 2373 | fifo_size = i9xx_get_fifo_size(dev_priv, PLANE_A); |
Jani Nikula | f2bc451 | 2021-12-01 15:57:05 +0200 | [diff] [blame] | 2374 | crtc = intel_crtc_for_plane(dev_priv, PLANE_A); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2375 | if (intel_crtc_active(crtc)) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2376 | const struct drm_display_mode *pipe_mode = |
| 2377 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2378 | const struct drm_framebuffer *fb = |
| 2379 | crtc->base.primary->state->fb; |
| 2380 | int cpp; |
| 2381 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2382 | if (DISPLAY_VER(dev_priv) == 2) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2383 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2384 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2385 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2386 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2387 | planea_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2388 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2389 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2390 | enabled = crtc; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2391 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2392 | planea_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2393 | if (planea_wm > (long)wm_info->max_wm) |
| 2394 | planea_wm = wm_info->max_wm; |
| 2395 | } |
| 2396 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2397 | if (DISPLAY_VER(dev_priv) == 2) |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2398 | wm_info = &i830_bc_wm_info; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2399 | |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 2400 | if (DISPLAY_VER(dev_priv) == 2) |
| 2401 | fifo_size = i830_get_fifo_size(dev_priv, PLANE_B); |
| 2402 | else |
| 2403 | fifo_size = i9xx_get_fifo_size(dev_priv, PLANE_B); |
Jani Nikula | f2bc451 | 2021-12-01 15:57:05 +0200 | [diff] [blame] | 2404 | crtc = intel_crtc_for_plane(dev_priv, PLANE_B); |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2405 | if (intel_crtc_active(crtc)) { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2406 | const struct drm_display_mode *pipe_mode = |
| 2407 | &crtc->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2408 | const struct drm_framebuffer *fb = |
| 2409 | crtc->base.primary->state->fb; |
| 2410 | int cpp; |
| 2411 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2412 | if (DISPLAY_VER(dev_priv) == 2) |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2413 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2414 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2415 | cpp = fb->format->cpp[0]; |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2416 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2417 | planeb_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Chris Wilson | b9e0bda | 2012-10-22 12:32:15 +0100 | [diff] [blame] | 2418 | wm_info, fifo_size, cpp, |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2419 | pessimal_latency_ns); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2420 | if (enabled == NULL) |
| 2421 | enabled = crtc; |
| 2422 | else |
| 2423 | enabled = NULL; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2424 | } else { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2425 | planeb_wm = fifo_size - wm_info->guard_size; |
Ville Syrjälä | 9d53910 | 2014-08-15 01:21:53 +0300 | [diff] [blame] | 2426 | if (planeb_wm > (long)wm_info->max_wm) |
| 2427 | planeb_wm = wm_info->max_wm; |
| 2428 | } |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2429 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2430 | drm_dbg_kms(&dev_priv->drm, |
| 2431 | "FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2432 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2433 | if (IS_I915GM(dev_priv) && enabled) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2434 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2435 | |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2436 | obj = intel_fb_obj(enabled->base.primary->state->fb); |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2437 | |
| 2438 | /* self-refresh seems busted with untiled */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2439 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 2ab1bc9 | 2014-04-07 08:54:21 +0200 | [diff] [blame] | 2440 | enabled = NULL; |
| 2441 | } |
| 2442 | |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2443 | /* |
| 2444 | * Overlay gets an aggressive default since video jitter is bad. |
| 2445 | */ |
| 2446 | cwm = 2; |
| 2447 | |
| 2448 | /* Play safe and disable self-refresh before adjusting watermarks. */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2449 | intel_set_memory_cxsr(dev_priv, false); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2450 | |
| 2451 | /* Calc sr entries for one plane configs */ |
Ville Syrjälä | 03427fc | 2016-10-31 22:37:18 +0200 | [diff] [blame] | 2452 | if (HAS_FW_BLC(dev_priv) && enabled) { |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2453 | /* self-refresh has much higher latency */ |
| 2454 | static const int sr_latency_ns = 6000; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2455 | const struct drm_display_mode *pipe_mode = |
| 2456 | &enabled->config->hw.pipe_mode; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2457 | const struct drm_framebuffer *fb = |
| 2458 | enabled->base.primary->state->fb; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2459 | int clock = pipe_mode->crtc_clock; |
| 2460 | int htotal = pipe_mode->crtc_htotal; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2461 | int hdisplay = enabled->config->pipe_src_w; |
| 2462 | int cpp; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2463 | int entries; |
| 2464 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2465 | if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv)) |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2466 | cpp = 4; |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2467 | else |
Ville Syrjälä | 353c859 | 2016-12-14 23:30:57 +0200 | [diff] [blame] | 2468 | cpp = fb->format->cpp[0]; |
Ville Syrjälä | 2d1b505 | 2016-07-29 17:57:01 +0300 | [diff] [blame] | 2469 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2470 | entries = intel_wm_method2(clock, htotal, hdisplay, cpp, |
| 2471 | sr_latency_ns / 100); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2472 | entries = DIV_ROUND_UP(entries, wm_info->cacheline_size); |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2473 | drm_dbg_kms(&dev_priv->drm, |
| 2474 | "self-refresh entries: %d\n", entries); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2475 | srwm = wm_info->fifo_size - entries; |
| 2476 | if (srwm < 0) |
| 2477 | srwm = 1; |
| 2478 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 2479 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2480 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2481 | FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); |
Ville Syrjälä | acb9135 | 2016-07-29 17:57:02 +0300 | [diff] [blame] | 2482 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2483 | intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, srwm & 0x3f); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2484 | } |
| 2485 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2486 | drm_dbg_kms(&dev_priv->drm, |
| 2487 | "Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", |
| 2488 | planea_wm, planeb_wm, cwm, srwm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2489 | |
| 2490 | fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f); |
| 2491 | fwater_hi = (cwm & 0x1f); |
| 2492 | |
| 2493 | /* Set request length to 8 cachelines per fetch */ |
| 2494 | fwater_lo = fwater_lo | (1 << 24) | (1 << 8); |
| 2495 | fwater_hi = fwater_hi | (1 << 8); |
| 2496 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2497 | intel_uncore_write(&dev_priv->uncore, FW_BLC, fwater_lo); |
| 2498 | intel_uncore_write(&dev_priv->uncore, FW_BLC2, fwater_hi); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2499 | |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 2500 | if (enabled) |
| 2501 | intel_set_memory_cxsr(dev_priv, true); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2502 | } |
| 2503 | |
Dave Airlie | ef9c66a | 2021-09-29 01:57:47 +0300 | [diff] [blame] | 2504 | static void i845_update_wm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2505 | { |
Ville Syrjälä | efc2611 | 2016-10-31 22:37:04 +0200 | [diff] [blame] | 2506 | struct intel_crtc *crtc; |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2507 | const struct drm_display_mode *pipe_mode; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2508 | u32 fwater_lo; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2509 | int planea_wm; |
| 2510 | |
Ville Syrjälä | ffc7a76 | 2016-10-31 22:37:21 +0200 | [diff] [blame] | 2511 | crtc = single_enabled_crtc(dev_priv); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2512 | if (crtc == NULL) |
| 2513 | return; |
| 2514 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2515 | pipe_mode = &crtc->config->hw.pipe_mode; |
| 2516 | planea_wm = intel_calculate_wm(pipe_mode->crtc_clock, |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 2517 | &i845_wm_info, |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 2518 | i845_get_fifo_size(dev_priv, PLANE_A), |
Chris Wilson | 5aef600 | 2014-09-03 11:56:07 +0100 | [diff] [blame] | 2519 | 4, pessimal_latency_ns); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2520 | fwater_lo = intel_uncore_read(&dev_priv->uncore, FW_BLC) & ~0xfff; |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2521 | fwater_lo |= (3<<8) | planea_wm; |
| 2522 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2523 | drm_dbg_kms(&dev_priv->drm, |
| 2524 | "Setting FIFO watermarks - A: %d\n", planea_wm); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2525 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 2526 | intel_uncore_write(&dev_priv->uncore, FW_BLC, fwater_lo); |
Eugeni Dodonov | b445e3b | 2012-04-16 22:20:35 -0300 | [diff] [blame] | 2527 | } |
| 2528 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2529 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2530 | static unsigned int ilk_wm_method1(unsigned int pixel_rate, |
| 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_method1(pixel_rate, cpp, latency); |
| 2537 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2538 | |
| 2539 | return ret; |
| 2540 | } |
| 2541 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2542 | /* latency must be in 0.1us units. */ |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2543 | static unsigned int ilk_wm_method2(unsigned int pixel_rate, |
| 2544 | unsigned int htotal, |
| 2545 | unsigned int width, |
| 2546 | unsigned int cpp, |
| 2547 | unsigned int latency) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2548 | { |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2549 | unsigned int ret; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2550 | |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2551 | ret = intel_wm_method2(pixel_rate, htotal, |
| 2552 | width, cpp, latency); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2553 | ret = DIV_ROUND_UP(ret, 64) + 2; |
Ville Syrjälä | baf69ca | 2017-04-21 21:14:27 +0300 | [diff] [blame] | 2554 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2555 | return ret; |
| 2556 | } |
| 2557 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2558 | 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] | 2559 | { |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2560 | /* |
| 2561 | * Neither of these should be possible since this function shouldn't be |
| 2562 | * called if the CRTC is off or the plane is invisible. But let's be |
| 2563 | * extra paranoid to avoid a potential divide-by-zero if we screw up |
| 2564 | * elsewhere in the driver. |
| 2565 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2566 | if (WARN_ON(!cpp)) |
Matt Roper | 1512688 | 2015-12-03 11:37:40 -0800 | [diff] [blame] | 2567 | return 0; |
| 2568 | if (WARN_ON(!horiz_pixels)) |
| 2569 | return 0; |
| 2570 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2571 | return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2572 | } |
| 2573 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2574 | struct ilk_wm_maximums { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2575 | u16 pri; |
| 2576 | u16 spr; |
| 2577 | u16 cur; |
| 2578 | u16 fbc; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2579 | }; |
| 2580 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2581 | /* |
| 2582 | * For both WM_PIPE and WM_LP. |
| 2583 | * mem_value must be in 0.1us units. |
| 2584 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2585 | static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state, |
| 2586 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2587 | u32 mem_value, bool is_lp) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2588 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2589 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2590 | int cpp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2591 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2592 | if (mem_value == 0) |
| 2593 | return U32_MAX; |
| 2594 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2595 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2596 | return 0; |
| 2597 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2598 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2599 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2600 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2601 | |
| 2602 | if (!is_lp) |
| 2603 | return method1; |
| 2604 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2605 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2606 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2607 | drm_rect_width(&plane_state->uapi.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2608 | cpp, mem_value); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2609 | |
| 2610 | return min(method1, method2); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2611 | } |
| 2612 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2613 | /* |
| 2614 | * For both WM_PIPE and WM_LP. |
| 2615 | * mem_value must be in 0.1us units. |
| 2616 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2617 | static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state, |
| 2618 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2619 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2620 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2621 | u32 method1, method2; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2622 | int cpp; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2623 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2624 | if (mem_value == 0) |
| 2625 | return U32_MAX; |
| 2626 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2627 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2628 | return 0; |
| 2629 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2630 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2631 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2632 | method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value); |
| 2633 | method2 = ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2634 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2635 | drm_rect_width(&plane_state->uapi.dst), |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2636 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2637 | return min(method1, method2); |
| 2638 | } |
| 2639 | |
Ville Syrjälä | 3712646 | 2013-08-01 16:18:55 +0300 | [diff] [blame] | 2640 | /* |
| 2641 | * For both WM_PIPE and WM_LP. |
| 2642 | * mem_value must be in 0.1us units. |
| 2643 | */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2644 | static u32 ilk_compute_cur_wm(const struct intel_crtc_state *crtc_state, |
| 2645 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2646 | u32 mem_value) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2647 | { |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2648 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2649 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 2650 | if (mem_value == 0) |
| 2651 | return U32_MAX; |
| 2652 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2653 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2654 | return 0; |
| 2655 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2656 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | a5509ab | 2017-02-17 17:01:59 +0200 | [diff] [blame] | 2657 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2658 | return ilk_wm_method2(crtc_state->pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 2659 | crtc_state->hw.pipe_mode.crtc_htotal, |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2660 | drm_rect_width(&plane_state->uapi.dst), |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 2661 | cpp, mem_value); |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 2662 | } |
| 2663 | |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2664 | /* Only for WM_LP. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2665 | static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state, |
| 2666 | const struct intel_plane_state *plane_state, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2667 | u32 pri_val) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2668 | { |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2669 | int cpp; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 2670 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2671 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2672 | return 0; |
| 2673 | |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 2674 | cpp = plane_state->hw.fb->format->cpp[0]; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 2675 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 2676 | return ilk_wm_fbc(pri_val, drm_rect_width(&plane_state->uapi.dst), |
| 2677 | cpp); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 2678 | } |
| 2679 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2680 | static unsigned int |
| 2681 | ilk_display_fifo_size(const struct drm_i915_private *dev_priv) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2682 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2683 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 2684 | return 3072; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2685 | else if (DISPLAY_VER(dev_priv) >= 7) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2686 | return 768; |
| 2687 | else |
| 2688 | return 512; |
| 2689 | } |
| 2690 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2691 | static unsigned int |
| 2692 | ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv, |
| 2693 | int level, bool is_sprite) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2694 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2695 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2696 | /* BDW primary/sprite plane watermarks */ |
| 2697 | return level == 0 ? 255 : 2047; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2698 | else if (DISPLAY_VER(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2699 | /* IVB/HSW primary/sprite plane watermarks */ |
| 2700 | return level == 0 ? 127 : 1023; |
| 2701 | else if (!is_sprite) |
| 2702 | /* ILK/SNB primary plane watermarks */ |
| 2703 | return level == 0 ? 127 : 511; |
| 2704 | else |
| 2705 | /* ILK/SNB sprite plane watermarks */ |
| 2706 | return level == 0 ? 63 : 255; |
| 2707 | } |
| 2708 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2709 | static unsigned int |
| 2710 | 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] | 2711 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2712 | if (DISPLAY_VER(dev_priv) >= 7) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2713 | return level == 0 ? 63 : 255; |
| 2714 | else |
| 2715 | return level == 0 ? 31 : 63; |
| 2716 | } |
| 2717 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2718 | 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] | 2719 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2720 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 4e97508 | 2014-03-07 18:32:11 +0200 | [diff] [blame] | 2721 | return 31; |
| 2722 | else |
| 2723 | return 15; |
| 2724 | } |
| 2725 | |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2726 | /* Calculate the maximum primary/sprite plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2727 | 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] | 2728 | int level, |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2729 | const struct intel_wm_config *config, |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2730 | enum intel_ddb_partitioning ddb_partitioning, |
| 2731 | bool is_sprite) |
| 2732 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2733 | unsigned int fifo_size = ilk_display_fifo_size(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2734 | |
| 2735 | /* if sprites aren't enabled, sprites get nothing */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2736 | if (is_sprite && !config->sprites_enabled) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2737 | return 0; |
| 2738 | |
| 2739 | /* HSW allows LP1+ watermarks even with multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2740 | if (level == 0 || config->num_pipes_active > 1) { |
Jani Nikula | 2497787 | 2019-09-11 12:26:08 +0300 | [diff] [blame] | 2741 | fifo_size /= INTEL_NUM_PIPES(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2742 | |
| 2743 | /* |
| 2744 | * For some reason the non self refresh |
| 2745 | * FIFO size is only half of the self |
| 2746 | * refresh FIFO size on ILK/SNB. |
| 2747 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2748 | if (DISPLAY_VER(dev_priv) <= 6) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2749 | fifo_size /= 2; |
| 2750 | } |
| 2751 | |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2752 | if (config->sprites_enabled) { |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2753 | /* level 0 is always calculated with 1:1 split */ |
| 2754 | if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) { |
| 2755 | if (is_sprite) |
| 2756 | fifo_size *= 5; |
| 2757 | fifo_size /= 6; |
| 2758 | } else { |
| 2759 | fifo_size /= 2; |
| 2760 | } |
| 2761 | } |
| 2762 | |
| 2763 | /* clamp to max that the registers can hold */ |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2764 | 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] | 2765 | } |
| 2766 | |
| 2767 | /* Calculate the maximum cursor plane watermark */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2768 | 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] | 2769 | int level, |
| 2770 | const struct intel_wm_config *config) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2771 | { |
| 2772 | /* HSW LP1+ watermarks w/ multiple pipes */ |
Ville Syrjälä | 240264f | 2013-08-07 13:29:12 +0300 | [diff] [blame] | 2773 | if (level > 0 && config->num_pipes_active > 1) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2774 | return 64; |
| 2775 | |
| 2776 | /* otherwise just report max that registers can hold */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2777 | return ilk_cursor_wm_reg_max(dev_priv, level); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2778 | } |
| 2779 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2780 | 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] | 2781 | int level, |
| 2782 | const struct intel_wm_config *config, |
| 2783 | enum intel_ddb_partitioning ddb_partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2784 | struct ilk_wm_maximums *max) |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2785 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 2786 | max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false); |
| 2787 | max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true); |
| 2788 | max->cur = ilk_cursor_wm_max(dev_priv, level, config); |
| 2789 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | 158ae64 | 2013-08-07 13:28:19 +0300 | [diff] [blame] | 2790 | } |
| 2791 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2792 | 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] | 2793 | int level, |
| 2794 | struct ilk_wm_maximums *max) |
| 2795 | { |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 2796 | max->pri = ilk_plane_wm_reg_max(dev_priv, level, false); |
| 2797 | max->spr = ilk_plane_wm_reg_max(dev_priv, level, true); |
| 2798 | max->cur = ilk_cursor_wm_reg_max(dev_priv, level); |
| 2799 | max->fbc = ilk_fbc_wm_reg_max(dev_priv); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 2800 | } |
| 2801 | |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2802 | static bool ilk_validate_wm_level(int level, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 2803 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | d939565 | 2013-10-09 19:18:10 +0300 | [diff] [blame] | 2804 | struct intel_wm_level *result) |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2805 | { |
| 2806 | bool ret; |
| 2807 | |
| 2808 | /* already determined to be invalid? */ |
| 2809 | if (!result->enable) |
| 2810 | return false; |
| 2811 | |
| 2812 | result->enable = result->pri_val <= max->pri && |
| 2813 | result->spr_val <= max->spr && |
| 2814 | result->cur_val <= max->cur; |
| 2815 | |
| 2816 | ret = result->enable; |
| 2817 | |
| 2818 | /* |
| 2819 | * HACK until we can pre-compute everything, |
| 2820 | * and thus fail gracefully if LP0 watermarks |
| 2821 | * are exceeded... |
| 2822 | */ |
| 2823 | if (level == 0 && !result->enable) { |
| 2824 | if (result->pri_val > max->pri) |
| 2825 | DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n", |
| 2826 | level, result->pri_val, max->pri); |
| 2827 | if (result->spr_val > max->spr) |
| 2828 | DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n", |
| 2829 | level, result->spr_val, max->spr); |
| 2830 | if (result->cur_val > max->cur) |
| 2831 | DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n", |
| 2832 | level, result->cur_val, max->cur); |
| 2833 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2834 | result->pri_val = min_t(u32, result->pri_val, max->pri); |
| 2835 | result->spr_val = min_t(u32, result->spr_val, max->spr); |
| 2836 | result->cur_val = min_t(u32, result->cur_val, max->cur); |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2837 | result->enable = true; |
| 2838 | } |
| 2839 | |
Ville Syrjälä | a9786a1 | 2013-08-07 13:24:47 +0300 | [diff] [blame] | 2840 | return ret; |
| 2841 | } |
| 2842 | |
Damien Lespiau | d34ff9c | 2014-01-06 19:17:23 +0000 | [diff] [blame] | 2843 | 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] | 2844 | const struct intel_crtc *crtc, |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2845 | int level, |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2846 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 2847 | const struct intel_plane_state *pristate, |
| 2848 | const struct intel_plane_state *sprstate, |
| 2849 | const struct intel_plane_state *curstate, |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 2850 | struct intel_wm_level *result) |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2851 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2852 | u16 pri_latency = dev_priv->wm.pri_latency[level]; |
| 2853 | u16 spr_latency = dev_priv->wm.spr_latency[level]; |
| 2854 | u16 cur_latency = dev_priv->wm.cur_latency[level]; |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2855 | |
| 2856 | /* WM1+ latency values stored in 0.5us units */ |
| 2857 | if (level > 0) { |
| 2858 | pri_latency *= 5; |
| 2859 | spr_latency *= 5; |
| 2860 | cur_latency *= 5; |
| 2861 | } |
| 2862 | |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2863 | if (pristate) { |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2864 | result->pri_val = ilk_compute_pri_wm(crtc_state, pristate, |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2865 | pri_latency, level); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2866 | 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] | 2867 | } |
| 2868 | |
| 2869 | if (sprstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2870 | result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2871 | |
| 2872 | if (curstate) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 2873 | result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency); |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 2874 | |
Ville Syrjälä | 6f5ddd1 | 2013-08-06 22:24:02 +0300 | [diff] [blame] | 2875 | result->enable = true; |
| 2876 | } |
| 2877 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 2878 | static void intel_read_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2879 | u16 wm[8]) |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2880 | { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2881 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 2882 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2883 | if (DISPLAY_VER(dev_priv) >= 9) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 2884 | u32 val; |
Vandana Kannan | 4f94738 | 2014-11-04 17:06:47 +0000 | [diff] [blame] | 2885 | int ret, i; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2886 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2887 | int mult = IS_DG2(dev_priv) ? 2 : 1; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2888 | |
| 2889 | /* read the first set of memory latencies[0:3] */ |
| 2890 | val = 0; /* data0 to be programmed to 0 for first set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2891 | ret = sandybridge_pcode_read(dev_priv, |
| 2892 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2893 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2894 | |
| 2895 | if (ret) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2896 | drm_err(&dev_priv->drm, |
| 2897 | "SKL Mailbox read error = %d\n", ret); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2898 | return; |
| 2899 | } |
| 2900 | |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2901 | wm[0] = (val & GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2902 | wm[1] = ((val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2903 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2904 | wm[2] = ((val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2905 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2906 | wm[3] = ((val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2907 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2908 | |
| 2909 | /* read the second set of memory latencies[4:7] */ |
| 2910 | val = 1; /* data0 to be programmed to 1 for second set */ |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2911 | ret = sandybridge_pcode_read(dev_priv, |
| 2912 | GEN9_PCODE_READ_MEM_LATENCY, |
Ville Syrjälä | d284d51 | 2019-05-21 19:40:24 +0300 | [diff] [blame] | 2913 | &val, NULL); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2914 | if (ret) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 2915 | drm_err(&dev_priv->drm, |
| 2916 | "SKL Mailbox read error = %d\n", ret); |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2917 | return; |
| 2918 | } |
| 2919 | |
Matt Roper | d3252e1 | 2021-08-20 15:57:10 -0700 | [diff] [blame] | 2920 | wm[4] = (val & GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2921 | wm[5] = ((val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) & |
| 2922 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2923 | wm[6] = ((val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) & |
| 2924 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
| 2925 | wm[7] = ((val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) & |
| 2926 | GEN9_MEM_LATENCY_LEVEL_MASK) * mult; |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 2927 | |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2928 | /* |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2929 | * If a level n (n > 1) has a 0us latency, all levels m (m >= n) |
| 2930 | * need to be disabled. We make sure to sanitize the values out |
| 2931 | * of the punit to satisfy this requirement. |
| 2932 | */ |
| 2933 | for (level = 1; level <= max_level; level++) { |
| 2934 | if (wm[level] == 0) { |
| 2935 | for (i = level + 1; i <= max_level; i++) |
| 2936 | wm[i] = 0; |
Lucas De Marchi | 0bc3a4e | 2021-06-22 14:22:10 -0700 | [diff] [blame] | 2937 | |
| 2938 | max_level = level - 1; |
| 2939 | |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2940 | break; |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | /* |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2945 | * WaWmMemoryReadLatency |
Damien Lespiau | 6f97235 | 2015-02-09 19:33:07 +0000 | [diff] [blame] | 2946 | * |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2947 | * 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] | 2948 | * to add proper adjustement to each valid level we retrieve |
| 2949 | * from the punit when level 0 response data is 0us. |
Vandana Kannan | 367294b | 2014-11-04 17:06:46 +0000 | [diff] [blame] | 2950 | */ |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2951 | if (wm[0] == 0) { |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2952 | u8 adjust = DISPLAY_VER(dev_priv) >= 12 ? 3 : 2; |
| 2953 | |
Lucas De Marchi | 0bc3a4e | 2021-06-22 14:22:10 -0700 | [diff] [blame] | 2954 | for (level = 0; level <= max_level; level++) |
Lucas De Marchi | cbeeb00 | 2021-06-22 14:22:09 -0700 | [diff] [blame] | 2955 | wm[level] += adjust; |
Paulo Zanoni | 0727e40 | 2016-09-22 18:00:30 -0300 | [diff] [blame] | 2956 | } |
| 2957 | |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2958 | /* |
| 2959 | * WA Level-0 adjustment for 16GB DIMMs: SKL+ |
| 2960 | * If we could not get dimm info enable this WA to prevent from |
| 2961 | * any underrun. If not able to get Dimm info assume 16GB dimm |
| 2962 | * to avoid any underrun. |
| 2963 | */ |
José Roberto de Souza | 66a2450 | 2021-01-28 08:43:12 -0800 | [diff] [blame] | 2964 | if (dev_priv->dram_info.wm_lv_0_adjust_needed) |
Mahesh Kumar | 86b5928 | 2018-08-31 16:39:42 +0530 | [diff] [blame] | 2965 | wm[0] += 1; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 2966 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2967 | u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2968 | |
| 2969 | wm[0] = (sskpd >> 56) & 0xFF; |
| 2970 | if (wm[0] == 0) |
| 2971 | wm[0] = sskpd & 0xF; |
Ville Syrjälä | e5d5019 | 2013-07-05 11:57:22 +0300 | [diff] [blame] | 2972 | wm[1] = (sskpd >> 4) & 0xFF; |
| 2973 | wm[2] = (sskpd >> 12) & 0xFF; |
| 2974 | wm[3] = (sskpd >> 20) & 0x1FF; |
| 2975 | wm[4] = (sskpd >> 32) & 0x1FF; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2976 | } else if (DISPLAY_VER(dev_priv) >= 6) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2977 | u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD); |
Ville Syrjälä | 63cf9a1 | 2013-07-05 11:57:23 +0300 | [diff] [blame] | 2978 | |
| 2979 | wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK; |
| 2980 | wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK; |
| 2981 | wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK; |
| 2982 | wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 2983 | } else if (DISPLAY_VER(dev_priv) >= 5) { |
Tvrtko Ursulin | 1cea02d | 2019-06-10 13:06:07 +0100 | [diff] [blame] | 2984 | u32 mltr = intel_uncore_read(uncore, MLTR_ILK); |
Ville Syrjälä | 3a88d0a | 2013-08-01 16:18:49 +0300 | [diff] [blame] | 2985 | |
| 2986 | /* ILK primary LP0 latency is 700 ns */ |
| 2987 | wm[0] = 7; |
| 2988 | wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK; |
| 2989 | wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK; |
Paulo Zanoni | 50682ee | 2017-08-09 13:52:43 -0700 | [diff] [blame] | 2990 | } else { |
| 2991 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Ville Syrjälä | 12b134d | 2013-07-05 11:57:21 +0300 | [diff] [blame] | 2992 | } |
| 2993 | } |
| 2994 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 2995 | 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] | 2996 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 2997 | { |
| 2998 | /* ILK sprite LP0 latency is 1300 ns */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 2999 | if (DISPLAY_VER(dev_priv) == 5) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3000 | wm[0] = 13; |
| 3001 | } |
| 3002 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3003 | 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] | 3004 | u16 wm[5]) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3005 | { |
| 3006 | /* ILK cursor LP0 latency is 1300 ns */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3007 | if (DISPLAY_VER(dev_priv) == 5) |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3008 | wm[0] = 13; |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3009 | } |
| 3010 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3011 | 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] | 3012 | { |
| 3013 | /* how many WM levels are we expecting */ |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 3014 | if (HAS_HW_SAGV_WM(dev_priv)) |
| 3015 | return 5; |
| 3016 | else if (DISPLAY_VER(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3017 | return 7; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3018 | else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 3019 | return 4; |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3020 | else if (DISPLAY_VER(dev_priv) >= 6) |
Ville Syrjälä | ad0d6dc | 2013-08-30 14:30:25 +0300 | [diff] [blame] | 3021 | return 3; |
| 3022 | else |
| 3023 | return 2; |
| 3024 | } |
Daniel Vetter | 7526ed7 | 2014-09-29 15:07:19 +0200 | [diff] [blame] | 3025 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3026 | 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] | 3027 | const char *name, |
Linus Torvalds | e7c6e40 | 2021-04-27 17:05:53 -0700 | [diff] [blame] | 3028 | const u16 wm[]) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3029 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3030 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3031 | |
| 3032 | for (level = 0; level <= max_level; level++) { |
| 3033 | unsigned int latency = wm[level]; |
| 3034 | |
| 3035 | if (latency == 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3036 | drm_dbg_kms(&dev_priv->drm, |
| 3037 | "%s WM%d latency not provided\n", |
| 3038 | name, level); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3039 | continue; |
| 3040 | } |
| 3041 | |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3042 | /* |
| 3043 | * - latencies are in us on gen9. |
| 3044 | * - before then, WM1+ latency values are in 0.5us units |
| 3045 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3046 | if (DISPLAY_VER(dev_priv) >= 9) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3047 | latency *= 10; |
| 3048 | else if (level > 0) |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3049 | latency *= 5; |
| 3050 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3051 | drm_dbg_kms(&dev_priv->drm, |
| 3052 | "%s WM%d latency %u (%u.%u usec)\n", name, level, |
| 3053 | wm[level], latency / 10, latency % 10); |
Ville Syrjälä | 26ec971 | 2013-08-01 16:18:52 +0300 | [diff] [blame] | 3054 | } |
| 3055 | } |
| 3056 | |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3057 | static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv, |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3058 | u16 wm[5], u16 min) |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3059 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3060 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3061 | |
| 3062 | if (wm[0] >= min) |
| 3063 | return false; |
| 3064 | |
| 3065 | wm[0] = max(wm[0], min); |
| 3066 | for (level = 1; level <= max_level; level++) |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3067 | 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] | 3068 | |
| 3069 | return true; |
| 3070 | } |
| 3071 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3072 | 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] | 3073 | { |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3074 | bool changed; |
| 3075 | |
| 3076 | /* |
| 3077 | * The BIOS provided WM memory latency values are often |
| 3078 | * inadequate for high resolution displays. Adjust them. |
| 3079 | */ |
Nathan Chancellor | 2e70570 | 2021-10-14 14:19:16 -0700 | [diff] [blame] | 3080 | changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12); |
| 3081 | changed |= ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12); |
| 3082 | changed |= ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12); |
Ville Syrjälä | e95a2f7 | 2014-05-08 15:09:19 +0300 | [diff] [blame] | 3083 | |
| 3084 | if (!changed) |
| 3085 | return; |
| 3086 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3087 | drm_dbg_kms(&dev_priv->drm, |
| 3088 | "WM latency values increased to avoid potential underruns\n"); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3089 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3090 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3091 | 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] | 3092 | } |
| 3093 | |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3094 | static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv) |
| 3095 | { |
| 3096 | /* |
| 3097 | * On some SNB machines (Thinkpad X220 Tablet at least) |
| 3098 | * LP3 usage can cause vblank interrupts to be lost. |
| 3099 | * The DEIIR bit will go high but it looks like the CPU |
| 3100 | * never gets interrupted. |
| 3101 | * |
| 3102 | * It's not clear whether other interrupt source could |
| 3103 | * be affected or if this is somehow limited to vblank |
| 3104 | * interrupts only. To play it safe we disable LP3 |
| 3105 | * watermarks entirely. |
| 3106 | */ |
| 3107 | if (dev_priv->wm.pri_latency[3] == 0 && |
| 3108 | dev_priv->wm.spr_latency[3] == 0 && |
| 3109 | dev_priv->wm.cur_latency[3] == 0) |
| 3110 | return; |
| 3111 | |
| 3112 | dev_priv->wm.pri_latency[3] = 0; |
| 3113 | dev_priv->wm.spr_latency[3] = 0; |
| 3114 | dev_priv->wm.cur_latency[3] = 0; |
| 3115 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3116 | drm_dbg_kms(&dev_priv->drm, |
| 3117 | "LP3 watermarks disabled due to potential for lost interrupts\n"); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3118 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3119 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3120 | intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency); |
| 3121 | } |
| 3122 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3123 | 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] | 3124 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3125 | intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3126 | |
| 3127 | memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency, |
| 3128 | sizeof(dev_priv->wm.pri_latency)); |
| 3129 | memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency, |
| 3130 | sizeof(dev_priv->wm.pri_latency)); |
| 3131 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3132 | intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3133 | 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] | 3134 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3135 | intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency); |
| 3136 | intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency); |
| 3137 | 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] | 3138 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3139 | if (DISPLAY_VER(dev_priv) == 6) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3140 | snb_wm_latency_quirk(dev_priv); |
Ville Syrjälä | 03981c6 | 2018-11-14 19:34:40 +0200 | [diff] [blame] | 3141 | snb_wm_lp3_irq_quirk(dev_priv); |
| 3142 | } |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 3143 | } |
| 3144 | |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3145 | static void skl_setup_wm_latency(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 2af30a5 | 2014-11-04 17:06:38 +0000 | [diff] [blame] | 3146 | { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 3147 | intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3148 | 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] | 3149 | } |
| 3150 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3151 | 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] | 3152 | struct intel_pipe_wm *pipe_wm) |
| 3153 | { |
| 3154 | /* LP0 watermark maximums depend on this pipe alone */ |
| 3155 | const struct intel_wm_config config = { |
| 3156 | .num_pipes_active = 1, |
| 3157 | .sprites_enabled = pipe_wm->sprites_enabled, |
| 3158 | .sprites_scaled = pipe_wm->sprites_scaled, |
| 3159 | }; |
| 3160 | struct ilk_wm_maximums max; |
| 3161 | |
| 3162 | /* LP0 watermarks always use 1/2 DDB partitioning */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3163 | 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] | 3164 | |
| 3165 | /* At least LP0 must be valid */ |
| 3166 | if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3167 | drm_dbg_kms(&dev_priv->drm, "LP0 watermark invalid\n"); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3168 | return false; |
| 3169 | } |
| 3170 | |
| 3171 | return true; |
| 3172 | } |
| 3173 | |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3174 | /* Compute new watermarks for the pipe */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3175 | static int ilk_compute_pipe_wm(struct intel_atomic_state *state, |
| 3176 | struct intel_crtc *crtc) |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 3177 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3178 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 3179 | struct intel_crtc_state *crtc_state = |
| 3180 | intel_atomic_get_new_crtc_state(state, crtc); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3181 | struct intel_pipe_wm *pipe_wm; |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3182 | struct intel_plane *plane; |
| 3183 | const struct intel_plane_state *plane_state; |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3184 | const struct intel_plane_state *pristate = NULL; |
| 3185 | const struct intel_plane_state *sprstate = NULL; |
| 3186 | const struct intel_plane_state *curstate = NULL; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3187 | int level, max_level = ilk_wm_max_level(dev_priv), usable_level; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3188 | struct ilk_wm_maximums max; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3189 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 3190 | pipe_wm = &crtc_state->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3191 | |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 3192 | intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) { |
| 3193 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 3194 | pristate = plane_state; |
| 3195 | else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY) |
| 3196 | sprstate = plane_state; |
| 3197 | else if (plane->base.type == DRM_PLANE_TYPE_CURSOR) |
| 3198 | curstate = plane_state; |
Matt Roper | 43d59ed | 2015-09-24 15:53:07 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 3201 | pipe_wm->pipe_enabled = crtc_state->hw.active; |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 3202 | if (sprstate) { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 3203 | pipe_wm->sprites_enabled = sprstate->uapi.visible; |
| 3204 | pipe_wm->sprites_scaled = sprstate->uapi.visible && |
| 3205 | (drm_rect_width(&sprstate->uapi.dst) != drm_rect_width(&sprstate->uapi.src) >> 16 || |
| 3206 | 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] | 3207 | } |
| 3208 | |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3209 | usable_level = max_level; |
| 3210 | |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3211 | /* ILK/SNB: LP2+ watermarks only w/o sprites */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3212 | if (DISPLAY_VER(dev_priv) <= 6 && pipe_wm->sprites_enabled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3213 | usable_level = 1; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3214 | |
| 3215 | /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3216 | if (pipe_wm->sprites_scaled) |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3217 | usable_level = 0; |
Ville Syrjälä | 7b39a0b | 2013-12-05 15:51:30 +0200 | [diff] [blame] | 3218 | |
Maarten Lankhorst | 71f0a62 | 2016-03-08 10:57:16 +0100 | [diff] [blame] | 3219 | memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm)); |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3220 | ilk_compute_wm_level(dev_priv, crtc, 0, crtc_state, |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3221 | pristate, sprstate, curstate, &pipe_wm->wm[0]); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3222 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3223 | if (!ilk_validate_pipe_wm(dev_priv, pipe_wm)) |
Maarten Lankhorst | 1a426d6 | 2016-03-02 12:36:03 +0100 | [diff] [blame] | 3224 | return -EINVAL; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3225 | |
Tvrtko Ursulin | 175fded | 2016-11-16 08:55:42 +0000 | [diff] [blame] | 3226 | ilk_compute_wm_reg_maximums(dev_priv, 1, &max); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3227 | |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3228 | for (level = 1; level <= usable_level; level++) { |
| 3229 | struct intel_wm_level *wm = &pipe_wm->wm[level]; |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3230 | |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 3231 | ilk_compute_wm_level(dev_priv, crtc, level, crtc_state, |
Maarten Lankhorst | d81f04c | 2016-03-02 12:38:06 +0100 | [diff] [blame] | 3232 | pristate, sprstate, curstate, wm); |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3233 | |
| 3234 | /* |
| 3235 | * Disable any watermark level that exceeds the |
| 3236 | * register maximums since such watermarks are |
| 3237 | * always invalid. |
| 3238 | */ |
Maarten Lankhorst | 28283f4 | 2017-10-19 17:13:40 +0200 | [diff] [blame] | 3239 | if (!ilk_validate_wm_level(level, &max, wm)) { |
| 3240 | memset(wm, 0, sizeof(*wm)); |
| 3241 | break; |
| 3242 | } |
Ville Syrjälä | a3cb404 | 2014-04-28 15:44:56 +0300 | [diff] [blame] | 3243 | } |
| 3244 | |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 3245 | return 0; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | /* |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3249 | * Build a set of 'intermediate' watermark values that satisfy both the old |
| 3250 | * state and the new state. These can be programmed to the hardware |
| 3251 | * immediately. |
| 3252 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3253 | static int ilk_compute_intermediate_wm(struct intel_atomic_state *state, |
| 3254 | struct intel_crtc *crtc) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3255 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3256 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3257 | struct intel_crtc_state *new_crtc_state = |
| 3258 | intel_atomic_get_new_crtc_state(state, crtc); |
| 3259 | const struct intel_crtc_state *old_crtc_state = |
| 3260 | intel_atomic_get_old_crtc_state(state, crtc); |
| 3261 | struct intel_pipe_wm *a = &new_crtc_state->wm.ilk.intermediate; |
| 3262 | const struct intel_pipe_wm *b = &old_crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3263 | int level, max_level = ilk_wm_max_level(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3264 | |
| 3265 | /* |
| 3266 | * Start with the final, target watermarks, then combine with the |
| 3267 | * currently active watermarks to get values that are safe both before |
| 3268 | * and after the vblank. |
| 3269 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3270 | *a = new_crtc_state->wm.ilk.optimal; |
| 3271 | if (!new_crtc_state->hw.active || |
| 3272 | drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) || |
| 3273 | state->skip_intermediate_wm) |
Maarten Lankhorst | b6b178a | 2017-10-19 17:13:41 +0200 | [diff] [blame] | 3274 | return 0; |
| 3275 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3276 | a->pipe_enabled |= b->pipe_enabled; |
| 3277 | a->sprites_enabled |= b->sprites_enabled; |
| 3278 | a->sprites_scaled |= b->sprites_scaled; |
| 3279 | |
| 3280 | for (level = 0; level <= max_level; level++) { |
| 3281 | struct intel_wm_level *a_wm = &a->wm[level]; |
| 3282 | const struct intel_wm_level *b_wm = &b->wm[level]; |
| 3283 | |
| 3284 | a_wm->enable &= b_wm->enable; |
| 3285 | a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val); |
| 3286 | a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val); |
| 3287 | a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val); |
| 3288 | a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val); |
| 3289 | } |
| 3290 | |
| 3291 | /* |
| 3292 | * We need to make sure that these merged watermark values are |
| 3293 | * actually a valid configuration themselves. If they're not, |
| 3294 | * there's no safe way to transition from the old state to |
| 3295 | * the new state, so we need to fail the atomic transaction. |
| 3296 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3297 | if (!ilk_validate_pipe_wm(dev_priv, a)) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3298 | return -EINVAL; |
| 3299 | |
| 3300 | /* |
| 3301 | * If our intermediate WM are identical to the final WM, then we can |
| 3302 | * omit the post-vblank programming; only update if it's different. |
| 3303 | */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3304 | if (memcmp(a, &new_crtc_state->wm.ilk.optimal, sizeof(*a)) != 0) |
| 3305 | new_crtc_state->wm.need_postvbl_update = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 3306 | |
| 3307 | return 0; |
| 3308 | } |
| 3309 | |
| 3310 | /* |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3311 | * Merge the watermarks from all active pipes for a specific level. |
| 3312 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3313 | 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] | 3314 | int level, |
| 3315 | struct intel_wm_level *ret_wm) |
| 3316 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3317 | const struct intel_crtc *crtc; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3318 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3319 | ret_wm->enable = true; |
| 3320 | |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3321 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 3322 | const struct intel_pipe_wm *active = &crtc->wm.active.ilk; |
Ville Syrjälä | fe392ef | 2014-03-07 18:32:10 +0200 | [diff] [blame] | 3323 | const struct intel_wm_level *wm = &active->wm[level]; |
| 3324 | |
| 3325 | if (!active->pipe_enabled) |
| 3326 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3327 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3328 | /* |
| 3329 | * The watermark values may have been used in the past, |
| 3330 | * so we must maintain them in the registers for some |
| 3331 | * time even if the level is now disabled. |
| 3332 | */ |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3333 | if (!wm->enable) |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3334 | ret_wm->enable = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3335 | |
| 3336 | ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val); |
| 3337 | ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val); |
| 3338 | ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val); |
| 3339 | ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val); |
| 3340 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | /* |
| 3344 | * Merge all low power watermarks for all active pipes. |
| 3345 | */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3346 | static void ilk_wm_merge(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3347 | const struct intel_wm_config *config, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3348 | const struct ilk_wm_maximums *max, |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3349 | struct intel_pipe_wm *merged) |
| 3350 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3351 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3352 | int last_enabled_level = max_level; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3353 | |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3354 | /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3355 | if ((DISPLAY_VER(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) && |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3356 | config->num_pipes_active > 1) |
Ville Syrjälä | 1204d5b | 2016-04-01 21:53:18 +0300 | [diff] [blame] | 3357 | last_enabled_level = 0; |
Ville Syrjälä | 0ba22e2 | 2013-12-05 15:51:34 +0200 | [diff] [blame] | 3358 | |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3359 | /* ILK: FBC WM must be disabled always */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3360 | merged->fbc_wm_enabled = DISPLAY_VER(dev_priv) >= 6; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3361 | |
| 3362 | /* merge each WM1+ level */ |
| 3363 | for (level = 1; level <= max_level; level++) { |
| 3364 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3365 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3366 | ilk_merge_wm_level(dev_priv, level, wm); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3367 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3368 | if (level > last_enabled_level) |
| 3369 | wm->enable = false; |
| 3370 | else if (!ilk_validate_wm_level(level, max, wm)) |
| 3371 | /* make sure all following levels get disabled */ |
| 3372 | last_enabled_level = level - 1; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3373 | |
| 3374 | /* |
| 3375 | * The spec says it is preferred to disable |
| 3376 | * FBC WMs instead of disabling a WM level. |
| 3377 | */ |
| 3378 | if (wm->fbc_val > max->fbc) { |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3379 | if (wm->enable) |
| 3380 | merged->fbc_wm_enabled = false; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3381 | wm->fbc_val = 0; |
| 3382 | } |
| 3383 | } |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3384 | |
| 3385 | /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */ |
Ville Syrjälä | 248e251 | 2021-11-24 13:36:33 +0200 | [diff] [blame] | 3386 | if (DISPLAY_VER(dev_priv) == 5 && HAS_FBC(dev_priv) && |
| 3387 | dev_priv->params.enable_fbc && !merged->fbc_wm_enabled) { |
Ville Syrjälä | 6c8b6c2 | 2013-12-05 15:51:35 +0200 | [diff] [blame] | 3388 | for (level = 2; level <= max_level; level++) { |
| 3389 | struct intel_wm_level *wm = &merged->wm[level]; |
| 3390 | |
| 3391 | wm->enable = false; |
| 3392 | } |
| 3393 | } |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3394 | } |
| 3395 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3396 | static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm) |
| 3397 | { |
| 3398 | /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */ |
| 3399 | return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable); |
| 3400 | } |
| 3401 | |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3402 | /* The value we need to program into the WM_LPx latency field */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3403 | static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv, |
| 3404 | int level) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3405 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3406 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | a68d68e | 2013-12-05 15:51:29 +0200 | [diff] [blame] | 3407 | return 2 * level; |
| 3408 | else |
| 3409 | return dev_priv->wm.pri_latency[level]; |
| 3410 | } |
| 3411 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3412 | 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] | 3413 | const struct intel_pipe_wm *merged, |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3414 | enum intel_ddb_partitioning partitioning, |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3415 | struct ilk_wm_values *results) |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3416 | { |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3417 | struct intel_crtc *crtc; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3418 | int level, wm_lp; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3419 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3420 | results->enable_fbc_wm = merged->fbc_wm_enabled; |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 3421 | results->partitioning = partitioning; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3422 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3423 | /* LP1+ register values */ |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3424 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
Ville Syrjälä | 1fd527c | 2013-08-06 22:24:05 +0300 | [diff] [blame] | 3425 | const struct intel_wm_level *r; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3426 | |
Ville Syrjälä | b380ca3 | 2013-10-09 19:18:01 +0300 | [diff] [blame] | 3427 | level = ilk_wm_lp_to_level(wm_lp, merged); |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3428 | |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 3429 | r = &merged->wm[level]; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3430 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3431 | /* |
| 3432 | * Maintain the watermark values even if the level is |
| 3433 | * disabled. Doing otherwise could cause underruns. |
| 3434 | */ |
| 3435 | results->wm_lp[wm_lp - 1] = |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3436 | (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) | |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3437 | (r->pri_val << WM1_LP_SR_SHIFT) | |
| 3438 | r->cur_val; |
| 3439 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3440 | if (r->enable) |
| 3441 | results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN; |
| 3442 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3443 | if (DISPLAY_VER(dev_priv) >= 8) |
Ville Syrjälä | 416f472 | 2013-11-02 21:07:46 -0700 | [diff] [blame] | 3444 | results->wm_lp[wm_lp - 1] |= |
| 3445 | r->fbc_val << WM1_LP_FBC_SHIFT_BDW; |
| 3446 | else |
| 3447 | results->wm_lp[wm_lp - 1] |= |
| 3448 | r->fbc_val << WM1_LP_FBC_SHIFT; |
| 3449 | |
Ville Syrjälä | d52fea5 | 2014-04-28 15:44:57 +0300 | [diff] [blame] | 3450 | /* |
| 3451 | * Always set WM1S_LP_EN when spr_val != 0, even if the |
| 3452 | * level is disabled. Doing otherwise could cause underruns. |
| 3453 | */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3454 | if (DISPLAY_VER(dev_priv) <= 6 && r->spr_val) { |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 3455 | drm_WARN_ON(&dev_priv->drm, wm_lp != 1); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3456 | results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val; |
| 3457 | } else |
| 3458 | results->wm_lp_spr[wm_lp - 1] = r->spr_val; |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3459 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3460 | |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3461 | /* LP0 register values */ |
Ville Syrjälä | 670c89e | 2021-06-09 11:56:30 +0300 | [diff] [blame] | 3462 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 3463 | enum pipe pipe = crtc->pipe; |
| 3464 | const struct intel_pipe_wm *pipe_wm = &crtc->wm.active.ilk; |
Ville Syrjälä | 0560b0c | 2020-01-20 19:47:11 +0200 | [diff] [blame] | 3465 | const struct intel_wm_level *r = &pipe_wm->wm[0]; |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3466 | |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 3467 | if (drm_WARN_ON(&dev_priv->drm, !r->enable)) |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3468 | continue; |
Ville Syrjälä | 0b2ae6d | 2013-10-09 19:17:55 +0300 | [diff] [blame] | 3469 | |
| 3470 | results->wm_pipe[pipe] = |
| 3471 | (r->pri_val << WM0_PIPE_PLANE_SHIFT) | |
| 3472 | (r->spr_val << WM0_PIPE_SPRITE_SHIFT) | |
| 3473 | r->cur_val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3474 | } |
| 3475 | } |
| 3476 | |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3477 | /* Find the result with the highest level enabled. Check for enable_fbc_wm in |
| 3478 | * 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] | 3479 | static struct intel_pipe_wm * |
| 3480 | ilk_find_best_result(struct drm_i915_private *dev_priv, |
| 3481 | struct intel_pipe_wm *r1, |
| 3482 | struct intel_pipe_wm *r2) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3483 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 3484 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3485 | int level1 = 0, level2 = 0; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3486 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3487 | for (level = 1; level <= max_level; level++) { |
| 3488 | if (r1->wm[level].enable) |
| 3489 | level1 = level; |
| 3490 | if (r2->wm[level].enable) |
| 3491 | level2 = level; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3492 | } |
| 3493 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3494 | if (level1 == level2) { |
| 3495 | if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled) |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3496 | return r2; |
| 3497 | else |
| 3498 | return r1; |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 3499 | } else if (level1 > level2) { |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 3500 | return r1; |
| 3501 | } else { |
| 3502 | return r2; |
| 3503 | } |
| 3504 | } |
| 3505 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3506 | /* dirty bits used to track which watermarks need changes */ |
| 3507 | #define WM_DIRTY_PIPE(pipe) (1 << (pipe)) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3508 | #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp))) |
| 3509 | #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3)) |
| 3510 | #define WM_DIRTY_FBC (1 << 24) |
| 3511 | #define WM_DIRTY_DDB (1 << 25) |
| 3512 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3513 | 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] | 3514 | const struct ilk_wm_values *old, |
| 3515 | const struct ilk_wm_values *new) |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3516 | { |
| 3517 | unsigned int dirty = 0; |
| 3518 | enum pipe pipe; |
| 3519 | int wm_lp; |
| 3520 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3521 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3522 | if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) { |
| 3523 | dirty |= WM_DIRTY_PIPE(pipe); |
| 3524 | /* Must disable LP1+ watermarks too */ |
| 3525 | dirty |= WM_DIRTY_LP_ALL; |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | if (old->enable_fbc_wm != new->enable_fbc_wm) { |
| 3530 | dirty |= WM_DIRTY_FBC; |
| 3531 | /* Must disable LP1+ watermarks too */ |
| 3532 | dirty |= WM_DIRTY_LP_ALL; |
| 3533 | } |
| 3534 | |
| 3535 | if (old->partitioning != new->partitioning) { |
| 3536 | dirty |= WM_DIRTY_DDB; |
| 3537 | /* Must disable LP1+ watermarks too */ |
| 3538 | dirty |= WM_DIRTY_LP_ALL; |
| 3539 | } |
| 3540 | |
| 3541 | /* LP1+ watermarks already deemed dirty, no need to continue */ |
| 3542 | if (dirty & WM_DIRTY_LP_ALL) |
| 3543 | return dirty; |
| 3544 | |
| 3545 | /* Find the lowest numbered LP1+ watermark in need of an update... */ |
| 3546 | for (wm_lp = 1; wm_lp <= 3; wm_lp++) { |
| 3547 | if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] || |
| 3548 | old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1]) |
| 3549 | break; |
| 3550 | } |
| 3551 | |
| 3552 | /* ...and mark it and all higher numbered LP1+ watermarks as dirty */ |
| 3553 | for (; wm_lp <= 3; wm_lp++) |
| 3554 | dirty |= WM_DIRTY_LP(wm_lp); |
| 3555 | |
| 3556 | return dirty; |
| 3557 | } |
| 3558 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3559 | static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv, |
| 3560 | unsigned int dirty) |
| 3561 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3562 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3563 | bool changed = false; |
| 3564 | |
| 3565 | if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) { |
| 3566 | previous->wm_lp[2] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3567 | 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] | 3568 | changed = true; |
| 3569 | } |
| 3570 | if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) { |
| 3571 | previous->wm_lp[1] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3572 | 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] | 3573 | changed = true; |
| 3574 | } |
| 3575 | if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) { |
| 3576 | previous->wm_lp[0] &= ~WM1_LP_SR_EN; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3577 | 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] | 3578 | changed = true; |
| 3579 | } |
| 3580 | |
| 3581 | /* |
| 3582 | * Don't touch WM1S_LP_EN here. |
| 3583 | * Doing so could cause underruns. |
| 3584 | */ |
| 3585 | |
| 3586 | return changed; |
| 3587 | } |
| 3588 | |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3589 | /* |
| 3590 | * The spec says we shouldn't write when we don't need, because every write |
| 3591 | * causes WMs to be re-evaluated, expending some power. |
| 3592 | */ |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3593 | static void ilk_write_wm_values(struct drm_i915_private *dev_priv, |
| 3594 | struct ilk_wm_values *results) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3595 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 3596 | struct ilk_wm_values *previous = &dev_priv->wm.hw; |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3597 | unsigned int dirty; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 3598 | u32 val; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3599 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 3600 | dirty = ilk_compute_wm_dirty(dev_priv, previous, results); |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3601 | if (!dirty) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3602 | return; |
| 3603 | |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3604 | _ilk_disable_lp_wm(dev_priv, dirty); |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3605 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3606 | if (dirty & WM_DIRTY_PIPE(PIPE_A)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3607 | 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] | 3608 | if (dirty & WM_DIRTY_PIPE(PIPE_B)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3609 | 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] | 3610 | if (dirty & WM_DIRTY_PIPE(PIPE_C)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3611 | 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] | 3612 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3613 | if (dirty & WM_DIRTY_DDB) { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3614 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3615 | val = intel_uncore_read(&dev_priv->uncore, WM_MISC); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3616 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3617 | val &= ~WM_MISC_DATA_PARTITION_5_6; |
| 3618 | else |
| 3619 | val |= WM_MISC_DATA_PARTITION_5_6; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3620 | intel_uncore_write(&dev_priv->uncore, WM_MISC, val); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3621 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3622 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3623 | if (results->partitioning == INTEL_DDB_PART_1_2) |
| 3624 | val &= ~DISP_DATA_PARTITION_5_6; |
| 3625 | else |
| 3626 | val |= DISP_DATA_PARTITION_5_6; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3627 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL2, val); |
Ville Syrjälä | ac9545f | 2013-12-05 15:51:28 +0200 | [diff] [blame] | 3628 | } |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 3629 | } |
| 3630 | |
Ville Syrjälä | 49a687c | 2013-10-11 19:39:52 +0300 | [diff] [blame] | 3631 | if (dirty & WM_DIRTY_FBC) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3632 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3633 | if (results->enable_fbc_wm) |
| 3634 | val &= ~DISP_FBC_WM_DIS; |
| 3635 | else |
| 3636 | val |= DISP_FBC_WM_DIS; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3637 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, val); |
Paulo Zanoni | cca32e9 | 2013-05-31 11:45:06 -0300 | [diff] [blame] | 3638 | } |
| 3639 | |
Imre Deak | 954911e | 2013-12-17 14:46:34 +0200 | [diff] [blame] | 3640 | if (dirty & WM_DIRTY_LP(1) && |
| 3641 | previous->wm_lp_spr[0] != results->wm_lp_spr[0]) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 3642 | 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] | 3643 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3644 | if (DISPLAY_VER(dev_priv) >= 7) { |
Ville Syrjälä | 6cef2b8a | 2013-12-05 15:51:32 +0200 | [diff] [blame] | 3645 | 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] | 3646 | 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] | 3647 | 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] | 3648 | 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] | 3649 | } |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3650 | |
Ville Syrjälä | facd619b | 2013-12-05 15:51:33 +0200 | [diff] [blame] | 3651 | 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] | 3652 | 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] | 3653 | 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] | 3654 | 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] | 3655 | 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] | 3656 | 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] | 3657 | |
| 3658 | dev_priv->wm.hw = *results; |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 3659 | } |
| 3660 | |
Ville Syrjälä | 60aca57 | 2019-11-27 21:05:51 +0200 | [diff] [blame] | 3661 | bool ilk_disable_lp_wm(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3662 | { |
Ville Syrjälä | 8553c18 | 2013-12-05 15:51:39 +0200 | [diff] [blame] | 3663 | return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL); |
| 3664 | } |
| 3665 | |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3666 | u8 intel_enabled_dbuf_slices_mask(struct drm_i915_private *dev_priv) |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3667 | { |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3668 | u8 enabled_slices = 0; |
| 3669 | enum dbuf_slice slice; |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3670 | |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3671 | for_each_dbuf_slice(dev_priv, slice) { |
| 3672 | if (intel_uncore_read(&dev_priv->uncore, |
| 3673 | DBUF_CTL_S(slice)) & DBUF_POWER_STATE) |
| 3674 | enabled_slices |= BIT(slice); |
Stanislav Lisovskiy | 0f0f9ae | 2020-02-03 01:06:29 +0200 | [diff] [blame] | 3675 | } |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3676 | |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 3677 | return enabled_slices; |
Mahesh Kumar | 74bd800 | 2018-04-26 19:55:15 +0530 | [diff] [blame] | 3678 | } |
| 3679 | |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 3680 | /* |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3681 | * FIXME: We still don't have the proper code detect if we need to apply the WA, |
| 3682 | * so assume we'll always need it in order to avoid underruns. |
| 3683 | */ |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 3684 | 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] | 3685 | { |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3686 | return DISPLAY_VER(dev_priv) == 9; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3687 | } |
| 3688 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3689 | static bool |
| 3690 | intel_has_sagv(struct drm_i915_private *dev_priv) |
| 3691 | { |
Matt Roper | 70bfb30 | 2021-04-07 13:39:45 -0700 | [diff] [blame] | 3692 | return DISPLAY_VER(dev_priv) >= 9 && !IS_LP(dev_priv) && |
Rodrigo Vivi | 1ca2b06 | 2018-10-26 13:03:17 -0700 | [diff] [blame] | 3693 | dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED; |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3694 | } |
| 3695 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3696 | static void |
| 3697 | skl_setup_sagv_block_time(struct drm_i915_private *dev_priv) |
| 3698 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3699 | if (DISPLAY_VER(dev_priv) >= 12) { |
James Ausmus | da80f04 | 2019-10-09 10:23:15 -0700 | [diff] [blame] | 3700 | u32 val = 0; |
| 3701 | int ret; |
| 3702 | |
| 3703 | ret = sandybridge_pcode_read(dev_priv, |
| 3704 | GEN12_PCODE_READ_SAGV_BLOCK_TIME_US, |
| 3705 | &val, NULL); |
| 3706 | if (!ret) { |
| 3707 | dev_priv->sagv_block_time_us = val; |
| 3708 | return; |
| 3709 | } |
| 3710 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3711 | 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] | 3712 | } else if (DISPLAY_VER(dev_priv) == 11) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3713 | dev_priv->sagv_block_time_us = 10; |
| 3714 | return; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3715 | } else if (DISPLAY_VER(dev_priv) == 10) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3716 | dev_priv->sagv_block_time_us = 20; |
| 3717 | return; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 3718 | } else if (DISPLAY_VER(dev_priv) == 9) { |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3719 | dev_priv->sagv_block_time_us = 30; |
| 3720 | return; |
| 3721 | } else { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3722 | MISSING_CASE(DISPLAY_VER(dev_priv)); |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 3723 | } |
| 3724 | |
| 3725 | /* Default to an unusable block time */ |
| 3726 | dev_priv->sagv_block_time_us = -1; |
| 3727 | } |
| 3728 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3729 | /* |
| 3730 | * SAGV dynamically adjusts the system agent voltage and clock frequencies |
| 3731 | * depending on power and performance requirements. The display engine access |
| 3732 | * to system memory is blocked during the adjustment time. Because of the |
| 3733 | * blocking time, having this enabled can cause full system hangs and/or pipe |
| 3734 | * underruns if we don't meet all of the following requirements: |
| 3735 | * |
| 3736 | * - <= 1 pipe enabled |
| 3737 | * - All planes can enable watermarks for latencies >= SAGV engine block time |
| 3738 | * - We're not using an interlaced display configuration |
| 3739 | */ |
Ville Syrjälä | 7102404 | 2020-09-25 15:17:48 +0300 | [diff] [blame] | 3740 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3741 | intel_enable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3742 | { |
| 3743 | int ret; |
| 3744 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3745 | if (!intel_has_sagv(dev_priv)) |
| 3746 | return 0; |
| 3747 | |
| 3748 | if (dev_priv->sagv_status == I915_SAGV_ENABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3749 | return 0; |
| 3750 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3751 | drm_dbg_kms(&dev_priv->drm, "Enabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3752 | ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3753 | GEN9_SAGV_ENABLE); |
| 3754 | |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3755 | /* We don't need to wait for SAGV when enabling */ |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3756 | |
| 3757 | /* |
| 3758 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3759 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3760 | */ |
Paulo Zanoni | 6e3100e | 2016-09-22 18:00:29 -0300 | [diff] [blame] | 3761 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3762 | drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3763 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3764 | return 0; |
| 3765 | } else if (ret < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3766 | drm_err(&dev_priv->drm, "Failed to enable SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3767 | return ret; |
| 3768 | } |
| 3769 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3770 | dev_priv->sagv_status = I915_SAGV_ENABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3771 | return 0; |
| 3772 | } |
| 3773 | |
Ville Syrjälä | 7102404 | 2020-09-25 15:17:48 +0300 | [diff] [blame] | 3774 | static int |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3775 | intel_disable_sagv(struct drm_i915_private *dev_priv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3776 | { |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3777 | int ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3778 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 3779 | if (!intel_has_sagv(dev_priv)) |
| 3780 | return 0; |
| 3781 | |
| 3782 | if (dev_priv->sagv_status == I915_SAGV_DISABLED) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3783 | return 0; |
| 3784 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3785 | drm_dbg_kms(&dev_priv->drm, "Disabling SAGV\n"); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3786 | /* bspec says to keep retrying for at least 1 ms */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3787 | ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL, |
| 3788 | GEN9_SAGV_DISABLE, |
| 3789 | GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED, |
| 3790 | 1); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3791 | /* |
| 3792 | * Some skl systems, pre-release machines in particular, |
Ville Syrjälä | ff61a97 | 2018-12-21 19:14:34 +0200 | [diff] [blame] | 3793 | * don't actually have SAGV. |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3794 | */ |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3795 | if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3796 | drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n"); |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3797 | dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3798 | return 0; |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3799 | } else if (ret < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 3800 | drm_err(&dev_priv->drm, "Failed to disable SAGV (%d)\n", ret); |
Imre Deak | b3b8e99 | 2016-12-05 18:27:38 +0200 | [diff] [blame] | 3801 | return ret; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3802 | } |
| 3803 | |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 3804 | dev_priv->sagv_status = I915_SAGV_DISABLED; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3805 | return 0; |
| 3806 | } |
| 3807 | |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3808 | void intel_sagv_pre_plane_update(struct intel_atomic_state *state) |
| 3809 | { |
| 3810 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3811 | const struct intel_bw_state *new_bw_state; |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3812 | const struct intel_bw_state *old_bw_state; |
| 3813 | u32 new_mask = 0; |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3814 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3815 | /* |
| 3816 | * Just return if we can't control SAGV or don't have it. |
| 3817 | * This is different from situation when we have SAGV but just can't |
| 3818 | * afford it due to DBuf limitation - in case if SAGV is completely |
| 3819 | * disabled in a BIOS, we are not even allowed to send a PCode request, |
| 3820 | * as it will throw an error. So have to check it here. |
| 3821 | */ |
| 3822 | if (!intel_has_sagv(dev_priv)) |
| 3823 | return; |
| 3824 | |
| 3825 | new_bw_state = intel_atomic_get_new_bw_state(state); |
| 3826 | if (!new_bw_state) |
| 3827 | return; |
| 3828 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3829 | 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] | 3830 | intel_disable_sagv(dev_priv); |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3831 | return; |
| 3832 | } |
| 3833 | |
| 3834 | old_bw_state = intel_atomic_get_old_bw_state(state); |
| 3835 | /* |
| 3836 | * Nothing to mask |
| 3837 | */ |
| 3838 | if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask) |
| 3839 | return; |
| 3840 | |
| 3841 | new_mask = old_bw_state->qgv_points_mask | new_bw_state->qgv_points_mask; |
| 3842 | |
| 3843 | /* |
| 3844 | * If new mask is zero - means there is nothing to mask, |
| 3845 | * we can only unmask, which should be done in unmask. |
| 3846 | */ |
| 3847 | if (!new_mask) |
| 3848 | return; |
| 3849 | |
| 3850 | /* |
| 3851 | * Restrict required qgv points before updating the configuration. |
| 3852 | * According to BSpec we can't mask and unmask qgv points at the same |
| 3853 | * time. Also masking should be done before updating the configuration |
| 3854 | * and unmasking afterwards. |
| 3855 | */ |
| 3856 | icl_pcode_restrict_qgv_points(dev_priv, new_mask); |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3857 | } |
| 3858 | |
| 3859 | void intel_sagv_post_plane_update(struct intel_atomic_state *state) |
| 3860 | { |
| 3861 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3862 | const struct intel_bw_state *new_bw_state; |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3863 | const struct intel_bw_state *old_bw_state; |
| 3864 | u32 new_mask = 0; |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3865 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3866 | /* |
| 3867 | * Just return if we can't control SAGV or don't have it. |
| 3868 | * This is different from situation when we have SAGV but just can't |
| 3869 | * afford it due to DBuf limitation - in case if SAGV is completely |
| 3870 | * disabled in a BIOS, we are not even allowed to send a PCode request, |
| 3871 | * as it will throw an error. So have to check it here. |
| 3872 | */ |
| 3873 | if (!intel_has_sagv(dev_priv)) |
| 3874 | return; |
| 3875 | |
| 3876 | new_bw_state = intel_atomic_get_new_bw_state(state); |
| 3877 | if (!new_bw_state) |
| 3878 | return; |
| 3879 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3880 | 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] | 3881 | intel_enable_sagv(dev_priv); |
Stanislav Lisovskiy | 20f505f | 2020-05-14 10:48:52 +0300 | [diff] [blame] | 3882 | return; |
| 3883 | } |
| 3884 | |
| 3885 | old_bw_state = intel_atomic_get_old_bw_state(state); |
| 3886 | /* |
| 3887 | * Nothing to unmask |
| 3888 | */ |
| 3889 | if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask) |
| 3890 | return; |
| 3891 | |
| 3892 | new_mask = new_bw_state->qgv_points_mask; |
| 3893 | |
| 3894 | /* |
| 3895 | * Allow required qgv points after updating the configuration. |
| 3896 | * According to BSpec we can't mask and unmask qgv points at the same |
| 3897 | * time. Also masking should be done before updating the configuration |
| 3898 | * and unmasking afterwards. |
| 3899 | */ |
| 3900 | icl_pcode_restrict_qgv_points(dev_priv, new_mask); |
Stanislav Lisovskiy | 680e1af | 2020-04-15 17:39:04 +0300 | [diff] [blame] | 3901 | } |
| 3902 | |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3903 | 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] | 3904 | { |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3905 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3906 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3907 | enum plane_id plane_id; |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3908 | int max_level = INT_MAX; |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3909 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3910 | if (!intel_has_sagv(dev_priv)) |
| 3911 | return false; |
| 3912 | |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3913 | if (!crtc_state->hw.active) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3914 | return true; |
Lucas De Marchi | da17223 | 2019-04-04 16:04:26 -0700 | [diff] [blame] | 3915 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 3916 | if (crtc_state->hw.pipe_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3917 | return false; |
| 3918 | |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3919 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3920 | const struct skl_plane_wm *wm = |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 3921 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3922 | int level; |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 3923 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3924 | /* Skip this plane if it's not enabled */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3925 | if (!wm->wm[0].enable) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3926 | continue; |
| 3927 | |
| 3928 | /* Find the highest enabled wm level for this plane */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3929 | for (level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3930 | !wm->wm[level].enable; --level) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3931 | { } |
| 3932 | |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3933 | /* Highest common enabled wm level for all planes */ |
| 3934 | max_level = min(level, max_level); |
| 3935 | } |
| 3936 | |
| 3937 | /* No enabled planes? */ |
| 3938 | if (max_level == INT_MAX) |
| 3939 | return true; |
| 3940 | |
| 3941 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 3942 | const struct skl_plane_wm *wm = |
| 3943 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3944 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3945 | /* |
Ville Syrjälä | cdf6462 | 2021-03-05 17:36:06 +0200 | [diff] [blame] | 3946 | * All enabled planes must have enabled a common wm level that |
| 3947 | * can tolerate memory latencies higher than sagv_block_time_us |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3948 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3949 | if (wm->wm[0].enable && !wm->wm[max_level].can_sagv) |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 3950 | return false; |
| 3951 | } |
| 3952 | |
| 3953 | return true; |
| 3954 | } |
| 3955 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3956 | static bool tgl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
| 3957 | { |
| 3958 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 3959 | enum plane_id plane_id; |
| 3960 | |
| 3961 | if (!crtc_state->hw.active) |
| 3962 | return true; |
| 3963 | |
| 3964 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3965 | const struct skl_plane_wm *wm = |
| 3966 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
| 3967 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 3968 | if (wm->wm[0].enable && !wm->sagv.wm0.enable) |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3969 | return false; |
| 3970 | } |
| 3971 | |
| 3972 | return true; |
| 3973 | } |
| 3974 | |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3975 | static bool intel_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state) |
| 3976 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3977 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 3978 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 3979 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3980 | if (DISPLAY_VER(dev_priv) >= 12) |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 3981 | return tgl_crtc_can_enable_sagv(crtc_state); |
| 3982 | else |
| 3983 | return skl_crtc_can_enable_sagv(crtc_state); |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 3984 | } |
| 3985 | |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3986 | bool intel_can_enable_sagv(struct drm_i915_private *dev_priv, |
| 3987 | const struct intel_bw_state *bw_state) |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 3988 | { |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 3989 | if (DISPLAY_VER(dev_priv) < 11 && |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3990 | bw_state->active_pipes && !is_power_of_2(bw_state->active_pipes)) |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 3991 | return false; |
| 3992 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3993 | return bw_state->pipe_sagv_reject == 0; |
| 3994 | } |
| 3995 | |
| 3996 | static int intel_compute_sagv_mask(struct intel_atomic_state *state) |
| 3997 | { |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 3998 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 3999 | int ret; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4000 | struct intel_crtc *crtc; |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 4001 | struct intel_crtc_state *new_crtc_state; |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4002 | struct intel_bw_state *new_bw_state = NULL; |
| 4003 | const struct intel_bw_state *old_bw_state = NULL; |
| 4004 | int i; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4005 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4006 | for_each_new_intel_crtc_in_state(state, crtc, |
| 4007 | new_crtc_state, i) { |
| 4008 | new_bw_state = intel_atomic_get_bw_state(state); |
| 4009 | if (IS_ERR(new_bw_state)) |
| 4010 | return PTR_ERR(new_bw_state); |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4011 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4012 | old_bw_state = intel_atomic_get_old_bw_state(state); |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4013 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4014 | if (intel_crtc_can_enable_sagv(new_crtc_state)) |
| 4015 | new_bw_state->pipe_sagv_reject &= ~BIT(crtc->pipe); |
| 4016 | else |
| 4017 | new_bw_state->pipe_sagv_reject |= BIT(crtc->pipe); |
| 4018 | } |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4019 | |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4020 | if (!new_bw_state) |
| 4021 | return 0; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4022 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 4023 | new_bw_state->active_pipes = |
| 4024 | intel_calc_active_pipes(state, old_bw_state->active_pipes); |
Stanislav Lisovskiy | 1d0a6c8 | 2020-05-13 12:38:12 +0300 | [diff] [blame] | 4025 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 4026 | if (new_bw_state->active_pipes != old_bw_state->active_pipes) { |
| 4027 | ret = intel_atomic_lock_global_state(&new_bw_state->base); |
| 4028 | if (ret) |
| 4029 | return ret; |
| 4030 | } |
| 4031 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 4032 | for_each_new_intel_crtc_in_state(state, crtc, |
| 4033 | new_crtc_state, i) { |
| 4034 | struct skl_pipe_wm *pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 4035 | |
| 4036 | /* |
| 4037 | * We store use_sagv_wm in the crtc state rather than relying on |
| 4038 | * that bw state since we have no convenient way to get at the |
| 4039 | * latter from the plane commit hooks (especially in the legacy |
| 4040 | * cursor case) |
| 4041 | */ |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 4042 | pipe_wm->use_sagv_wm = !HAS_HW_SAGV_WM(dev_priv) && |
| 4043 | DISPLAY_VER(dev_priv) >= 12 && |
| 4044 | intel_can_enable_sagv(dev_priv, new_bw_state); |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 4045 | } |
| 4046 | |
Stanislav Lisovskiy | d8d5afe | 2020-05-13 12:38:13 +0300 | [diff] [blame] | 4047 | if (intel_can_enable_sagv(dev_priv, new_bw_state) != |
| 4048 | intel_can_enable_sagv(dev_priv, old_bw_state)) { |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 4049 | ret = intel_atomic_serialize_global_state(&new_bw_state->base); |
| 4050 | if (ret) |
| 4051 | return ret; |
| 4052 | } else if (new_bw_state->pipe_sagv_reject != old_bw_state->pipe_sagv_reject) { |
| 4053 | ret = intel_atomic_lock_global_state(&new_bw_state->base); |
| 4054 | if (ret) |
| 4055 | return ret; |
| 4056 | } |
| 4057 | |
| 4058 | return 0; |
Stanislav Lisovskiy | a389c49 | 2020-04-15 17:57:40 +0300 | [diff] [blame] | 4059 | } |
| 4060 | |
Ville Syrjälä | 944a5e3 | 2021-01-22 22:56:28 +0200 | [diff] [blame] | 4061 | static int intel_dbuf_slice_size(struct drm_i915_private *dev_priv) |
| 4062 | { |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 4063 | return INTEL_INFO(dev_priv)->dbuf.size / |
| 4064 | hweight8(INTEL_INFO(dev_priv)->dbuf.slice_mask); |
Ville Syrjälä | 944a5e3 | 2021-01-22 22:56:28 +0200 | [diff] [blame] | 4065 | } |
| 4066 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4067 | static void |
| 4068 | skl_ddb_entry_for_slices(struct drm_i915_private *dev_priv, u8 slice_mask, |
| 4069 | struct skl_ddb_entry *ddb) |
Mahesh Kumar | aa9664f | 2018-04-26 19:55:16 +0530 | [diff] [blame] | 4070 | { |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4071 | int slice_size = intel_dbuf_slice_size(dev_priv); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4072 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4073 | if (!slice_mask) { |
| 4074 | ddb->start = 0; |
| 4075 | ddb->end = 0; |
| 4076 | return; |
| 4077 | } |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4078 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4079 | ddb->start = (ffs(slice_mask) - 1) * slice_size; |
| 4080 | ddb->end = fls(slice_mask) * slice_size; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4081 | |
Ville Syrjälä | 96dc6ed | 2021-01-22 22:56:29 +0200 | [diff] [blame] | 4082 | WARN_ON(ddb->start >= ddb->end); |
Ville Syrjälä | b88da66 | 2021-04-16 20:10:09 +0300 | [diff] [blame] | 4083 | WARN_ON(ddb->end > INTEL_INFO(dev_priv)->dbuf.size); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4084 | } |
| 4085 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4086 | static unsigned int mbus_ddb_offset(struct drm_i915_private *i915, u8 slice_mask) |
| 4087 | { |
| 4088 | struct skl_ddb_entry ddb; |
| 4089 | |
| 4090 | if (slice_mask & (BIT(DBUF_S1) | BIT(DBUF_S2))) |
| 4091 | slice_mask = BIT(DBUF_S1); |
| 4092 | else if (slice_mask & (BIT(DBUF_S3) | BIT(DBUF_S4))) |
| 4093 | slice_mask = BIT(DBUF_S3); |
| 4094 | |
| 4095 | skl_ddb_entry_for_slices(i915, slice_mask, &ddb); |
| 4096 | |
| 4097 | return ddb.start; |
| 4098 | } |
| 4099 | |
Stanislav Lisovskiy | cd19154 | 2020-05-20 18:00:58 +0300 | [diff] [blame] | 4100 | u32 skl_ddb_dbuf_slice_mask(struct drm_i915_private *dev_priv, |
| 4101 | const struct skl_ddb_entry *entry) |
| 4102 | { |
Ville Syrjälä | 6390e5a | 2021-04-16 20:10:07 +0300 | [diff] [blame] | 4103 | int slice_size = intel_dbuf_slice_size(dev_priv); |
| 4104 | enum dbuf_slice start_slice, end_slice; |
| 4105 | u8 slice_mask = 0; |
Stanislav Lisovskiy | cd19154 | 2020-05-20 18:00:58 +0300 | [diff] [blame] | 4106 | |
| 4107 | if (!skl_ddb_entry_size(entry)) |
| 4108 | return 0; |
| 4109 | |
| 4110 | start_slice = entry->start / slice_size; |
| 4111 | end_slice = (entry->end - 1) / slice_size; |
| 4112 | |
| 4113 | /* |
| 4114 | * Per plane DDB entry can in a really worst case be on multiple slices |
| 4115 | * but single entry is anyway contigious. |
| 4116 | */ |
| 4117 | while (start_slice <= end_slice) { |
| 4118 | slice_mask |= BIT(start_slice); |
| 4119 | start_slice++; |
| 4120 | } |
| 4121 | |
| 4122 | return slice_mask; |
| 4123 | } |
| 4124 | |
Ville Syrjälä | 2791a40 | 2021-01-22 22:56:26 +0200 | [diff] [blame] | 4125 | static unsigned int intel_crtc_ddb_weight(const struct intel_crtc_state *crtc_state) |
| 4126 | { |
| 4127 | const struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode; |
| 4128 | int hdisplay, vdisplay; |
| 4129 | |
| 4130 | if (!crtc_state->hw.active) |
| 4131 | return 0; |
| 4132 | |
| 4133 | /* |
| 4134 | * Watermark/ddb requirement highly depends upon width of the |
| 4135 | * framebuffer, So instead of allocating DDB equally among pipes |
| 4136 | * distribute DDB based on resolution/width of the display. |
| 4137 | */ |
| 4138 | drm_mode_get_hv_timing(pipe_mode, &hdisplay, &vdisplay); |
| 4139 | |
| 4140 | return hdisplay; |
| 4141 | } |
| 4142 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4143 | static void intel_crtc_dbuf_weights(const struct intel_dbuf_state *dbuf_state, |
| 4144 | enum pipe for_pipe, |
| 4145 | unsigned int *weight_start, |
| 4146 | unsigned int *weight_end, |
| 4147 | unsigned int *weight_total) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4148 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4149 | struct drm_i915_private *dev_priv = |
| 4150 | to_i915(dbuf_state->base.state->base.dev); |
| 4151 | enum pipe pipe; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4152 | |
| 4153 | *weight_start = 0; |
| 4154 | *weight_end = 0; |
| 4155 | *weight_total = 0; |
| 4156 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4157 | for_each_pipe(dev_priv, pipe) { |
| 4158 | int weight = dbuf_state->weight[pipe]; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4159 | |
| 4160 | /* |
| 4161 | * Do not account pipes using other slice sets |
| 4162 | * luckily as of current BSpec slice sets do not partially |
| 4163 | * intersect(pipes share either same one slice or same slice set |
| 4164 | * i.e no partial intersection), so it is enough to check for |
| 4165 | * equality for now. |
| 4166 | */ |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4167 | if (dbuf_state->slices[pipe] != dbuf_state->slices[for_pipe]) |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4168 | continue; |
| 4169 | |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4170 | *weight_total += weight; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4171 | if (pipe < for_pipe) { |
| 4172 | *weight_start += weight; |
| 4173 | *weight_end += weight; |
| 4174 | } else if (pipe == for_pipe) { |
| 4175 | *weight_end += weight; |
| 4176 | } |
Mahesh Kumar | cf1f697 | 2018-08-01 20:41:13 +0530 | [diff] [blame] | 4177 | } |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | static int |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4181 | 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] | 4182 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4183 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4184 | unsigned int weight_total, weight_start, weight_end; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4185 | const struct intel_dbuf_state *old_dbuf_state = |
| 4186 | intel_atomic_get_old_dbuf_state(state); |
| 4187 | struct intel_dbuf_state *new_dbuf_state = |
| 4188 | intel_atomic_get_new_dbuf_state(state); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4189 | struct intel_crtc_state *crtc_state; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4190 | struct skl_ddb_entry ddb_slices; |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4191 | enum pipe pipe = crtc->pipe; |
Manasi Navare | e2bebb9 | 2021-06-03 14:53:38 -0700 | [diff] [blame] | 4192 | unsigned int mbus_offset = 0; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4193 | u32 ddb_range_size; |
| 4194 | u32 dbuf_slice_mask; |
| 4195 | u32 start, end; |
| 4196 | int ret; |
| 4197 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4198 | if (new_dbuf_state->weight[pipe] == 0) { |
| 4199 | new_dbuf_state->ddb[pipe].start = 0; |
| 4200 | new_dbuf_state->ddb[pipe].end = 0; |
| 4201 | goto out; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4202 | } |
| 4203 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4204 | dbuf_slice_mask = new_dbuf_state->slices[pipe]; |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4205 | |
| 4206 | 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] | 4207 | mbus_offset = mbus_ddb_offset(dev_priv, dbuf_slice_mask); |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4208 | ddb_range_size = skl_ddb_entry_size(&ddb_slices); |
| 4209 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4210 | intel_crtc_dbuf_weights(new_dbuf_state, pipe, |
| 4211 | &weight_start, &weight_end, &weight_total); |
Ville Syrjälä | 5363096 | 2021-01-22 22:56:31 +0200 | [diff] [blame] | 4212 | |
| 4213 | start = ddb_range_size * weight_start / weight_total; |
| 4214 | end = ddb_range_size * weight_end / weight_total; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4215 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4216 | new_dbuf_state->ddb[pipe].start = ddb_slices.start - mbus_offset + start; |
| 4217 | 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] | 4218 | out: |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4219 | if (old_dbuf_state->slices[pipe] == new_dbuf_state->slices[pipe] && |
| 4220 | skl_ddb_entry_equal(&old_dbuf_state->ddb[pipe], |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4221 | &new_dbuf_state->ddb[pipe])) |
| 4222 | return 0; |
| 4223 | |
| 4224 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 4225 | if (ret) |
| 4226 | return ret; |
| 4227 | |
| 4228 | crtc_state = intel_atomic_get_crtc_state(&state->base, crtc); |
| 4229 | if (IS_ERR(crtc_state)) |
| 4230 | return PTR_ERR(crtc_state); |
| 4231 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 4232 | /* |
| 4233 | * Used for checking overlaps, so we need absolute |
| 4234 | * offsets instead of MBUS relative offsets. |
| 4235 | */ |
| 4236 | crtc_state->wm.skl.ddb.start = mbus_offset + new_dbuf_state->ddb[pipe].start; |
| 4237 | 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] | 4238 | |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 4239 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4240 | "[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] | 4241 | crtc->base.base.id, crtc->base.name, |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 4242 | old_dbuf_state->slices[pipe], new_dbuf_state->slices[pipe], |
| 4243 | old_dbuf_state->ddb[pipe].start, old_dbuf_state->ddb[pipe].end, |
| 4244 | new_dbuf_state->ddb[pipe].start, new_dbuf_state->ddb[pipe].end, |
| 4245 | old_dbuf_state->active_pipes, new_dbuf_state->active_pipes); |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 4246 | |
| 4247 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4248 | } |
| 4249 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4250 | static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 4251 | int width, const struct drm_format_info *format, |
| 4252 | u64 modifier, unsigned int rotation, |
| 4253 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 4254 | int color_plane); |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4255 | 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] | 4256 | int level, |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 4257 | unsigned int latency, |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4258 | const struct skl_wm_params *wp, |
| 4259 | const struct skl_wm_level *result_prev, |
| 4260 | struct skl_wm_level *result /* out */); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4261 | |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4262 | static unsigned int |
| 4263 | skl_cursor_allocation(const struct intel_crtc_state *crtc_state, |
| 4264 | int num_active) |
| 4265 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 4266 | 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] | 4267 | int level, max_level = ilk_wm_max_level(dev_priv); |
| 4268 | struct skl_wm_level wm = {}; |
| 4269 | int ret, min_ddb_alloc = 0; |
| 4270 | struct skl_wm_params wp; |
| 4271 | |
| 4272 | ret = skl_compute_wm_params(crtc_state, 256, |
| 4273 | drm_format_info(DRM_FORMAT_ARGB8888), |
| 4274 | DRM_FORMAT_MOD_LINEAR, |
| 4275 | DRM_MODE_ROTATE_0, |
| 4276 | crtc_state->pixel_rate, &wp, 0); |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 4277 | drm_WARN_ON(&dev_priv->drm, ret); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4278 | |
| 4279 | for (level = 0; level <= max_level; level++) { |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 4280 | unsigned int latency = dev_priv->wm.skl_latency[level]; |
| 4281 | |
| 4282 | skl_compute_plane_wm(crtc_state, level, latency, &wp, &wm, &wm); |
Ville Syrjälä | df331de | 2019-03-19 18:03:11 +0200 | [diff] [blame] | 4283 | if (wm.min_ddb_alloc == U16_MAX) |
| 4284 | break; |
| 4285 | |
| 4286 | min_ddb_alloc = wm.min_ddb_alloc; |
| 4287 | } |
| 4288 | |
| 4289 | return max(num_active == 1 ? 32 : 8, min_ddb_alloc); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4290 | } |
| 4291 | |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4292 | static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv, |
| 4293 | struct skl_ddb_entry *entry, u32 reg) |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4294 | { |
Ville Syrjälä | d7e449a | 2019-02-05 22:50:56 +0200 | [diff] [blame] | 4295 | entry->start = reg & DDB_ENTRY_MASK; |
| 4296 | entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK; |
Mahesh Kumar | 37cde11 | 2018-04-26 19:55:17 +0530 | [diff] [blame] | 4297 | |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 4298 | if (entry->end) |
| 4299 | entry->end += 1; |
Damien Lespiau | a269c58 | 2014-11-04 17:06:49 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4302 | static void |
| 4303 | skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv, |
| 4304 | const enum pipe pipe, |
| 4305 | const enum plane_id plane_id, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4306 | struct skl_ddb_entry *ddb_y, |
| 4307 | struct skl_ddb_entry *ddb_uv) |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4308 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4309 | u32 val, val2; |
| 4310 | u32 fourcc = 0; |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4311 | |
| 4312 | /* Cursor doesn't support NV12/planar, so no extra calculation needed */ |
| 4313 | if (plane_id == PLANE_CURSOR) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4314 | val = intel_uncore_read(&dev_priv->uncore, CUR_BUF_CFG(pipe)); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4315 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4316 | return; |
| 4317 | } |
| 4318 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4319 | val = intel_uncore_read(&dev_priv->uncore, PLANE_CTL(pipe, plane_id)); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4320 | |
| 4321 | /* No DDB allocated for disabled planes */ |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4322 | if (val & PLANE_CTL_ENABLE) |
| 4323 | fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK, |
| 4324 | val & PLANE_CTL_ORDER_RGBX, |
| 4325 | val & PLANE_CTL_ALPHA_MASK); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4326 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 4327 | if (DISPLAY_VER(dev_priv) >= 11) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4328 | 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] | 4329 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4330 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 4331 | val = intel_uncore_read(&dev_priv->uncore, PLANE_BUF_CFG(pipe, plane_id)); |
| 4332 | 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] | 4333 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4334 | if (fourcc && |
| 4335 | drm_format_info_is_yuv_semiplanar(drm_format_info(fourcc))) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4336 | swap(val, val2); |
| 4337 | |
| 4338 | skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val); |
| 4339 | skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2); |
Mahesh Kumar | ddf3431 | 2018-04-09 09:11:03 +0530 | [diff] [blame] | 4340 | } |
| 4341 | } |
| 4342 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4343 | void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc, |
| 4344 | struct skl_ddb_entry *ddb_y, |
| 4345 | struct skl_ddb_entry *ddb_uv) |
| 4346 | { |
| 4347 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4348 | enum intel_display_power_domain power_domain; |
| 4349 | enum pipe pipe = crtc->pipe; |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4350 | intel_wakeref_t wakeref; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4351 | enum plane_id plane_id; |
| 4352 | |
| 4353 | power_domain = POWER_DOMAIN_PIPE(pipe); |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4354 | wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain); |
| 4355 | if (!wakeref) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4356 | return; |
| 4357 | |
| 4358 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 4359 | skl_ddb_get_hw_plane_state(dev_priv, pipe, |
| 4360 | plane_id, |
| 4361 | &ddb_y[plane_id], |
| 4362 | &ddb_uv[plane_id]); |
| 4363 | |
Chris Wilson | 0e6e0be | 2019-01-14 14:21:24 +0000 | [diff] [blame] | 4364 | intel_display_power_put(dev_priv, power_domain, wakeref); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 4365 | } |
| 4366 | |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4367 | /* |
| 4368 | * Determines the downscale amount of a plane for the purposes of watermark calculations. |
| 4369 | * The bspec defines downscale amount as: |
| 4370 | * |
| 4371 | * """ |
| 4372 | * Horizontal down scale amount = maximum[1, Horizontal source size / |
| 4373 | * Horizontal destination size] |
| 4374 | * Vertical down scale amount = maximum[1, Vertical source size / |
| 4375 | * Vertical destination size] |
| 4376 | * Total down scale amount = Horizontal down scale amount * |
| 4377 | * Vertical down scale amount |
| 4378 | * """ |
| 4379 | * |
| 4380 | * Return value is provided in 16.16 fixed point form to retain fractional part. |
| 4381 | * Caller should take care of dividing & rounding off the value. |
| 4382 | */ |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4383 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4384 | skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state, |
| 4385 | const struct intel_plane_state *plane_state) |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4386 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 4387 | 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] | 4388 | u32 src_w, src_h, dst_w, dst_h; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4389 | uint_fixed_16_16_t fp_w_ratio, fp_h_ratio; |
| 4390 | uint_fixed_16_16_t downscale_h, downscale_w; |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4391 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 4392 | if (drm_WARN_ON(&dev_priv->drm, |
| 4393 | !intel_wm_plane_visible(crtc_state, plane_state))) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4394 | return u32_to_fixed16(0); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4395 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 4396 | /* |
| 4397 | * Src coordinates are already rotated by 270 degrees for |
| 4398 | * the 90/270 degree plane rotation cases (to match the |
| 4399 | * GTT mapping), hence no need to account for rotation here. |
| 4400 | * |
| 4401 | * n.b., src is 16.16 fixed point, dst is whole integer. |
| 4402 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4403 | src_w = drm_rect_width(&plane_state->uapi.src) >> 16; |
| 4404 | src_h = drm_rect_height(&plane_state->uapi.src) >> 16; |
| 4405 | dst_w = drm_rect_width(&plane_state->uapi.dst); |
| 4406 | dst_h = drm_rect_height(&plane_state->uapi.dst); |
Ville Syrjälä | 93aa2a1 | 2017-03-14 17:10:50 +0200 | [diff] [blame] | 4407 | |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 4408 | fp_w_ratio = div_fixed16(src_w, dst_w); |
| 4409 | fp_h_ratio = div_fixed16(src_h, dst_h); |
| 4410 | downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1)); |
| 4411 | downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1)); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4412 | |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4413 | return mul_fixed16(downscale_w, downscale_h); |
Kumar, Mahesh | 9c2f7a9 | 2016-05-16 15:52:00 -0700 | [diff] [blame] | 4414 | } |
| 4415 | |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4416 | struct dbuf_slice_conf_entry { |
| 4417 | u8 active_pipes; |
| 4418 | u8 dbuf_mask[I915_MAX_PIPES]; |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4419 | bool join_mbus; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4420 | }; |
| 4421 | |
| 4422 | /* |
| 4423 | * Table taken from Bspec 12716 |
| 4424 | * Pipes do have some preferred DBuf slice affinity, |
| 4425 | * plus there are some hardcoded requirements on how |
| 4426 | * those should be distributed for multipipe scenarios. |
| 4427 | * For more DBuf slices algorithm can get even more messy |
| 4428 | * and less readable, so decided to use a table almost |
| 4429 | * as is from BSpec itself - that way it is at least easier |
| 4430 | * to compare, change and check. |
| 4431 | */ |
Jani Nikula | f8226d0 | 2020-02-19 17:45:42 +0200 | [diff] [blame] | 4432 | static const struct dbuf_slice_conf_entry icl_allowed_dbufs[] = |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4433 | /* Autogenerated with igt/tools/intel_dbuf_map tool: */ |
| 4434 | { |
| 4435 | { |
| 4436 | .active_pipes = BIT(PIPE_A), |
| 4437 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4438 | [PIPE_A] = BIT(DBUF_S1), |
| 4439 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4440 | }, |
| 4441 | { |
| 4442 | .active_pipes = BIT(PIPE_B), |
| 4443 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4444 | [PIPE_B] = BIT(DBUF_S1), |
| 4445 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4446 | }, |
| 4447 | { |
| 4448 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4449 | .dbuf_mask = { |
| 4450 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4451 | [PIPE_B] = BIT(DBUF_S2), |
| 4452 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4453 | }, |
| 4454 | { |
| 4455 | .active_pipes = BIT(PIPE_C), |
| 4456 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4457 | [PIPE_C] = BIT(DBUF_S2), |
| 4458 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4459 | }, |
| 4460 | { |
| 4461 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4462 | .dbuf_mask = { |
| 4463 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4464 | [PIPE_C] = BIT(DBUF_S2), |
| 4465 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4466 | }, |
| 4467 | { |
| 4468 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4469 | .dbuf_mask = { |
| 4470 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4471 | [PIPE_C] = BIT(DBUF_S2), |
| 4472 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4473 | }, |
| 4474 | { |
| 4475 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4476 | .dbuf_mask = { |
| 4477 | [PIPE_A] = BIT(DBUF_S1), |
| 4478 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4479 | [PIPE_C] = BIT(DBUF_S2), |
| 4480 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4481 | }, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4482 | {} |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4483 | }; |
| 4484 | |
| 4485 | /* |
| 4486 | * Table taken from Bspec 49255 |
| 4487 | * Pipes do have some preferred DBuf slice affinity, |
| 4488 | * plus there are some hardcoded requirements on how |
| 4489 | * those should be distributed for multipipe scenarios. |
| 4490 | * For more DBuf slices algorithm can get even more messy |
| 4491 | * and less readable, so decided to use a table almost |
| 4492 | * as is from BSpec itself - that way it is at least easier |
| 4493 | * to compare, change and check. |
| 4494 | */ |
Jani Nikula | f8226d0 | 2020-02-19 17:45:42 +0200 | [diff] [blame] | 4495 | static const struct dbuf_slice_conf_entry tgl_allowed_dbufs[] = |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4496 | /* Autogenerated with igt/tools/intel_dbuf_map tool: */ |
| 4497 | { |
| 4498 | { |
| 4499 | .active_pipes = BIT(PIPE_A), |
| 4500 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4501 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4502 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4503 | }, |
| 4504 | { |
| 4505 | .active_pipes = BIT(PIPE_B), |
| 4506 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4507 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4508 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4509 | }, |
| 4510 | { |
| 4511 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4512 | .dbuf_mask = { |
| 4513 | [PIPE_A] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4514 | [PIPE_B] = BIT(DBUF_S1), |
| 4515 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4516 | }, |
| 4517 | { |
| 4518 | .active_pipes = BIT(PIPE_C), |
| 4519 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4520 | [PIPE_C] = BIT(DBUF_S2) | BIT(DBUF_S1), |
| 4521 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4522 | }, |
| 4523 | { |
| 4524 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4525 | .dbuf_mask = { |
| 4526 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4527 | [PIPE_C] = BIT(DBUF_S2), |
| 4528 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4529 | }, |
| 4530 | { |
| 4531 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4532 | .dbuf_mask = { |
| 4533 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4534 | [PIPE_C] = BIT(DBUF_S2), |
| 4535 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4536 | }, |
| 4537 | { |
| 4538 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4539 | .dbuf_mask = { |
| 4540 | [PIPE_A] = BIT(DBUF_S1), |
| 4541 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4542 | [PIPE_C] = BIT(DBUF_S2), |
| 4543 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4544 | }, |
| 4545 | { |
| 4546 | .active_pipes = BIT(PIPE_D), |
| 4547 | .dbuf_mask = { |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4548 | [PIPE_D] = BIT(DBUF_S2) | BIT(DBUF_S1), |
| 4549 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4550 | }, |
| 4551 | { |
| 4552 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4553 | .dbuf_mask = { |
| 4554 | [PIPE_A] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4555 | [PIPE_D] = BIT(DBUF_S2), |
| 4556 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4557 | }, |
| 4558 | { |
| 4559 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4560 | .dbuf_mask = { |
| 4561 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4562 | [PIPE_D] = BIT(DBUF_S2), |
| 4563 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4564 | }, |
| 4565 | { |
| 4566 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D), |
| 4567 | .dbuf_mask = { |
| 4568 | [PIPE_A] = BIT(DBUF_S1), |
| 4569 | [PIPE_B] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4570 | [PIPE_D] = BIT(DBUF_S2), |
| 4571 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4572 | }, |
| 4573 | { |
| 4574 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4575 | .dbuf_mask = { |
| 4576 | [PIPE_C] = BIT(DBUF_S1), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4577 | [PIPE_D] = BIT(DBUF_S2), |
| 4578 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4579 | }, |
| 4580 | { |
| 4581 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4582 | .dbuf_mask = { |
| 4583 | [PIPE_A] = BIT(DBUF_S1), |
| 4584 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4585 | [PIPE_D] = BIT(DBUF_S2), |
| 4586 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4587 | }, |
| 4588 | { |
| 4589 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4590 | .dbuf_mask = { |
| 4591 | [PIPE_B] = BIT(DBUF_S1), |
| 4592 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4593 | [PIPE_D] = BIT(DBUF_S2), |
| 4594 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4595 | }, |
| 4596 | { |
| 4597 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4598 | .dbuf_mask = { |
| 4599 | [PIPE_A] = BIT(DBUF_S1), |
| 4600 | [PIPE_B] = BIT(DBUF_S1), |
| 4601 | [PIPE_C] = BIT(DBUF_S2), |
Ville Syrjälä | 06812bd | 2020-02-25 19:11:08 +0200 | [diff] [blame] | 4602 | [PIPE_D] = BIT(DBUF_S2), |
| 4603 | }, |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4604 | }, |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4605 | {} |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4606 | }; |
| 4607 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4608 | static const struct dbuf_slice_conf_entry dg2_allowed_dbufs[] = { |
| 4609 | { |
| 4610 | .active_pipes = BIT(PIPE_A), |
| 4611 | .dbuf_mask = { |
| 4612 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4613 | }, |
| 4614 | }, |
| 4615 | { |
| 4616 | .active_pipes = BIT(PIPE_B), |
| 4617 | .dbuf_mask = { |
| 4618 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4619 | }, |
| 4620 | }, |
| 4621 | { |
| 4622 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4623 | .dbuf_mask = { |
| 4624 | [PIPE_A] = BIT(DBUF_S1), |
| 4625 | [PIPE_B] = BIT(DBUF_S2), |
| 4626 | }, |
| 4627 | }, |
| 4628 | { |
| 4629 | .active_pipes = BIT(PIPE_C), |
| 4630 | .dbuf_mask = { |
| 4631 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4632 | }, |
| 4633 | }, |
| 4634 | { |
| 4635 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4636 | .dbuf_mask = { |
| 4637 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4638 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4639 | }, |
| 4640 | }, |
| 4641 | { |
| 4642 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4643 | .dbuf_mask = { |
| 4644 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4645 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4646 | }, |
| 4647 | }, |
| 4648 | { |
| 4649 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4650 | .dbuf_mask = { |
| 4651 | [PIPE_A] = BIT(DBUF_S1), |
| 4652 | [PIPE_B] = BIT(DBUF_S2), |
| 4653 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4654 | }, |
| 4655 | }, |
| 4656 | { |
| 4657 | .active_pipes = BIT(PIPE_D), |
| 4658 | .dbuf_mask = { |
| 4659 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4660 | }, |
| 4661 | }, |
| 4662 | { |
| 4663 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4664 | .dbuf_mask = { |
| 4665 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4666 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4667 | }, |
| 4668 | }, |
| 4669 | { |
| 4670 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4671 | .dbuf_mask = { |
| 4672 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4673 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4674 | }, |
| 4675 | }, |
| 4676 | { |
| 4677 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D), |
| 4678 | .dbuf_mask = { |
| 4679 | [PIPE_A] = BIT(DBUF_S1), |
| 4680 | [PIPE_B] = BIT(DBUF_S2), |
| 4681 | [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4682 | }, |
| 4683 | }, |
| 4684 | { |
| 4685 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4686 | .dbuf_mask = { |
| 4687 | [PIPE_C] = BIT(DBUF_S3), |
| 4688 | [PIPE_D] = BIT(DBUF_S4), |
| 4689 | }, |
| 4690 | }, |
| 4691 | { |
| 4692 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4693 | .dbuf_mask = { |
| 4694 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4695 | [PIPE_C] = BIT(DBUF_S3), |
| 4696 | [PIPE_D] = BIT(DBUF_S4), |
| 4697 | }, |
| 4698 | }, |
| 4699 | { |
| 4700 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4701 | .dbuf_mask = { |
| 4702 | [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4703 | [PIPE_C] = BIT(DBUF_S3), |
| 4704 | [PIPE_D] = BIT(DBUF_S4), |
| 4705 | }, |
| 4706 | }, |
| 4707 | { |
| 4708 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4709 | .dbuf_mask = { |
| 4710 | [PIPE_A] = BIT(DBUF_S1), |
| 4711 | [PIPE_B] = BIT(DBUF_S2), |
| 4712 | [PIPE_C] = BIT(DBUF_S3), |
| 4713 | [PIPE_D] = BIT(DBUF_S4), |
| 4714 | }, |
| 4715 | }, |
| 4716 | {} |
| 4717 | }; |
| 4718 | |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4719 | static const struct dbuf_slice_conf_entry adlp_allowed_dbufs[] = { |
| 4720 | { |
| 4721 | .active_pipes = BIT(PIPE_A), |
| 4722 | .dbuf_mask = { |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4723 | [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] | 4724 | }, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4725 | .join_mbus = true, |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4726 | }, |
| 4727 | { |
| 4728 | .active_pipes = BIT(PIPE_B), |
| 4729 | .dbuf_mask = { |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4730 | [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] | 4731 | }, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4732 | .join_mbus = true, |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4733 | }, |
| 4734 | { |
| 4735 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B), |
| 4736 | .dbuf_mask = { |
| 4737 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4738 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4739 | }, |
| 4740 | }, |
| 4741 | { |
| 4742 | .active_pipes = BIT(PIPE_C), |
| 4743 | .dbuf_mask = { |
| 4744 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4745 | }, |
| 4746 | }, |
| 4747 | { |
| 4748 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C), |
| 4749 | .dbuf_mask = { |
| 4750 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4751 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4752 | }, |
| 4753 | }, |
| 4754 | { |
| 4755 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C), |
| 4756 | .dbuf_mask = { |
| 4757 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4758 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4759 | }, |
| 4760 | }, |
| 4761 | { |
| 4762 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), |
| 4763 | .dbuf_mask = { |
| 4764 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4765 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4766 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4767 | }, |
| 4768 | }, |
| 4769 | { |
| 4770 | .active_pipes = BIT(PIPE_D), |
| 4771 | .dbuf_mask = { |
| 4772 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4773 | }, |
| 4774 | }, |
| 4775 | { |
| 4776 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_D), |
| 4777 | .dbuf_mask = { |
| 4778 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4779 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4780 | }, |
| 4781 | }, |
| 4782 | { |
| 4783 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_D), |
| 4784 | .dbuf_mask = { |
| 4785 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4786 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4787 | }, |
| 4788 | }, |
| 4789 | { |
| 4790 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D), |
| 4791 | .dbuf_mask = { |
| 4792 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4793 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4794 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4795 | }, |
| 4796 | }, |
| 4797 | { |
| 4798 | .active_pipes = BIT(PIPE_C) | BIT(PIPE_D), |
| 4799 | .dbuf_mask = { |
| 4800 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4801 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4802 | }, |
| 4803 | }, |
| 4804 | { |
| 4805 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4806 | .dbuf_mask = { |
| 4807 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4808 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4809 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4810 | }, |
| 4811 | }, |
| 4812 | { |
| 4813 | .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4814 | .dbuf_mask = { |
| 4815 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4816 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4817 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4818 | }, |
| 4819 | }, |
| 4820 | { |
| 4821 | .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D), |
| 4822 | .dbuf_mask = { |
| 4823 | [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4824 | [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4825 | [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4), |
| 4826 | [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2), |
| 4827 | }, |
| 4828 | }, |
| 4829 | {} |
| 4830 | |
| 4831 | }; |
| 4832 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 4833 | static bool check_mbus_joined(u8 active_pipes, |
| 4834 | const struct dbuf_slice_conf_entry *dbuf_slices) |
| 4835 | { |
| 4836 | int i; |
| 4837 | |
| 4838 | for (i = 0; i < dbuf_slices[i].active_pipes; i++) { |
| 4839 | if (dbuf_slices[i].active_pipes == active_pipes) |
| 4840 | return dbuf_slices[i].join_mbus; |
| 4841 | } |
| 4842 | return false; |
| 4843 | } |
| 4844 | |
| 4845 | static bool adlp_check_mbus_joined(u8 active_pipes) |
| 4846 | { |
| 4847 | return check_mbus_joined(active_pipes, adlp_allowed_dbufs); |
| 4848 | } |
| 4849 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4850 | static u8 compute_dbuf_slices(enum pipe pipe, u8 active_pipes, |
| 4851 | const struct dbuf_slice_conf_entry *dbuf_slices) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4852 | { |
| 4853 | int i; |
| 4854 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4855 | for (i = 0; i < dbuf_slices[i].active_pipes; i++) { |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4856 | if (dbuf_slices[i].active_pipes == active_pipes) |
| 4857 | return dbuf_slices[i].dbuf_mask[pipe]; |
| 4858 | } |
| 4859 | return 0; |
| 4860 | } |
| 4861 | |
| 4862 | /* |
| 4863 | * This function finds an entry with same enabled pipe configuration and |
| 4864 | * returns correspondent DBuf slice mask as stated in BSpec for particular |
| 4865 | * platform. |
| 4866 | */ |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4867 | static u8 icl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4868 | { |
| 4869 | /* |
| 4870 | * FIXME: For ICL this is still a bit unclear as prev BSpec revision |
| 4871 | * required calculating "pipe ratio" in order to determine |
| 4872 | * if one or two slices can be used for single pipe configurations |
| 4873 | * as additional constraint to the existing table. |
| 4874 | * However based on recent info, it should be not "pipe ratio" |
| 4875 | * but rather ratio between pixel_rate and cdclk with additional |
| 4876 | * constants, so for now we are using only table until this is |
| 4877 | * clarified. Also this is the reason why crtc_state param is |
| 4878 | * still here - we will need it once those additional constraints |
| 4879 | * pop up. |
| 4880 | */ |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4881 | return compute_dbuf_slices(pipe, active_pipes, icl_allowed_dbufs); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4882 | } |
| 4883 | |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4884 | static u8 tgl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes) |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4885 | { |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4886 | return compute_dbuf_slices(pipe, active_pipes, tgl_allowed_dbufs); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4887 | } |
| 4888 | |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4889 | static u32 adlp_compute_dbuf_slices(enum pipe pipe, u32 active_pipes) |
| 4890 | { |
| 4891 | return compute_dbuf_slices(pipe, active_pipes, adlp_allowed_dbufs); |
| 4892 | } |
| 4893 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4894 | static u32 dg2_compute_dbuf_slices(enum pipe pipe, u32 active_pipes) |
| 4895 | { |
| 4896 | return compute_dbuf_slices(pipe, active_pipes, dg2_allowed_dbufs); |
| 4897 | } |
| 4898 | |
Ville Syrjälä | 2d42f32 | 2021-01-22 22:56:27 +0200 | [diff] [blame] | 4899 | 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] | 4900 | { |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4901 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 4902 | enum pipe pipe = crtc->pipe; |
| 4903 | |
Matt Roper | 49f7563 | 2021-07-21 15:30:40 -0700 | [diff] [blame] | 4904 | if (IS_DG2(dev_priv)) |
| 4905 | return dg2_compute_dbuf_slices(pipe, active_pipes); |
| 4906 | else if (IS_ALDERLAKE_P(dev_priv)) |
Vandita Kulkarni | 247bdac | 2021-05-18 17:06:15 -0700 | [diff] [blame] | 4907 | return adlp_compute_dbuf_slices(pipe, active_pipes); |
| 4908 | else if (DISPLAY_VER(dev_priv) == 12) |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4909 | return tgl_compute_dbuf_slices(pipe, active_pipes); |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 4910 | else if (DISPLAY_VER(dev_priv) == 11) |
Ville Syrjälä | 05e8155 | 2020-02-25 19:11:09 +0200 | [diff] [blame] | 4911 | return icl_compute_dbuf_slices(pipe, active_pipes); |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4912 | /* |
| 4913 | * For anything else just return one slice yet. |
| 4914 | * Should be extended for other platforms. |
| 4915 | */ |
Ville Syrjälä | 2f9078c | 2020-02-25 19:11:10 +0200 | [diff] [blame] | 4916 | return active_pipes & BIT(pipe) ? BIT(DBUF_S1) : 0; |
Stanislav Lisovskiy | ff2cd86 | 2020-02-03 01:06:30 +0200 | [diff] [blame] | 4917 | } |
| 4918 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4919 | static u64 |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4920 | skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state, |
| 4921 | const struct intel_plane_state *plane_state, |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4922 | int color_plane) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4923 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4924 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 4925 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 4926 | u32 data_rate; |
| 4927 | u32 width = 0, height = 0; |
Kumar, Mahesh | 7084b50 | 2017-05-17 17:28:23 +0530 | [diff] [blame] | 4928 | uint_fixed_16_16_t down_scale_amount; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4929 | u64 rate; |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4930 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4931 | if (!plane_state->uapi.visible) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4932 | return 0; |
Ville Syrjälä | 8305494 | 2016-11-18 21:53:00 +0200 | [diff] [blame] | 4933 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4934 | if (plane->id == PLANE_CURSOR) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4935 | return 0; |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4936 | |
| 4937 | if (color_plane == 1 && |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 4938 | !intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier)) |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4939 | return 0; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4940 | |
Ville Syrjälä | fce5adf | 2017-03-31 21:00:55 +0300 | [diff] [blame] | 4941 | /* |
| 4942 | * Src coordinates are already rotated by 270 degrees for |
| 4943 | * the 90/270 degree plane rotation cases (to match the |
| 4944 | * GTT mapping), hence no need to account for rotation here. |
| 4945 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 4946 | width = drm_rect_width(&plane_state->uapi.src) >> 16; |
| 4947 | height = drm_rect_height(&plane_state->uapi.src) >> 16; |
Kumar, Mahesh | a280f7d | 2016-04-06 08:26:39 -0700 | [diff] [blame] | 4948 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4949 | /* UV plane does 1/2 pixel sub-sampling */ |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4950 | if (color_plane == 1) { |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4951 | width /= 2; |
| 4952 | height /= 2; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 4953 | } |
| 4954 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4955 | data_rate = width * height; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4956 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 4957 | down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state); |
Kumar, Mahesh | 8d19d7d | 2016-05-19 15:03:01 -0700 | [diff] [blame] | 4958 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4959 | rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount); |
| 4960 | |
Ville Syrjälä | d1d23d7 | 2019-09-13 22:31:54 +0300 | [diff] [blame] | 4961 | rate *= fb->format->cpp[color_plane]; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4962 | return rate; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4963 | } |
| 4964 | |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4965 | static u64 |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4966 | skl_get_total_relative_data_rate(struct intel_atomic_state *state, |
| 4967 | struct intel_crtc *crtc) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4968 | { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4969 | struct intel_crtc_state *crtc_state = |
| 4970 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 4971 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4972 | struct intel_plane *plane; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 4973 | u64 total_data_rate = 0; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4974 | enum plane_id plane_id; |
| 4975 | int i; |
Matt Roper | a6d3460e | 2016-05-12 07:06:04 -0700 | [diff] [blame] | 4976 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 4977 | /* Calculate and cache data rate for each plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4978 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 4979 | if (plane->pipe != crtc->pipe) |
| 4980 | continue; |
| 4981 | |
| 4982 | plane_id = plane->id; |
Matt Roper | 024c904 | 2015-09-24 15:53:11 -0700 | [diff] [blame] | 4983 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4984 | /* packed/y */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4985 | crtc_state->plane_data_rate[plane_id] = |
| 4986 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Matt Roper | 9c74d82 | 2016-05-12 07:05:58 -0700 | [diff] [blame] | 4987 | |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 4988 | /* uv-plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 4989 | crtc_state->uv_plane_data_rate[plane_id] = |
| 4990 | skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
| 4991 | } |
| 4992 | |
| 4993 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 4994 | total_data_rate += crtc_state->plane_data_rate[plane_id]; |
| 4995 | total_data_rate += crtc_state->uv_plane_data_rate[plane_id]; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | return total_data_rate; |
| 4999 | } |
| 5000 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5001 | static u64 |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5002 | icl_get_total_relative_data_rate(struct intel_atomic_state *state, |
| 5003 | struct intel_crtc *crtc) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5004 | { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5005 | struct intel_crtc_state *crtc_state = |
| 5006 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5007 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5008 | struct intel_plane *plane; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5009 | u64 total_data_rate = 0; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5010 | enum plane_id plane_id; |
| 5011 | int i; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5012 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5013 | /* Calculate and cache data rate for each plane */ |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5014 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 5015 | if (plane->pipe != crtc->pipe) |
| 5016 | continue; |
| 5017 | |
| 5018 | plane_id = plane->id; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5019 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5020 | if (!plane_state->planar_linked_plane) { |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5021 | crtc_state->plane_data_rate[plane_id] = |
| 5022 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5023 | } else { |
| 5024 | enum plane_id y_plane_id; |
| 5025 | |
| 5026 | /* |
| 5027 | * The slave plane might not iterate in |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5028 | * intel_atomic_crtc_state_for_each_plane_state(), |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5029 | * and needs the master plane state which may be |
| 5030 | * NULL if we try get_new_plane_state(), so we |
| 5031 | * always calculate from the master. |
| 5032 | */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5033 | if (plane_state->planar_slave) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5034 | continue; |
| 5035 | |
| 5036 | /* Y plane rate is calculated on the slave */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5037 | y_plane_id = plane_state->planar_linked_plane->id; |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5038 | crtc_state->plane_data_rate[y_plane_id] = |
| 5039 | skl_plane_relative_data_rate(crtc_state, plane_state, 0); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5040 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5041 | crtc_state->plane_data_rate[plane_id] = |
| 5042 | skl_plane_relative_data_rate(crtc_state, plane_state, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5043 | } |
| 5044 | } |
| 5045 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5046 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 5047 | total_data_rate += crtc_state->plane_data_rate[plane_id]; |
| 5048 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5049 | return total_data_rate; |
| 5050 | } |
| 5051 | |
Ville Syrjälä | 5516e89 | 2021-02-26 17:32:03 +0200 | [diff] [blame] | 5052 | const struct skl_wm_level * |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5053 | skl_plane_wm_level(const struct skl_pipe_wm *pipe_wm, |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5054 | enum plane_id plane_id, |
| 5055 | int level) |
| 5056 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5057 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5058 | |
| 5059 | if (level == 0 && pipe_wm->use_sagv_wm) |
Ville Syrjälä | a68aa48 | 2021-02-26 17:32:01 +0200 | [diff] [blame] | 5060 | return &wm->sagv.wm0; |
Stanislav Lisovskiy | d916234 | 2020-05-13 12:38:11 +0300 | [diff] [blame] | 5061 | |
| 5062 | return &wm->wm[level]; |
| 5063 | } |
| 5064 | |
Ville Syrjälä | 5516e89 | 2021-02-26 17:32:03 +0200 | [diff] [blame] | 5065 | const struct skl_wm_level * |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5066 | skl_plane_trans_wm(const struct skl_pipe_wm *pipe_wm, |
| 5067 | enum plane_id plane_id) |
| 5068 | { |
| 5069 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5070 | |
| 5071 | if (pipe_wm->use_sagv_wm) |
| 5072 | return &wm->sagv.trans_wm; |
| 5073 | |
| 5074 | return &wm->trans_wm; |
| 5075 | } |
| 5076 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5077 | /* |
| 5078 | * We only disable the watermarks for each plane if |
| 5079 | * they exceed the ddb allocation of said plane. This |
| 5080 | * is done so that we don't end up touching cursor |
| 5081 | * watermarks needlessly when some other plane reduces |
| 5082 | * our max possible watermark level. |
| 5083 | * |
| 5084 | * Bspec has this to say about the PLANE_WM enable bit: |
| 5085 | * "All the watermarks at this level for all enabled |
| 5086 | * planes must be enabled before the level will be used." |
| 5087 | * So this is actually safe to do. |
| 5088 | */ |
| 5089 | static void |
| 5090 | skl_check_wm_level(struct skl_wm_level *wm, u64 total) |
| 5091 | { |
| 5092 | if (wm->min_ddb_alloc > total) |
| 5093 | memset(wm, 0, sizeof(*wm)); |
| 5094 | } |
| 5095 | |
| 5096 | static void |
| 5097 | skl_check_nv12_wm_level(struct skl_wm_level *wm, struct skl_wm_level *uv_wm, |
| 5098 | u64 total, u64 uv_total) |
| 5099 | { |
| 5100 | if (wm->min_ddb_alloc > total || |
| 5101 | uv_wm->min_ddb_alloc > uv_total) { |
| 5102 | memset(wm, 0, sizeof(*wm)); |
| 5103 | memset(uv_wm, 0, sizeof(*uv_wm)); |
| 5104 | } |
| 5105 | } |
| 5106 | |
Stanislav Lisovskiy | eeb04fa | 2021-11-18 11:39:07 +0200 | [diff] [blame] | 5107 | static bool icl_need_wm1_wa(struct drm_i915_private *i915, |
| 5108 | enum plane_id plane_id) |
| 5109 | { |
| 5110 | /* |
| 5111 | * Wa_1408961008:icl, ehl |
| 5112 | * Wa_14012656716:tgl, adl |
| 5113 | * Underruns with WM1+ disabled |
| 5114 | */ |
| 5115 | return DISPLAY_VER(i915) == 11 || |
| 5116 | (IS_DISPLAY_VER(i915, 12, 13) && plane_id == PLANE_CURSOR); |
| 5117 | } |
| 5118 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5119 | static int |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5120 | skl_allocate_plane_ddb(struct intel_atomic_state *state, |
| 5121 | struct intel_crtc *crtc) |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5122 | { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5123 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5124 | struct intel_crtc_state *crtc_state = |
| 5125 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5126 | const struct intel_dbuf_state *dbuf_state = |
Ville Syrjälä | 47a1495 | 2021-01-22 22:56:30 +0200 | [diff] [blame] | 5127 | intel_atomic_get_new_dbuf_state(state); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5128 | const struct skl_ddb_entry *alloc = &dbuf_state->ddb[crtc->pipe]; |
| 5129 | int num_active = hweight8(dbuf_state->active_pipes); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5130 | u16 alloc_size, start = 0; |
| 5131 | u16 total[I915_MAX_PLANES] = {}; |
| 5132 | u16 uv_total[I915_MAX_PLANES] = {}; |
Maarten Lankhorst | 24719e9 | 2018-10-22 12:20:00 +0200 | [diff] [blame] | 5133 | u64 total_data_rate; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5134 | enum plane_id plane_id; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5135 | u32 blocks; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5136 | int level; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5137 | |
Paulo Zanoni | 5a920b8 | 2016-10-04 14:37:32 -0300 | [diff] [blame] | 5138 | /* Clear the partitioning for disabled planes. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5139 | memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y)); |
| 5140 | 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] | 5141 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 5142 | if (!crtc_state->hw.active) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5143 | return 0; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5144 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5145 | if (DISPLAY_VER(dev_priv) >= 11) |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5146 | total_data_rate = |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5147 | icl_get_total_relative_data_rate(state, crtc); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5148 | else |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5149 | total_data_rate = |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5150 | skl_get_total_relative_data_rate(state, crtc); |
Lucas De Marchi | 323b0a8 | 2019-04-04 16:04:25 -0700 | [diff] [blame] | 5151 | |
Damien Lespiau | 34bb56a | 2014-11-04 17:07:01 +0000 | [diff] [blame] | 5152 | alloc_size = skl_ddb_entry_size(alloc); |
Kumar, Mahesh | 336031e | 2017-05-17 17:28:25 +0530 | [diff] [blame] | 5153 | if (alloc_size == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5154 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5155 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5156 | /* Allocate fixed number of blocks for cursor. */ |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5157 | total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5158 | alloc_size -= total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5159 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start = |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5160 | alloc->end - total[PLANE_CURSOR]; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5161 | crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end; |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 5162 | |
Matt Roper | a1de91e | 2016-05-12 07:05:57 -0700 | [diff] [blame] | 5163 | if (total_data_rate == 0) |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5164 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5165 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5166 | /* |
| 5167 | * Find the highest watermark level for which we can satisfy the block |
| 5168 | * requirement of active planes. |
| 5169 | */ |
| 5170 | for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) { |
Matt Roper | 25db2ea | 2018-12-12 11:17:20 -0800 | [diff] [blame] | 5171 | blocks = 0; |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5172 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5173 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5174 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 5175 | |
| 5176 | if (plane_id == PLANE_CURSOR) { |
Vandita Kulkarni | 4ba4870 | 2019-12-16 13:36:19 +0530 | [diff] [blame] | 5177 | if (wm->wm[level].min_ddb_alloc > total[PLANE_CURSOR]) { |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5178 | drm_WARN_ON(&dev_priv->drm, |
| 5179 | wm->wm[level].min_ddb_alloc != U16_MAX); |
Ville Syrjälä | 10a7e07 | 2019-03-12 22:58:40 +0200 | [diff] [blame] | 5180 | blocks = U32_MAX; |
| 5181 | break; |
| 5182 | } |
| 5183 | continue; |
| 5184 | } |
| 5185 | |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5186 | blocks += wm->wm[level].min_ddb_alloc; |
| 5187 | blocks += wm->uv_wm[level].min_ddb_alloc; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5188 | } |
| 5189 | |
Ville Syrjälä | 3cf963c | 2019-03-12 22:58:36 +0200 | [diff] [blame] | 5190 | if (blocks <= alloc_size) { |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5191 | alloc_size -= blocks; |
| 5192 | break; |
| 5193 | } |
| 5194 | } |
| 5195 | |
| 5196 | if (level < 0) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5197 | drm_dbg_kms(&dev_priv->drm, |
| 5198 | "Requested display configuration exceeds system DDB limitations"); |
| 5199 | drm_dbg_kms(&dev_priv->drm, "minimum required %d/%d\n", |
| 5200 | blocks, alloc_size); |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5201 | return -EINVAL; |
| 5202 | } |
| 5203 | |
| 5204 | /* |
| 5205 | * Grant each plane the blocks it requires at the highest achievable |
| 5206 | * watermark level, plus an extra share of the leftover blocks |
| 5207 | * proportional to its relative data rate. |
| 5208 | */ |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5209 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5210 | const struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5211 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5212 | u64 rate; |
| 5213 | u16 extra; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5214 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5215 | if (plane_id == PLANE_CURSOR) |
Maarten Lankhorst | 49845a7 | 2016-10-26 15:41:34 +0200 | [diff] [blame] | 5216 | continue; |
| 5217 | |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5218 | /* |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5219 | * We've accounted for all active planes; remaining planes are |
| 5220 | * all disabled. |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5221 | */ |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5222 | if (total_data_rate == 0) |
| 5223 | break; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5224 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5225 | rate = crtc_state->plane_data_rate[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5226 | extra = min_t(u16, alloc_size, |
| 5227 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 5228 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5229 | total[plane_id] = wm->wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5230 | alloc_size -= extra; |
| 5231 | total_data_rate -= rate; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5232 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5233 | if (total_data_rate == 0) |
| 5234 | break; |
Chandra Konduru | 2cd601c | 2015-04-27 15:47:37 -0700 | [diff] [blame] | 5235 | |
Ville Syrjälä | ab01630 | 2020-11-06 19:30:41 +0200 | [diff] [blame] | 5236 | rate = crtc_state->uv_plane_data_rate[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5237 | extra = min_t(u16, alloc_size, |
| 5238 | DIV64_U64_ROUND_UP(alloc_size * rate, |
| 5239 | total_data_rate)); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5240 | uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5241 | alloc_size -= extra; |
| 5242 | total_data_rate -= rate; |
| 5243 | } |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5244 | 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] | 5245 | |
| 5246 | /* Set the actual DDB start/end points for each plane */ |
| 5247 | start = alloc->start; |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5248 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5249 | struct skl_ddb_entry *plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5250 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5251 | struct skl_ddb_entry *uv_plane_alloc = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5252 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5253 | |
| 5254 | if (plane_id == PLANE_CURSOR) |
| 5255 | continue; |
| 5256 | |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5257 | /* Gen11+ uses a separate plane for UV watermarks */ |
Pankaj Bharadiya | 48a1b8d | 2020-01-15 09:14:53 +0530 | [diff] [blame] | 5258 | drm_WARN_ON(&dev_priv->drm, |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5259 | DISPLAY_VER(dev_priv) >= 11 && uv_total[plane_id]); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5260 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5261 | /* Leave disabled planes at (0,0) */ |
| 5262 | if (total[plane_id]) { |
| 5263 | plane_alloc->start = start; |
| 5264 | start += total[plane_id]; |
| 5265 | plane_alloc->end = start; |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5266 | } |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 5267 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5268 | if (uv_total[plane_id]) { |
| 5269 | uv_plane_alloc->start = start; |
| 5270 | start += uv_total[plane_id]; |
| 5271 | uv_plane_alloc->end = start; |
| 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | /* |
| 5276 | * When we calculated watermark values we didn't know how high |
| 5277 | * of a level we'd actually be able to hit, so we just marked |
| 5278 | * all levels as "enabled." Go back now and disable the ones |
| 5279 | * that aren't actually possible. |
| 5280 | */ |
| 5281 | for (level++; level <= ilk_wm_max_level(dev_priv); level++) { |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5282 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5283 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5284 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | a301cb0 | 2019-03-12 22:58:41 +0200 | [diff] [blame] | 5285 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5286 | skl_check_nv12_wm_level(&wm->wm[level], &wm->uv_wm[level], |
| 5287 | total[plane_id], uv_total[plane_id]); |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5288 | |
Stanislav Lisovskiy | eeb04fa | 2021-11-18 11:39:07 +0200 | [diff] [blame] | 5289 | if (icl_need_wm1_wa(dev_priv, plane_id) && |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5290 | level == 1 && wm->wm[0].enable) { |
| 5291 | wm->wm[level].blocks = wm->wm[0].blocks; |
| 5292 | wm->wm[level].lines = wm->wm[0].lines; |
Ville Syrjälä | c384afe | 2019-02-28 19:36:39 +0200 | [diff] [blame] | 5293 | wm->wm[level].ignore_lines = wm->wm[0].ignore_lines; |
Ville Syrjälä | 290248c | 2019-02-13 18:54:24 +0200 | [diff] [blame] | 5294 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5295 | } |
| 5296 | } |
| 5297 | |
| 5298 | /* |
Ville Syrjälä | df4a50a | 2021-02-26 17:31:59 +0200 | [diff] [blame] | 5299 | * Go back and disable the transition and SAGV watermarks |
| 5300 | * 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] | 5301 | */ |
Ville Syrjälä | 2a67054b | 2020-02-25 19:11:06 +0200 | [diff] [blame] | 5302 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5303 | struct skl_plane_wm *wm = |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5304 | &crtc_state->wm.skl.optimal.planes[plane_id]; |
Ville Syrjälä | 5e6037c | 2019-03-12 22:58:42 +0200 | [diff] [blame] | 5305 | |
Ville Syrjälä | a5941b4 | 2021-03-05 17:36:09 +0200 | [diff] [blame] | 5306 | skl_check_wm_level(&wm->trans_wm, total[plane_id]); |
| 5307 | skl_check_wm_level(&wm->sagv.wm0, total[plane_id]); |
| 5308 | skl_check_wm_level(&wm->sagv.trans_wm, total[plane_id]); |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5309 | } |
| 5310 | |
Matt Roper | c107acf | 2016-05-12 07:06:01 -0700 | [diff] [blame] | 5311 | return 0; |
Damien Lespiau | b9cec07 | 2014-11-04 17:06:43 +0000 | [diff] [blame] | 5312 | } |
| 5313 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5314 | /* |
| 5315 | * 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] | 5316 | * for the read latency) and cpp should always be <= 8, so that |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5317 | * should allow pixel_rate up to ~2 GHz which seems sufficient since max |
| 5318 | * 2xcdclk is 1350 MHz and the pixel rate should never exceed that. |
| 5319 | */ |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5320 | static uint_fixed_16_16_t |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5321 | skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate, |
| 5322 | u8 cpp, u32 latency, u32 dbuf_block_size) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5323 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5324 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5325 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5326 | |
| 5327 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5328 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5329 | |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5330 | wm_intermediate_val = latency * pixel_rate * cpp; |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5331 | ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size); |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5332 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5333 | if (DISPLAY_VER(dev_priv) >= 10) |
Paulo Zanoni | 6c64dd3 | 2017-08-11 16:38:25 -0700 | [diff] [blame] | 5334 | ret = add_fixed16_u32(ret, 1); |
| 5335 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5336 | return ret; |
| 5337 | } |
| 5338 | |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5339 | static uint_fixed_16_16_t |
| 5340 | skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency, |
| 5341 | uint_fixed_16_16_t plane_blocks_per_line) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5342 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5343 | u32 wm_intermediate_val; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5344 | uint_fixed_16_16_t ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5345 | |
| 5346 | if (latency == 0) |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5347 | return FP_16_16_MAX; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5348 | |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5349 | wm_intermediate_val = latency * pixel_rate; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5350 | wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val, |
| 5351 | pipe_htotal * 1000); |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5352 | ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5353 | return ret; |
| 5354 | } |
| 5355 | |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5356 | static uint_fixed_16_16_t |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5357 | intel_get_linetime_us(const struct intel_crtc_state *crtc_state) |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5358 | { |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5359 | 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] | 5360 | u32 pixel_rate; |
| 5361 | u32 crtc_htotal; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5362 | uint_fixed_16_16_t linetime_us; |
| 5363 | |
Maarten Lankhorst | 1326a92 | 2019-10-31 12:26:02 +0100 | [diff] [blame] | 5364 | if (!crtc_state->hw.active) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5365 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5366 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5367 | pixel_rate = crtc_state->pixel_rate; |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5368 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5369 | if (drm_WARN_ON(&dev_priv->drm, pixel_rate == 0)) |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5370 | return u32_to_fixed16(0); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5371 | |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5372 | crtc_htotal = crtc_state->hw.pipe_mode.crtc_htotal; |
Kumar, Mahesh | eac2cb8 | 2017-07-05 20:01:46 +0530 | [diff] [blame] | 5373 | linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate); |
Kumar, Mahesh | d555cb5 | 2017-05-17 17:28:29 +0530 | [diff] [blame] | 5374 | |
| 5375 | return linetime_us; |
| 5376 | } |
| 5377 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5378 | static int |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5379 | skl_compute_wm_params(const struct intel_crtc_state *crtc_state, |
| 5380 | int width, const struct drm_format_info *format, |
| 5381 | u64 modifier, unsigned int rotation, |
| 5382 | u32 plane_pixel_rate, struct skl_wm_params *wp, |
| 5383 | int color_plane) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5384 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5385 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5386 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5387 | u32 interm_pbpl; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5388 | |
Juha-Pekka Heikkila | df7d415 | 2019-03-04 17:26:31 +0530 | [diff] [blame] | 5389 | /* only planar format has two planes */ |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 5390 | if (color_plane == 1 && |
| 5391 | !intel_format_info_is_yuv_semiplanar(format, modifier)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 5392 | drm_dbg_kms(&dev_priv->drm, |
| 5393 | "Non planar format have single plane\n"); |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5394 | return -EINVAL; |
| 5395 | } |
| 5396 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5397 | wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED || |
| 5398 | modifier == I915_FORMAT_MOD_Yf_TILED || |
| 5399 | modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 5400 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
| 5401 | wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED; |
| 5402 | wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS || |
| 5403 | modifier == I915_FORMAT_MOD_Yf_TILED_CCS; |
Imre Deak | 4941f35 | 2019-12-21 14:05:43 +0200 | [diff] [blame] | 5404 | wp->is_planar = intel_format_info_is_yuv_semiplanar(format, modifier); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5405 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5406 | wp->width = width; |
Ville Syrjälä | 45bee43 | 2018-11-14 23:07:28 +0200 | [diff] [blame] | 5407 | if (color_plane == 1 && wp->is_planar) |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5408 | wp->width /= 2; |
| 5409 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5410 | wp->cpp = format->cpp[color_plane]; |
| 5411 | wp->plane_pixel_rate = plane_pixel_rate; |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5412 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5413 | if (DISPLAY_VER(dev_priv) >= 11 && |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5414 | modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1) |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5415 | wp->dbuf_block_size = 256; |
| 5416 | else |
| 5417 | wp->dbuf_block_size = 512; |
| 5418 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5419 | if (drm_rotation_90_or_270(rotation)) { |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5420 | switch (wp->cpp) { |
| 5421 | case 1: |
| 5422 | wp->y_min_scanlines = 16; |
| 5423 | break; |
| 5424 | case 2: |
| 5425 | wp->y_min_scanlines = 8; |
| 5426 | break; |
| 5427 | case 4: |
| 5428 | wp->y_min_scanlines = 4; |
| 5429 | break; |
| 5430 | default: |
| 5431 | MISSING_CASE(wp->cpp); |
| 5432 | return -EINVAL; |
| 5433 | } |
| 5434 | } else { |
| 5435 | wp->y_min_scanlines = 4; |
| 5436 | } |
| 5437 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 5438 | if (skl_needs_memory_bw_wa(dev_priv)) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5439 | wp->y_min_scanlines *= 2; |
| 5440 | |
| 5441 | wp->plane_bytes_per_line = wp->width * wp->cpp; |
| 5442 | if (wp->y_tiled) { |
| 5443 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line * |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5444 | wp->y_min_scanlines, |
| 5445 | wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5446 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5447 | if (DISPLAY_VER(dev_priv) >= 10) |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5448 | interm_pbpl++; |
| 5449 | |
| 5450 | wp->plane_blocks_per_line = div_fixed16(interm_pbpl, |
| 5451 | wp->y_min_scanlines); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5452 | } else { |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5453 | interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line, |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5454 | wp->dbuf_block_size); |
| 5455 | |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5456 | if (!wp->x_tiled || DISPLAY_VER(dev_priv) >= 10) |
Ville Syrjälä | 260a6c1b | 2020-04-30 15:58:21 +0300 | [diff] [blame] | 5457 | interm_pbpl++; |
| 5458 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5459 | wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl); |
| 5460 | } |
| 5461 | |
| 5462 | wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines, |
| 5463 | wp->plane_blocks_per_line); |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5464 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5465 | wp->linetime_us = fixed16_to_u32_round_up( |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5466 | intel_get_linetime_us(crtc_state)); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5467 | |
| 5468 | return 0; |
| 5469 | } |
| 5470 | |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5471 | static int |
| 5472 | skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state, |
| 5473 | const struct intel_plane_state *plane_state, |
| 5474 | struct skl_wm_params *wp, int color_plane) |
| 5475 | { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5476 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5477 | int width; |
| 5478 | |
Maarten Lankhorst | 3a61276 | 2019-10-04 13:34:54 +0200 | [diff] [blame] | 5479 | /* |
| 5480 | * Src coordinates are already rotated by 270 degrees for |
| 5481 | * the 90/270 degree plane rotation cases (to match the |
| 5482 | * GTT mapping), hence no need to account for rotation here. |
| 5483 | */ |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 5484 | width = drm_rect_width(&plane_state->uapi.src) >> 16; |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5485 | |
| 5486 | return skl_compute_wm_params(crtc_state, width, |
| 5487 | fb->format, fb->modifier, |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5488 | plane_state->hw.rotation, |
Ville Syrjälä | 3df3fe2 | 2020-11-06 19:30:42 +0200 | [diff] [blame] | 5489 | intel_plane_pixel_rate(crtc_state, plane_state), |
Ville Syrjälä | c92558a | 2019-03-12 22:58:38 +0200 | [diff] [blame] | 5490 | wp, color_plane); |
| 5491 | } |
| 5492 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5493 | static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level) |
| 5494 | { |
Matt Roper | 2b5a456 | 2021-03-22 16:38:40 -0700 | [diff] [blame] | 5495 | if (DISPLAY_VER(dev_priv) >= 10) |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5496 | return true; |
| 5497 | |
| 5498 | /* The number of lines are ignored for the level 0 watermark. */ |
| 5499 | return level > 0; |
| 5500 | } |
| 5501 | |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5502 | static int skl_wm_max_lines(struct drm_i915_private *dev_priv) |
| 5503 | { |
| 5504 | if (DISPLAY_VER(dev_priv) >= 13) |
| 5505 | return 255; |
| 5506 | else |
| 5507 | return 31; |
| 5508 | } |
| 5509 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5510 | 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] | 5511 | int level, |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5512 | unsigned int latency, |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5513 | const struct skl_wm_params *wp, |
| 5514 | const struct skl_wm_level *result_prev, |
| 5515 | struct skl_wm_level *result /* out */) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5516 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5517 | 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] | 5518 | uint_fixed_16_16_t method1, method2; |
Mahesh Kumar | b95320b | 2016-12-01 21:19:37 +0530 | [diff] [blame] | 5519 | uint_fixed_16_16_t selected_result; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5520 | u32 blocks, lines, min_ddb_alloc = 0; |
Ville Syrjälä | ce110ec | 2018-11-14 23:07:21 +0200 | [diff] [blame] | 5521 | |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5522 | if (latency == 0) { |
| 5523 | /* reject it */ |
| 5524 | result->min_ddb_alloc = U16_MAX; |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 5525 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5526 | } |
Ville Syrjälä | 692927f | 2018-12-21 19:14:29 +0200 | [diff] [blame] | 5527 | |
Ville Syrjälä | 25312ef | 2019-05-03 20:38:05 +0300 | [diff] [blame] | 5528 | /* |
| 5529 | * WaIncreaseLatencyIPCEnabled: kbl,cfl |
| 5530 | * Display WA #1141: kbl,cfl |
| 5531 | */ |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 5532 | if ((IS_KABYLAKE(dev_priv) || |
| 5533 | IS_COFFEELAKE(dev_priv) || |
| 5534 | IS_COMETLAKE(dev_priv)) && |
Rodrigo Vivi | 82525c1 | 2017-06-08 08:50:00 -0700 | [diff] [blame] | 5535 | dev_priv->ipc_enabled) |
Mahesh Kumar | 4b7b233 | 2016-12-01 21:19:35 +0530 | [diff] [blame] | 5536 | latency += 4; |
| 5537 | |
Ville Syrjälä | 60e983f | 2018-12-21 19:14:33 +0200 | [diff] [blame] | 5538 | if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled) |
Paulo Zanoni | ee3d532 | 2016-10-11 15:25:38 -0300 | [diff] [blame] | 5539 | latency += 15; |
| 5540 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5541 | method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate, |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5542 | wp->cpp, latency, wp->dbuf_block_size); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5543 | method2 = skl_wm_method2(wp->plane_pixel_rate, |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5544 | crtc_state->hw.pipe_mode.crtc_htotal, |
Paulo Zanoni | 1186fa8 | 2016-09-22 18:00:31 -0300 | [diff] [blame] | 5545 | latency, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5546 | wp->plane_blocks_per_line); |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5547 | |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5548 | if (wp->y_tiled) { |
| 5549 | selected_result = max_fixed16(method2, wp->y_tile_minimum); |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5550 | } else { |
Maarten Lankhorst | bafcdad | 2020-11-12 21:17:18 +0200 | [diff] [blame] | 5551 | if ((wp->cpp * crtc_state->hw.pipe_mode.crtc_htotal / |
Mahesh Kumar | df8ee19 | 2018-01-30 11:49:11 -0200 | [diff] [blame] | 5552 | wp->dbuf_block_size < 1) && |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5553 | (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) { |
Paulo Zanoni | f1db3ea | 2016-09-22 18:00:34 -0300 | [diff] [blame] | 5554 | selected_result = method2; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5555 | } else if (latency >= wp->linetime_us) { |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5556 | if (DISPLAY_VER(dev_priv) == 9) |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5557 | selected_result = min_fixed16(method1, method2); |
| 5558 | else |
| 5559 | selected_result = method2; |
| 5560 | } else { |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5561 | selected_result = method1; |
Paulo Zanoni | 077b582 | 2018-10-04 16:15:57 -0700 | [diff] [blame] | 5562 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5563 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5564 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5565 | blocks = fixed16_to_u32_round_up(selected_result) + 1; |
| 5566 | lines = div_round_up_fixed16(selected_result, |
| 5567 | wp->plane_blocks_per_line); |
Damien Lespiau | e6d6617 | 2014-11-04 17:06:55 +0000 | [diff] [blame] | 5568 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5569 | if (DISPLAY_VER(dev_priv) == 9) { |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5570 | /* Display WA #1125: skl,bxt,kbl */ |
| 5571 | if (level == 0 && wp->rc_surface) |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5572 | blocks += fixed16_to_u32_round_up(wp->y_tile_minimum); |
Ville Syrjälä | 2e2adb0 | 2017-08-01 09:58:13 -0700 | [diff] [blame] | 5573 | |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5574 | /* Display WA #1126: skl,bxt,kbl */ |
| 5575 | if (level >= 1 && level <= 7) { |
| 5576 | if (wp->y_tiled) { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5577 | blocks += fixed16_to_u32_round_up(wp->y_tile_minimum); |
| 5578 | lines += wp->y_min_scanlines; |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5579 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5580 | blocks++; |
Paulo Zanoni | a5b79d3 | 2018-11-13 17:24:32 -0800 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | /* |
| 5584 | * Make sure result blocks for higher latency levels are |
| 5585 | * atleast as high as level below the current level. |
| 5586 | * Assumption in DDB algorithm optimization for special |
| 5587 | * cases. Also covers Display WA #1125 for RC. |
| 5588 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5589 | if (result_prev->blocks > blocks) |
| 5590 | blocks = result_prev->blocks; |
Paulo Zanoni | 75676ed | 2016-09-22 18:00:33 -0300 | [diff] [blame] | 5591 | } |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 5592 | } |
Tvrtko Ursulin | d4c2aa6 | 2015-02-27 11:15:22 +0000 | [diff] [blame] | 5593 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5594 | if (DISPLAY_VER(dev_priv) >= 11) { |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5595 | if (wp->y_tiled) { |
| 5596 | int extra_lines; |
| 5597 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5598 | if (lines % wp->y_min_scanlines == 0) |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5599 | extra_lines = wp->y_min_scanlines; |
| 5600 | else |
| 5601 | extra_lines = wp->y_min_scanlines * 2 - |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5602 | lines % wp->y_min_scanlines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5603 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5604 | min_ddb_alloc = mul_round_up_u32_fixed16(lines + extra_lines, |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5605 | wp->plane_blocks_per_line); |
| 5606 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5607 | min_ddb_alloc = blocks + DIV_ROUND_UP(blocks, 10); |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5608 | } |
| 5609 | } |
| 5610 | |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5611 | if (!skl_wm_has_lines(dev_priv, level)) |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5612 | lines = 0; |
Ville Syrjälä | b52c273 | 2018-12-21 19:14:28 +0200 | [diff] [blame] | 5613 | |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5614 | if (lines > skl_wm_max_lines(dev_priv)) { |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5615 | /* reject it */ |
| 5616 | result->min_ddb_alloc = U16_MAX; |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5617 | return; |
Ville Syrjälä | 0aded17 | 2019-02-05 17:50:53 +0200 | [diff] [blame] | 5618 | } |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5619 | |
| 5620 | /* |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5621 | * If lines is valid, assume we can use this watermark level |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5622 | * for now. We'll come back and disable it after we calculate the |
| 5623 | * DDB allocation if it turns out we don't actually have enough |
| 5624 | * blocks to satisfy it. |
| 5625 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5626 | result->blocks = blocks; |
| 5627 | result->lines = lines; |
Ville Syrjälä | 961d95e | 2018-12-21 19:14:32 +0200 | [diff] [blame] | 5628 | /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5629 | result->min_ddb_alloc = max(min_ddb_alloc, blocks) + 1; |
| 5630 | result->enable = true; |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 5631 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5632 | if (DISPLAY_VER(dev_priv) < 12) |
Ville Syrjälä | 9c31212 | 2020-11-06 19:30:40 +0200 | [diff] [blame] | 5633 | result->can_sagv = latency >= dev_priv->sagv_block_time_us; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5634 | } |
| 5635 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5636 | static void |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5637 | skl_compute_wm_levels(const struct intel_crtc_state *crtc_state, |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5638 | const struct skl_wm_params *wm_params, |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5639 | struct skl_wm_level *levels) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5640 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 5641 | 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] | 5642 | int level, max_level = ilk_wm_max_level(dev_priv); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5643 | struct skl_wm_level *result_prev = &levels[0]; |
Lyude | a62163e | 2016-10-04 14:28:20 -0400 | [diff] [blame] | 5644 | |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5645 | for (level = 0; level <= max_level; level++) { |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5646 | struct skl_wm_level *result = &levels[level]; |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5647 | unsigned int latency = dev_priv->wm.skl_latency[level]; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5648 | |
Stanislav Lisovskiy | 7b99475 | 2020-04-09 18:47:18 +0300 | [diff] [blame] | 5649 | skl_compute_plane_wm(crtc_state, level, latency, |
| 5650 | wm_params, result_prev, result); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5651 | |
| 5652 | result_prev = result; |
Kumar, Mahesh | d2f5e36 | 2017-05-17 17:28:28 +0530 | [diff] [blame] | 5653 | } |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5654 | } |
| 5655 | |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5656 | static void tgl_compute_sagv_wm(const struct intel_crtc_state *crtc_state, |
| 5657 | const struct skl_wm_params *wm_params, |
| 5658 | struct skl_plane_wm *plane_wm) |
| 5659 | { |
| 5660 | 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] | 5661 | struct skl_wm_level *sagv_wm = &plane_wm->sagv.wm0; |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5662 | struct skl_wm_level *levels = plane_wm->wm; |
| 5663 | unsigned int latency = dev_priv->wm.skl_latency[0] + dev_priv->sagv_block_time_us; |
| 5664 | |
| 5665 | skl_compute_plane_wm(crtc_state, 0, latency, |
| 5666 | wm_params, &levels[0], |
| 5667 | sagv_wm); |
| 5668 | } |
| 5669 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5670 | static void skl_compute_transition_wm(struct drm_i915_private *dev_priv, |
| 5671 | struct skl_wm_level *trans_wm, |
| 5672 | const struct skl_wm_level *wm0, |
| 5673 | const struct skl_wm_params *wp) |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 5674 | { |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5675 | u16 trans_min, trans_amount, trans_y_tile_min; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5676 | u16 wm0_blocks, trans_offset, blocks; |
Damien Lespiau | 9414f56 | 2014-11-04 17:06:58 +0000 | [diff] [blame] | 5677 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5678 | /* Transition WM don't make any sense if ipc is disabled */ |
| 5679 | if (!dev_priv->ipc_enabled) |
Ville Syrjälä | 14a4306 | 2018-11-14 23:07:22 +0200 | [diff] [blame] | 5680 | return; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5681 | |
Ville Syrjälä | a7f1e8e | 2020-02-28 22:35:51 +0200 | [diff] [blame] | 5682 | /* |
| 5683 | * WaDisableTWM:skl,kbl,cfl,bxt |
| 5684 | * Transition WM are not recommended by HW team for GEN9 |
| 5685 | */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5686 | if (DISPLAY_VER(dev_priv) == 9) |
Ville Syrjälä | a7f1e8e | 2020-02-28 22:35:51 +0200 | [diff] [blame] | 5687 | return; |
| 5688 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5689 | if (DISPLAY_VER(dev_priv) >= 11) |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5690 | trans_min = 4; |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5691 | else |
| 5692 | trans_min = 14; |
| 5693 | |
| 5694 | /* Display WA #1140: glk,cnl */ |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 5695 | if (DISPLAY_VER(dev_priv) == 10) |
Ville Syrjälä | c834d03 | 2020-02-28 22:35:52 +0200 | [diff] [blame] | 5696 | trans_amount = 0; |
| 5697 | else |
| 5698 | trans_amount = 10; /* This is configurable amount */ |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5699 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5700 | trans_offset = trans_min + trans_amount; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5701 | |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5702 | /* |
| 5703 | * The spec asks for Selected Result Blocks for wm0 (the real value), |
| 5704 | * not Result Blocks (the integer value). Pay attention to the capital |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5705 | * letters. The value wm_l0->blocks is actually Result Blocks, but |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5706 | * since Result Blocks is the ceiling of Selected Result Blocks plus 1, |
| 5707 | * and since we later will have to get the ceiling of the sum in the |
| 5708 | * transition watermarks calculation, we can just pretend Selected |
| 5709 | * Result Blocks is Result Blocks minus 1 and it should work for the |
| 5710 | * current platforms. |
| 5711 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5712 | wm0_blocks = wm0->blocks - 1; |
Paulo Zanoni | cbacc79 | 2018-10-04 16:15:58 -0700 | [diff] [blame] | 5713 | |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5714 | if (wp->y_tiled) { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5715 | trans_y_tile_min = |
| 5716 | (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum); |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5717 | blocks = max(wm0_blocks, trans_y_tile_min) + trans_offset; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5718 | } else { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5719 | blocks = wm0_blocks + trans_offset; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5720 | } |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5721 | blocks++; |
Kumar, Mahesh | ca47667 | 2017-08-17 19:15:24 +0530 | [diff] [blame] | 5722 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 5723 | /* |
| 5724 | * Just assume we can enable the transition watermark. After |
| 5725 | * computing the DDB we'll come back and disable it if that |
| 5726 | * assumption turns out to be false. |
| 5727 | */ |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5728 | trans_wm->blocks = blocks; |
| 5729 | trans_wm->min_ddb_alloc = max_t(u16, wm0->min_ddb_alloc, blocks + 1); |
| 5730 | trans_wm->enable = true; |
Damien Lespiau | 407b50f | 2014-11-04 17:06:57 +0000 | [diff] [blame] | 5731 | } |
| 5732 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5733 | 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] | 5734 | const struct intel_plane_state *plane_state, |
| 5735 | enum plane_id plane_id, int color_plane) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5736 | { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5737 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); |
| 5738 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5739 | 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] | 5740 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5741 | int ret; |
| 5742 | |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5743 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5744 | &wm_params, color_plane); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5745 | if (ret) |
| 5746 | return ret; |
| 5747 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5748 | skl_compute_wm_levels(crtc_state, &wm_params, wm->wm); |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5749 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5750 | skl_compute_transition_wm(dev_priv, &wm->trans_wm, |
| 5751 | &wm->wm[0], &wm_params); |
| 5752 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5753 | if (DISPLAY_VER(dev_priv) >= 12) { |
Stanislav Lisovskiy | 7241c57 | 2020-05-14 10:48:51 +0300 | [diff] [blame] | 5754 | tgl_compute_sagv_wm(crtc_state, &wm_params, wm); |
| 5755 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5756 | skl_compute_transition_wm(dev_priv, &wm->sagv.trans_wm, |
| 5757 | &wm->sagv.wm0, &wm_params); |
| 5758 | } |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5759 | |
| 5760 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5761 | } |
| 5762 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5763 | 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] | 5764 | const struct intel_plane_state *plane_state, |
| 5765 | enum plane_id plane_id) |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5766 | { |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5767 | 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] | 5768 | struct skl_wm_params wm_params; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5769 | int ret; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5770 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5771 | wm->is_planar = true; |
| 5772 | |
| 5773 | /* uv plane watermarks must also be validated for NV12/Planar */ |
Ville Syrjälä | 51de9c6 | 2018-11-14 23:07:25 +0200 | [diff] [blame] | 5774 | ret = skl_compute_plane_wm_params(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5775 | &wm_params, 1); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5776 | if (ret) |
| 5777 | return ret; |
| 5778 | |
Ville Syrjälä | 67155a6 | 2019-03-12 22:58:37 +0200 | [diff] [blame] | 5779 | skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5780 | |
| 5781 | return 0; |
| 5782 | } |
| 5783 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5784 | 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] | 5785 | const struct intel_plane_state *plane_state) |
| 5786 | { |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 5787 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5788 | enum plane_id plane_id = plane->id; |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5789 | struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id]; |
| 5790 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5791 | int ret; |
| 5792 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5793 | memset(wm, 0, sizeof(*wm)); |
| 5794 | |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5795 | if (!intel_wm_plane_visible(crtc_state, plane_state)) |
| 5796 | return 0; |
| 5797 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5798 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5799 | plane_id, 0); |
| 5800 | if (ret) |
| 5801 | return ret; |
| 5802 | |
| 5803 | if (fb->format->is_yuv && fb->format->num_planes > 1) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5804 | ret = skl_build_plane_wm_uv(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5805 | plane_id); |
| 5806 | if (ret) |
| 5807 | return ret; |
| 5808 | } |
| 5809 | |
| 5810 | return 0; |
| 5811 | } |
| 5812 | |
Ville Syrjälä | 96cb7cd | 2019-03-12 22:58:43 +0200 | [diff] [blame] | 5813 | 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] | 5814 | const struct intel_plane_state *plane_state) |
| 5815 | { |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5816 | struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane); |
| 5817 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
| 5818 | enum plane_id plane_id = plane->id; |
| 5819 | 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] | 5820 | int ret; |
| 5821 | |
| 5822 | /* Watermarks calculated in master */ |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5823 | if (plane_state->planar_slave) |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5824 | return 0; |
| 5825 | |
Ville Syrjälä | f99b805 | 2021-03-27 02:59:45 +0200 | [diff] [blame] | 5826 | memset(wm, 0, sizeof(*wm)); |
| 5827 | |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5828 | if (plane_state->planar_linked_plane) { |
Maarten Lankhorst | 7b3cb17 | 2019-10-31 12:26:07 +0100 | [diff] [blame] | 5829 | const struct drm_framebuffer *fb = plane_state->hw.fb; |
Maarten Lankhorst | c47b7dd | 2019-09-20 13:42:20 +0200 | [diff] [blame] | 5830 | 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] | 5831 | |
Pankaj Bharadiya | 19edeb38 | 2020-05-04 23:45:59 +0530 | [diff] [blame] | 5832 | drm_WARN_ON(&dev_priv->drm, |
| 5833 | !intel_wm_plane_visible(crtc_state, plane_state)); |
| 5834 | drm_WARN_ON(&dev_priv->drm, !fb->format->is_yuv || |
| 5835 | fb->format->num_planes == 1); |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5836 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5837 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5838 | y_plane_id, 0); |
| 5839 | if (ret) |
| 5840 | return ret; |
| 5841 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5842 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5843 | plane_id, 1); |
| 5844 | if (ret) |
| 5845 | return ret; |
| 5846 | } else if (intel_wm_plane_visible(crtc_state, plane_state)) { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5847 | ret = skl_build_plane_wm_single(crtc_state, plane_state, |
Ville Syrjälä | 8315847 | 2018-11-27 18:57:26 +0200 | [diff] [blame] | 5848 | plane_id, 0); |
| 5849 | if (ret) |
| 5850 | return ret; |
| 5851 | } |
| 5852 | |
| 5853 | return 0; |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5854 | } |
| 5855 | |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5856 | static int skl_build_pipe_wm(struct intel_atomic_state *state, |
| 5857 | struct intel_crtc *crtc) |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5858 | { |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 5859 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 5860 | struct intel_crtc_state *crtc_state = |
| 5861 | intel_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | af9fbfa | 2019-10-04 13:34:53 +0200 | [diff] [blame] | 5862 | const struct intel_plane_state *plane_state; |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5863 | struct intel_plane *plane; |
| 5864 | int ret, i; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5865 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5866 | for_each_new_intel_plane_in_state(state, plane, plane_state, i) { |
| 5867 | /* |
| 5868 | * FIXME should perhaps check {old,new}_plane_crtc->hw.crtc |
| 5869 | * instead but we don't populate that correctly for NV12 Y |
| 5870 | * planes so for now hack this. |
| 5871 | */ |
| 5872 | if (plane->pipe != crtc->pipe) |
| 5873 | continue; |
Kumar, Mahesh | eb2fdcd | 2017-05-17 17:28:27 +0530 | [diff] [blame] | 5874 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5875 | if (DISPLAY_VER(dev_priv) >= 11) |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5876 | ret = icl_build_plane_wm(crtc_state, plane_state); |
Maarten Lankhorst | b048a00 | 2018-10-18 13:51:30 +0200 | [diff] [blame] | 5877 | else |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 5878 | ret = skl_build_plane_wm(crtc_state, plane_state); |
Kumar, Mahesh | 7e452fd | 2017-08-17 19:15:23 +0530 | [diff] [blame] | 5879 | if (ret) |
| 5880 | return ret; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5881 | } |
Mahesh Kumar | 942aa2d | 2018-04-09 09:11:04 +0530 | [diff] [blame] | 5882 | |
Ville Syrjälä | dbf7138 | 2020-11-06 19:30:38 +0200 | [diff] [blame] | 5883 | crtc_state->wm.skl.optimal = crtc_state->wm.skl.raw; |
| 5884 | |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 5885 | return 0; |
Pradeep Bhat | 2d41c0b | 2014-11-04 17:06:42 +0000 | [diff] [blame] | 5886 | } |
| 5887 | |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5888 | static void skl_ddb_entry_write(struct drm_i915_private *dev_priv, |
| 5889 | i915_reg_t reg, |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5890 | const struct skl_ddb_entry *entry) |
| 5891 | { |
| 5892 | if (entry->end) |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5893 | intel_de_write_fw(dev_priv, reg, |
| 5894 | (entry->end - 1) << 16 | entry->start); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5895 | else |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5896 | intel_de_write_fw(dev_priv, reg, 0); |
Damien Lespiau | 16160e3 | 2014-11-04 17:06:53 +0000 | [diff] [blame] | 5897 | } |
| 5898 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5899 | static void skl_write_wm_level(struct drm_i915_private *dev_priv, |
| 5900 | i915_reg_t reg, |
| 5901 | const struct skl_wm_level *level) |
| 5902 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 5903 | u32 val = 0; |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5904 | |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5905 | if (level->enable) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5906 | val |= PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5907 | if (level->ignore_lines) |
| 5908 | val |= PLANE_WM_IGNORE_LINES; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5909 | val |= level->blocks; |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 5910 | val |= REG_FIELD_PREP(PLANE_WM_LINES_MASK, level->lines); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5911 | |
Jani Nikula | 9b6320a | 2020-01-23 16:00:04 +0200 | [diff] [blame] | 5912 | intel_de_write_fw(dev_priv, reg, val); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5913 | } |
| 5914 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5915 | void skl_write_plane_wm(struct intel_plane *plane, |
| 5916 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5917 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5918 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5919 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5920 | enum plane_id plane_id = plane->id; |
| 5921 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5922 | const struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal; |
| 5923 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5924 | const struct skl_ddb_entry *ddb_y = |
| 5925 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 5926 | const struct skl_ddb_entry *ddb_uv = |
| 5927 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5928 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5929 | for (level = 0; level <= max_level; level++) |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5930 | 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] | 5931 | skl_plane_wm_level(pipe_wm, plane_id, level)); |
| 5932 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 5933 | 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] | 5934 | skl_plane_trans_wm(pipe_wm, plane_id)); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5935 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 5936 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 5937 | skl_write_wm_level(dev_priv, PLANE_WM_SAGV(pipe, plane_id), |
| 5938 | &wm->sagv.wm0); |
| 5939 | skl_write_wm_level(dev_priv, PLANE_WM_SAGV_TRANS(pipe, plane_id), |
| 5940 | &wm->sagv.trans_wm); |
| 5941 | } |
| 5942 | |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 5943 | if (DISPLAY_VER(dev_priv) >= 11) { |
Mahesh Kumar | 234059d | 2018-01-30 11:49:13 -0200 | [diff] [blame] | 5944 | skl_ddb_entry_write(dev_priv, |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5945 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5946 | return; |
Mahesh Kumar | b879d58 | 2018-04-09 09:11:01 +0530 | [diff] [blame] | 5947 | } |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5948 | |
| 5949 | if (wm->is_planar) |
| 5950 | swap(ddb_y, ddb_uv); |
| 5951 | |
| 5952 | skl_ddb_entry_write(dev_priv, |
| 5953 | PLANE_BUF_CFG(pipe, plane_id), ddb_y); |
| 5954 | skl_ddb_entry_write(dev_priv, |
| 5955 | PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5956 | } |
| 5957 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5958 | void skl_write_cursor_wm(struct intel_plane *plane, |
| 5959 | const struct intel_crtc_state *crtc_state) |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5960 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5961 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 5962 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5963 | enum plane_id plane_id = plane->id; |
| 5964 | enum pipe pipe = plane->pipe; |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5965 | 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] | 5966 | const struct skl_ddb_entry *ddb = |
| 5967 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5968 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5969 | for (level = 0; level <= max_level; level++) |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 5970 | skl_write_wm_level(dev_priv, CUR_WM(pipe, level), |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 5971 | skl_plane_wm_level(pipe_wm, plane_id, level)); |
| 5972 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 5973 | skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), |
| 5974 | skl_plane_trans_wm(pipe_wm, plane_id)); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 5975 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 5976 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 5977 | const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id]; |
| 5978 | |
| 5979 | skl_write_wm_level(dev_priv, CUR_WM_SAGV(pipe), |
| 5980 | &wm->sagv.wm0); |
| 5981 | skl_write_wm_level(dev_priv, CUR_WM_SAGV_TRANS(pipe), |
| 5982 | &wm->sagv.trans_wm); |
| 5983 | } |
| 5984 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5985 | skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 5986 | } |
| 5987 | |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5988 | bool skl_wm_level_equals(const struct skl_wm_level *l1, |
| 5989 | const struct skl_wm_level *l2) |
| 5990 | { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5991 | return l1->enable == l2->enable && |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 5992 | l1->ignore_lines == l2->ignore_lines && |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 5993 | l1->lines == l2->lines && |
| 5994 | l1->blocks == l2->blocks; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5995 | } |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 5996 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 5997 | static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv, |
| 5998 | const struct skl_plane_wm *wm1, |
| 5999 | const struct skl_plane_wm *wm2) |
| 6000 | { |
| 6001 | int level, max_level = ilk_wm_max_level(dev_priv); |
cpaul@redhat.com | 45ece23 | 2016-10-14 17:31:56 -0400 | [diff] [blame] | 6002 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6003 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | e7f54e6 | 2020-02-28 22:35:49 +0200 | [diff] [blame] | 6004 | /* |
| 6005 | * We don't check uv_wm as the hardware doesn't actually |
| 6006 | * use it. It only gets used for calculating the required |
| 6007 | * ddb allocation. |
| 6008 | */ |
| 6009 | if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level])) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6010 | return false; |
| 6011 | } |
| 6012 | |
Ville Syrjälä | f11449d | 2021-02-26 17:32:00 +0200 | [diff] [blame] | 6013 | return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm) && |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6014 | skl_wm_level_equals(&wm1->sagv.wm0, &wm2->sagv.wm0) && |
| 6015 | 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] | 6016 | } |
| 6017 | |
Jani Nikula | 81b55ef | 2020-04-20 17:04:38 +0300 | [diff] [blame] | 6018 | static bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a, |
| 6019 | const struct skl_ddb_entry *b) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6020 | { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 6021 | return a->start < b->end && b->start < a->end; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6022 | } |
| 6023 | |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6024 | static void skl_ddb_entry_union(struct skl_ddb_entry *a, |
| 6025 | const struct skl_ddb_entry *b) |
| 6026 | { |
| 6027 | if (a->end && b->end) { |
| 6028 | a->start = min(a->start, b->start); |
| 6029 | a->end = max(a->end, b->end); |
| 6030 | } else if (b->end) { |
| 6031 | a->start = b->start; |
| 6032 | a->end = b->end; |
| 6033 | } |
| 6034 | } |
| 6035 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6036 | bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb, |
Jani Nikula | 696173b | 2019-04-05 14:00:15 +0300 | [diff] [blame] | 6037 | const struct skl_ddb_entry *entries, |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6038 | int num_entries, int ignore_idx) |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6039 | { |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6040 | int i; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6041 | |
Ville Syrjälä | 53cc6880 | 2018-11-01 17:05:59 +0200 | [diff] [blame] | 6042 | for (i = 0; i < num_entries; i++) { |
| 6043 | if (i != ignore_idx && |
| 6044 | skl_ddb_entries_overlap(ddb, &entries[i])) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 6045 | return true; |
Mika Kahola | 2b68504 | 2017-10-10 13:17:03 +0300 | [diff] [blame] | 6046 | } |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6047 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 6048 | return false; |
Damien Lespiau | 0e8fb7b | 2014-11-04 17:07:02 +0000 | [diff] [blame] | 6049 | } |
| 6050 | |
Jani Nikula | bb7791b | 2016-10-04 12:29:17 +0300 | [diff] [blame] | 6051 | static int |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6052 | skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state, |
| 6053 | struct intel_crtc_state *new_crtc_state) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6054 | { |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 6055 | struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->uapi.state); |
| 6056 | 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] | 6057 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6058 | struct intel_plane *plane; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6059 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6060 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6061 | struct intel_plane_state *plane_state; |
| 6062 | enum plane_id plane_id = plane->id; |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6063 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6064 | if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id], |
| 6065 | &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) && |
| 6066 | skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id], |
| 6067 | &new_crtc_state->wm.skl.plane_ddb_uv[plane_id])) |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6068 | continue; |
| 6069 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6070 | plane_state = intel_atomic_get_plane_state(state, plane); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6071 | if (IS_ERR(plane_state)) |
| 6072 | return PTR_ERR(plane_state); |
Maarten Lankhorst | 1ab554b | 2018-10-22 15:51:52 +0200 | [diff] [blame] | 6073 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6074 | new_crtc_state->update_planes |= BIT(plane_id); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | return 0; |
| 6078 | } |
| 6079 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6080 | static u8 intel_dbuf_enabled_slices(const struct intel_dbuf_state *dbuf_state) |
| 6081 | { |
| 6082 | struct drm_i915_private *dev_priv = to_i915(dbuf_state->base.state->base.dev); |
| 6083 | u8 enabled_slices; |
| 6084 | enum pipe pipe; |
| 6085 | |
| 6086 | /* |
| 6087 | * FIXME: For now we always enable slice S1 as per |
| 6088 | * the Bspec display initialization sequence. |
| 6089 | */ |
| 6090 | enabled_slices = BIT(DBUF_S1); |
| 6091 | |
| 6092 | for_each_pipe(dev_priv, pipe) |
| 6093 | enabled_slices |= dbuf_state->slices[pipe]; |
| 6094 | |
| 6095 | return enabled_slices; |
| 6096 | } |
| 6097 | |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6098 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6099 | skl_compute_ddb(struct intel_atomic_state *state) |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6100 | { |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 6101 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 6102 | const struct intel_dbuf_state *old_dbuf_state; |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6103 | struct intel_dbuf_state *new_dbuf_state = NULL; |
Ville Syrjälä | 70b1a26 | 2020-02-25 19:11:16 +0200 | [diff] [blame] | 6104 | const struct intel_crtc_state *old_crtc_state; |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6105 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6106 | struct intel_crtc *crtc; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6107 | int ret, i; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6108 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6109 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6110 | new_dbuf_state = intel_atomic_get_dbuf_state(state); |
| 6111 | if (IS_ERR(new_dbuf_state)) |
| 6112 | return PTR_ERR(new_dbuf_state); |
| 6113 | |
| 6114 | old_dbuf_state = intel_atomic_get_old_dbuf_state(state); |
| 6115 | break; |
| 6116 | } |
| 6117 | |
| 6118 | if (!new_dbuf_state) |
| 6119 | return 0; |
| 6120 | |
| 6121 | new_dbuf_state->active_pipes = |
| 6122 | intel_calc_active_pipes(state, old_dbuf_state->active_pipes); |
| 6123 | |
| 6124 | if (old_dbuf_state->active_pipes != new_dbuf_state->active_pipes) { |
| 6125 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6126 | if (ret) |
| 6127 | return ret; |
| 6128 | } |
| 6129 | |
| 6130 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6131 | enum pipe pipe = crtc->pipe; |
| 6132 | |
| 6133 | new_dbuf_state->slices[pipe] = |
| 6134 | skl_compute_dbuf_slices(crtc, new_dbuf_state->active_pipes); |
| 6135 | |
| 6136 | if (old_dbuf_state->slices[pipe] == new_dbuf_state->slices[pipe]) |
| 6137 | continue; |
| 6138 | |
| 6139 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6140 | if (ret) |
| 6141 | return ret; |
| 6142 | } |
| 6143 | |
| 6144 | new_dbuf_state->enabled_slices = intel_dbuf_enabled_slices(new_dbuf_state); |
| 6145 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6146 | if (IS_ALDERLAKE_P(dev_priv)) |
| 6147 | new_dbuf_state->joined_mbus = adlp_check_mbus_joined(new_dbuf_state->active_pipes); |
| 6148 | |
| 6149 | if (old_dbuf_state->enabled_slices != new_dbuf_state->enabled_slices || |
| 6150 | old_dbuf_state->joined_mbus != new_dbuf_state->joined_mbus) { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6151 | ret = intel_atomic_serialize_global_state(&new_dbuf_state->base); |
| 6152 | if (ret) |
| 6153 | return ret; |
| 6154 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6155 | if (old_dbuf_state->joined_mbus != new_dbuf_state->joined_mbus) { |
| 6156 | /* TODO: Implement vblank synchronized MBUS joining changes */ |
| 6157 | ret = intel_modeset_all_pipes(state); |
| 6158 | if (ret) |
| 6159 | return ret; |
| 6160 | } |
| 6161 | |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6162 | drm_dbg_kms(&dev_priv->drm, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6163 | "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] | 6164 | old_dbuf_state->enabled_slices, |
| 6165 | new_dbuf_state->enabled_slices, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6166 | INTEL_INFO(dev_priv)->dbuf.slice_mask, |
| 6167 | yesno(old_dbuf_state->joined_mbus), |
| 6168 | yesno(new_dbuf_state->joined_mbus)); |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6172 | enum pipe pipe = crtc->pipe; |
| 6173 | |
| 6174 | new_dbuf_state->weight[pipe] = intel_crtc_ddb_weight(new_crtc_state); |
| 6175 | |
| 6176 | if (old_dbuf_state->weight[pipe] == new_dbuf_state->weight[pipe]) |
| 6177 | continue; |
| 6178 | |
| 6179 | ret = intel_atomic_lock_global_state(&new_dbuf_state->base); |
| 6180 | if (ret) |
| 6181 | return ret; |
| 6182 | } |
| 6183 | |
| 6184 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6185 | ret = skl_crtc_allocate_ddb(state, crtc); |
| 6186 | if (ret) |
| 6187 | return ret; |
| 6188 | } |
| 6189 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6190 | 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] | 6191 | new_crtc_state, i) { |
Ville Syrjälä | ef79d62 | 2021-01-22 22:56:32 +0200 | [diff] [blame] | 6192 | ret = skl_allocate_plane_ddb(state, crtc); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6193 | if (ret) |
| 6194 | return ret; |
| 6195 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6196 | ret = skl_ddb_add_affected_planes(old_crtc_state, |
| 6197 | new_crtc_state); |
Rodrigo Vivi | 9a30a26 | 2017-06-13 10:52:30 -0700 | [diff] [blame] | 6198 | if (ret) |
| 6199 | return ret; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6200 | } |
| 6201 | |
| 6202 | return 0; |
| 6203 | } |
| 6204 | |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6205 | static char enast(bool enable) |
| 6206 | { |
| 6207 | return enable ? '*' : ' '; |
| 6208 | } |
| 6209 | |
Matt Roper | 2722efb | 2016-08-17 15:55:55 -0400 | [diff] [blame] | 6210 | static void |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6211 | skl_print_wm_changes(struct intel_atomic_state *state) |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6212 | { |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6213 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 6214 | const struct intel_crtc_state *old_crtc_state; |
| 6215 | const struct intel_crtc_state *new_crtc_state; |
| 6216 | struct intel_plane *plane; |
| 6217 | struct intel_crtc *crtc; |
Maarten Lankhorst | 7570498 | 2016-11-01 12:04:10 +0100 | [diff] [blame] | 6218 | int i; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6219 | |
Jani Nikula | bdbf43d | 2019-10-28 12:38:15 +0200 | [diff] [blame] | 6220 | if (!drm_debug_enabled(DRM_UT_KMS)) |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6221 | return; |
| 6222 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6223 | for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, |
| 6224 | new_crtc_state, i) { |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6225 | const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm; |
| 6226 | |
| 6227 | old_pipe_wm = &old_crtc_state->wm.skl.optimal; |
| 6228 | new_pipe_wm = &new_crtc_state->wm.skl.optimal; |
| 6229 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6230 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6231 | enum plane_id plane_id = plane->id; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6232 | const struct skl_ddb_entry *old, *new; |
| 6233 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6234 | old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 6235 | new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id]; |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6236 | |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6237 | if (skl_ddb_entry_equal(old, new)) |
| 6238 | continue; |
| 6239 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6240 | drm_dbg_kms(&dev_priv->drm, |
| 6241 | "[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n", |
| 6242 | plane->base.base.id, plane->base.name, |
| 6243 | old->start, old->end, new->start, new->end, |
| 6244 | skl_ddb_entry_size(old), skl_ddb_entry_size(new)); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6248 | enum plane_id plane_id = plane->id; |
| 6249 | const struct skl_plane_wm *old_wm, *new_wm; |
| 6250 | |
| 6251 | old_wm = &old_pipe_wm->planes[plane_id]; |
| 6252 | new_wm = &new_pipe_wm->planes[plane_id]; |
| 6253 | |
| 6254 | if (skl_plane_wm_equals(dev_priv, old_wm, new_wm)) |
| 6255 | continue; |
| 6256 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6257 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6258 | "[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm,%cstwm" |
| 6259 | " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm,%cstwm\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6260 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6261 | enast(old_wm->wm[0].enable), enast(old_wm->wm[1].enable), |
| 6262 | enast(old_wm->wm[2].enable), enast(old_wm->wm[3].enable), |
| 6263 | enast(old_wm->wm[4].enable), enast(old_wm->wm[5].enable), |
| 6264 | enast(old_wm->wm[6].enable), enast(old_wm->wm[7].enable), |
| 6265 | enast(old_wm->trans_wm.enable), |
| 6266 | enast(old_wm->sagv.wm0.enable), |
| 6267 | enast(old_wm->sagv.trans_wm.enable), |
| 6268 | enast(new_wm->wm[0].enable), enast(new_wm->wm[1].enable), |
| 6269 | enast(new_wm->wm[2].enable), enast(new_wm->wm[3].enable), |
| 6270 | enast(new_wm->wm[4].enable), enast(new_wm->wm[5].enable), |
| 6271 | enast(new_wm->wm[6].enable), enast(new_wm->wm[7].enable), |
| 6272 | enast(new_wm->trans_wm.enable), |
| 6273 | enast(new_wm->sagv.wm0.enable), |
| 6274 | enast(new_wm->sagv.trans_wm.enable)); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6275 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6276 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6277 | "[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" |
| 6278 | " -> %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] | 6279 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6280 | enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].lines, |
| 6281 | enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].lines, |
| 6282 | enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].lines, |
| 6283 | enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].lines, |
| 6284 | enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].lines, |
| 6285 | enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].lines, |
| 6286 | enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].lines, |
| 6287 | enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].lines, |
| 6288 | enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.lines, |
| 6289 | enast(old_wm->sagv.wm0.ignore_lines), old_wm->sagv.wm0.lines, |
| 6290 | enast(old_wm->sagv.trans_wm.ignore_lines), old_wm->sagv.trans_wm.lines, |
| 6291 | enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].lines, |
| 6292 | enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].lines, |
| 6293 | enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].lines, |
| 6294 | enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].lines, |
| 6295 | enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].lines, |
| 6296 | enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].lines, |
| 6297 | enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].lines, |
| 6298 | enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].lines, |
| 6299 | enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.lines, |
| 6300 | enast(new_wm->sagv.wm0.ignore_lines), new_wm->sagv.wm0.lines, |
| 6301 | 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] | 6302 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6303 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6304 | "[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d" |
| 6305 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6306 | plane->base.base.id, plane->base.name, |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6307 | old_wm->wm[0].blocks, old_wm->wm[1].blocks, |
| 6308 | old_wm->wm[2].blocks, old_wm->wm[3].blocks, |
| 6309 | old_wm->wm[4].blocks, old_wm->wm[5].blocks, |
| 6310 | old_wm->wm[6].blocks, old_wm->wm[7].blocks, |
| 6311 | old_wm->trans_wm.blocks, |
| 6312 | old_wm->sagv.wm0.blocks, |
| 6313 | old_wm->sagv.trans_wm.blocks, |
| 6314 | new_wm->wm[0].blocks, new_wm->wm[1].blocks, |
| 6315 | new_wm->wm[2].blocks, new_wm->wm[3].blocks, |
| 6316 | new_wm->wm[4].blocks, new_wm->wm[5].blocks, |
| 6317 | new_wm->wm[6].blocks, new_wm->wm[7].blocks, |
| 6318 | new_wm->trans_wm.blocks, |
| 6319 | new_wm->sagv.wm0.blocks, |
| 6320 | new_wm->sagv.trans_wm.blocks); |
Ville Syrjälä | ab98e94 | 2019-02-08 22:05:27 +0200 | [diff] [blame] | 6321 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6322 | drm_dbg_kms(&dev_priv->drm, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6323 | "[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d" |
| 6324 | " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d\n", |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6325 | plane->base.base.id, plane->base.name, |
| 6326 | old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc, |
| 6327 | old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc, |
| 6328 | old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc, |
| 6329 | old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc, |
| 6330 | old_wm->trans_wm.min_ddb_alloc, |
Ville Syrjälä | a68aa48 | 2021-02-26 17:32:01 +0200 | [diff] [blame] | 6331 | old_wm->sagv.wm0.min_ddb_alloc, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6332 | old_wm->sagv.trans_wm.min_ddb_alloc, |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6333 | new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc, |
| 6334 | new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc, |
| 6335 | new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc, |
| 6336 | 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] | 6337 | new_wm->trans_wm.min_ddb_alloc, |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6338 | new_wm->sagv.wm0.min_ddb_alloc, |
| 6339 | new_wm->sagv.trans_wm.min_ddb_alloc); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6340 | } |
| 6341 | } |
| 6342 | } |
| 6343 | |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6344 | static bool skl_plane_selected_wm_equals(struct intel_plane *plane, |
| 6345 | const struct skl_pipe_wm *old_pipe_wm, |
| 6346 | const struct skl_pipe_wm *new_pipe_wm) |
| 6347 | { |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6348 | struct drm_i915_private *i915 = to_i915(plane->base.dev); |
| 6349 | int level, max_level = ilk_wm_max_level(i915); |
| 6350 | |
| 6351 | for (level = 0; level <= max_level; level++) { |
| 6352 | /* |
| 6353 | * We don't check uv_wm as the hardware doesn't actually |
| 6354 | * use it. It only gets used for calculating the required |
| 6355 | * ddb allocation. |
| 6356 | */ |
Ville Syrjälä | 93fe862 | 2021-03-25 02:44:14 +0200 | [diff] [blame] | 6357 | if (!skl_wm_level_equals(skl_plane_wm_level(old_pipe_wm, plane->id, level), |
| 6358 | skl_plane_wm_level(new_pipe_wm, plane->id, level))) |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6359 | return false; |
| 6360 | } |
| 6361 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 6362 | if (HAS_HW_SAGV_WM(i915)) { |
| 6363 | const struct skl_plane_wm *old_wm = &old_pipe_wm->planes[plane->id]; |
| 6364 | const struct skl_plane_wm *new_wm = &new_pipe_wm->planes[plane->id]; |
| 6365 | |
| 6366 | if (!skl_wm_level_equals(&old_wm->sagv.wm0, &new_wm->sagv.wm0) || |
| 6367 | !skl_wm_level_equals(&old_wm->sagv.trans_wm, &new_wm->sagv.trans_wm)) |
| 6368 | return false; |
| 6369 | } |
| 6370 | |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6371 | return skl_wm_level_equals(skl_plane_trans_wm(old_pipe_wm, plane->id), |
| 6372 | skl_plane_trans_wm(new_pipe_wm, plane->id)); |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6373 | } |
| 6374 | |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6375 | /* |
| 6376 | * To make sure the cursor watermark registers are always consistent |
| 6377 | * with our computed state the following scenario needs special |
| 6378 | * treatment: |
| 6379 | * |
| 6380 | * 1. enable cursor |
| 6381 | * 2. move cursor entirely offscreen |
| 6382 | * 3. disable cursor |
| 6383 | * |
| 6384 | * Step 2. does call .disable_plane() but does not zero the watermarks |
| 6385 | * (since we consider an offscreen cursor still active for the purposes |
| 6386 | * of watermarks). Step 3. would not normally call .disable_plane() |
| 6387 | * because the actual plane visibility isn't changing, and we don't |
| 6388 | * deallocate the cursor ddb until the pipe gets disabled. So we must |
| 6389 | * force step 3. to call .disable_plane() to update the watermark |
| 6390 | * registers properly. |
| 6391 | * |
| 6392 | * Other planes do not suffer from this issues as their watermarks are |
| 6393 | * calculated based on the actual plane visibility. The only time this |
| 6394 | * can trigger for the other planes is during the initial readout as the |
| 6395 | * default value of the watermarks registers is not zero. |
| 6396 | */ |
| 6397 | static int skl_wm_add_affected_planes(struct intel_atomic_state *state, |
| 6398 | struct intel_crtc *crtc) |
| 6399 | { |
| 6400 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6401 | const struct intel_crtc_state *old_crtc_state = |
| 6402 | intel_atomic_get_old_crtc_state(state, crtc); |
| 6403 | struct intel_crtc_state *new_crtc_state = |
| 6404 | intel_atomic_get_new_crtc_state(state, crtc); |
| 6405 | struct intel_plane *plane; |
| 6406 | |
| 6407 | for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) { |
| 6408 | struct intel_plane_state *plane_state; |
| 6409 | enum plane_id plane_id = plane->id; |
| 6410 | |
| 6411 | /* |
| 6412 | * Force a full wm update for every plane on modeset. |
| 6413 | * Required because the reset value of the wm registers |
| 6414 | * is non-zero, whereas we want all disabled planes to |
| 6415 | * have zero watermarks. So if we turn off the relevant |
| 6416 | * power well the hardware state will go out of sync |
| 6417 | * with the software state. |
| 6418 | */ |
Maarten Lankhorst | 2225f3c | 2019-10-31 12:26:03 +0100 | [diff] [blame] | 6419 | if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) && |
Ville Syrjälä | 2871b2f | 2021-02-26 17:31:58 +0200 | [diff] [blame] | 6420 | skl_plane_selected_wm_equals(plane, |
| 6421 | &old_crtc_state->wm.skl.optimal, |
| 6422 | &new_crtc_state->wm.skl.optimal)) |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6423 | continue; |
| 6424 | |
| 6425 | plane_state = intel_atomic_get_plane_state(state, plane); |
| 6426 | if (IS_ERR(plane_state)) |
| 6427 | return PTR_ERR(plane_state); |
| 6428 | |
| 6429 | new_crtc_state->update_planes |= BIT(plane_id); |
| 6430 | } |
| 6431 | |
| 6432 | return 0; |
| 6433 | } |
| 6434 | |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6435 | static int |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6436 | skl_compute_wm(struct intel_atomic_state *state) |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6437 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6438 | struct intel_crtc *crtc; |
Ville Syrjälä | 8cac9fd | 2019-03-12 22:58:44 +0200 | [diff] [blame] | 6439 | struct intel_crtc_state *new_crtc_state; |
Mahesh Kumar | e1f96a6 | 2018-04-09 09:11:08 +0530 | [diff] [blame] | 6440 | int ret, i; |
| 6441 | |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 6442 | for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 6443 | ret = skl_build_pipe_wm(state, crtc); |
Ville Syrjälä | ff43bc3 | 2018-11-27 18:59:00 +0200 | [diff] [blame] | 6444 | if (ret) |
| 6445 | return ret; |
Matt Roper | 734fa01 | 2016-05-12 15:11:40 -0700 | [diff] [blame] | 6446 | } |
| 6447 | |
Matt Roper | d8e8749 | 2018-12-11 09:31:07 -0800 | [diff] [blame] | 6448 | ret = skl_compute_ddb(state); |
| 6449 | if (ret) |
| 6450 | return ret; |
| 6451 | |
Stanislav Lisovskiy | ecab0f3 | 2020-04-30 22:56:34 +0300 | [diff] [blame] | 6452 | ret = intel_compute_sagv_mask(state); |
| 6453 | if (ret) |
| 6454 | return ret; |
Stanislav Lisovskiy | 9728889 | 2020-04-30 22:17:57 +0300 | [diff] [blame] | 6455 | |
Ville Syrjälä | 23baedd | 2020-02-28 22:35:50 +0200 | [diff] [blame] | 6456 | /* |
| 6457 | * skl_compute_ddb() will have adjusted the final watermarks |
| 6458 | * based on how much ddb is available. Now we can actually |
| 6459 | * check if the final watermarks changed. |
| 6460 | */ |
Ville Syrjälä | ffc9003 | 2020-11-06 19:30:37 +0200 | [diff] [blame] | 6461 | 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] | 6462 | ret = skl_wm_add_affected_planes(state, crtc); |
| 6463 | if (ret) |
| 6464 | return ret; |
| 6465 | } |
| 6466 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6467 | skl_print_wm_changes(state); |
cpaul@redhat.com | 413fc53 | 2016-10-14 17:31:54 -0400 | [diff] [blame] | 6468 | |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 6469 | return 0; |
| 6470 | } |
| 6471 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6472 | 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] | 6473 | struct intel_wm_config *config) |
| 6474 | { |
| 6475 | struct intel_crtc *crtc; |
| 6476 | |
| 6477 | /* Compute the currently _active_ config */ |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6478 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6479 | const struct intel_pipe_wm *wm = &crtc->wm.active.ilk; |
| 6480 | |
| 6481 | if (!wm->pipe_enabled) |
| 6482 | continue; |
| 6483 | |
| 6484 | config->sprites_enabled |= wm->sprites_enabled; |
| 6485 | config->sprites_scaled |= wm->sprites_scaled; |
| 6486 | config->num_pipes_active++; |
| 6487 | } |
| 6488 | } |
| 6489 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6490 | static void ilk_program_watermarks(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 801bcff | 2013-05-31 10:08:35 -0300 | [diff] [blame] | 6491 | { |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6492 | 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] | 6493 | struct ilk_wm_maximums max; |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6494 | struct intel_wm_config config = {}; |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6495 | struct ilk_wm_values results = {}; |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 6496 | enum intel_ddb_partitioning partitioning; |
Matt Roper | 261a27d | 2015-10-08 15:28:25 -0700 | [diff] [blame] | 6497 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6498 | ilk_compute_wm_config(dev_priv, &config); |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6499 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6500 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max); |
| 6501 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2); |
Ville Syrjälä | 0362c78 | 2013-10-09 19:17:57 +0300 | [diff] [blame] | 6502 | |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 6503 | /* 5/6 split only in single pipe config on IVB+ */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 6504 | if (DISPLAY_VER(dev_priv) >= 7 && |
Ville Syrjälä | d890565 | 2016-01-14 14:53:35 +0200 | [diff] [blame] | 6505 | config.num_pipes_active == 1 && config.sprites_enabled) { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6506 | ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max); |
| 6507 | ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6); |
Ville Syrjälä | a485bfb | 2013-10-09 19:17:59 +0300 | [diff] [blame] | 6508 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6509 | 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] | 6510 | } else { |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 6511 | best_lp_wm = &lp_wm_1_2; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6512 | } |
| 6513 | |
Ville Syrjälä | 198a1e9 | 2013-10-09 19:17:58 +0300 | [diff] [blame] | 6514 | partitioning = (best_lp_wm == &lp_wm_1_2) ? |
Ville Syrjälä | 77c122b | 2013-08-06 22:24:04 +0300 | [diff] [blame] | 6515 | INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6; |
Paulo Zanoni | 861f338 | 2013-05-31 10:19:21 -0300 | [diff] [blame] | 6516 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6517 | ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results); |
Ville Syrjälä | 609cede | 2013-10-09 19:18:03 +0300 | [diff] [blame] | 6518 | |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6519 | ilk_write_wm_values(dev_priv, &results); |
Paulo Zanoni | 1011d8c | 2013-05-09 16:55:50 -0300 | [diff] [blame] | 6520 | } |
| 6521 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 6522 | static void ilk_initial_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6523 | struct intel_crtc *crtc) |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6524 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6525 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6526 | const struct intel_crtc_state *crtc_state = |
| 6527 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6528 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6529 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6530 | crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6531 | ilk_program_watermarks(dev_priv); |
| 6532 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6533 | } |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6534 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 6535 | static void ilk_optimize_watermarks(struct intel_atomic_state *state, |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6536 | struct intel_crtc *crtc) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6537 | { |
Ville Syrjälä | 7a8fdb1f | 2019-11-18 18:44:26 +0200 | [diff] [blame] | 6538 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6539 | const struct intel_crtc_state *crtc_state = |
| 6540 | intel_atomic_get_new_crtc_state(state, crtc); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6541 | |
| 6542 | if (!crtc_state->wm.need_postvbl_update) |
| 6543 | return; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6544 | |
| 6545 | mutex_lock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | 88016a9 | 2019-07-01 19:05:45 +0300 | [diff] [blame] | 6546 | crtc->wm.active.ilk = crtc_state->wm.ilk.optimal; |
| 6547 | ilk_program_watermarks(dev_priv); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 6548 | mutex_unlock(&dev_priv->wm.wm_mutex); |
Ville Syrjälä | b9d5c83 | 2015-09-24 15:53:14 -0700 | [diff] [blame] | 6549 | } |
| 6550 | |
Jani Nikula | 81b55ef | 2020-04-20 17:04:38 +0300 | [diff] [blame] | 6551 | 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] | 6552 | { |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6553 | level->enable = val & PLANE_WM_EN; |
Ville Syrjälä | 2ed8e1f | 2019-02-13 18:54:23 +0200 | [diff] [blame] | 6554 | level->ignore_lines = val & PLANE_WM_IGNORE_LINES; |
Ville Syrjälä | 5dac808 | 2021-03-05 17:36:10 +0200 | [diff] [blame] | 6555 | level->blocks = val & PLANE_WM_BLOCKS_MASK; |
Matt Roper | 1003cee | 2021-05-14 08:36:54 -0700 | [diff] [blame] | 6556 | level->lines = REG_FIELD_GET(PLANE_WM_LINES_MASK, val); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6557 | } |
| 6558 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6559 | void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc, |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6560 | struct skl_pipe_wm *out) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6561 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6562 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6563 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6564 | int level, max_level; |
| 6565 | enum plane_id plane_id; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6566 | u32 val; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6567 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6568 | max_level = ilk_wm_max_level(dev_priv); |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6569 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6570 | for_each_plane_id_on_crtc(crtc, plane_id) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6571 | struct skl_plane_wm *wm = &out->planes[plane_id]; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6572 | |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6573 | for (level = 0; level <= max_level; level++) { |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6574 | if (plane_id != PLANE_CURSOR) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6575 | 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] | 6576 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6577 | val = intel_uncore_read(&dev_priv->uncore, CUR_WM(pipe, level)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6578 | |
| 6579 | skl_wm_level_from_reg_val(val, &wm->wm[level]); |
| 6580 | } |
| 6581 | |
Ville Syrjälä | d5cdfdf5 | 2016-11-22 18:01:58 +0200 | [diff] [blame] | 6582 | if (plane_id != PLANE_CURSOR) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6583 | 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] | 6584 | else |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6585 | val = intel_uncore_read(&dev_priv->uncore, CUR_WM_TRANS(pipe)); |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6586 | |
| 6587 | skl_wm_level_from_reg_val(val, &wm->trans_wm); |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6588 | |
Matt Roper | 7959ffe | 2021-05-18 17:06:11 -0700 | [diff] [blame] | 6589 | if (HAS_HW_SAGV_WM(dev_priv)) { |
| 6590 | if (plane_id != PLANE_CURSOR) |
| 6591 | val = intel_uncore_read(&dev_priv->uncore, |
| 6592 | PLANE_WM_SAGV(pipe, plane_id)); |
| 6593 | else |
| 6594 | val = intel_uncore_read(&dev_priv->uncore, |
| 6595 | CUR_WM_SAGV(pipe)); |
| 6596 | |
| 6597 | skl_wm_level_from_reg_val(val, &wm->sagv.wm0); |
| 6598 | |
| 6599 | if (plane_id != PLANE_CURSOR) |
| 6600 | val = intel_uncore_read(&dev_priv->uncore, |
| 6601 | PLANE_WM_SAGV_TRANS(pipe, plane_id)); |
| 6602 | else |
| 6603 | val = intel_uncore_read(&dev_priv->uncore, |
| 6604 | CUR_WM_SAGV_TRANS(pipe)); |
| 6605 | |
| 6606 | skl_wm_level_from_reg_val(val, &wm->sagv.trans_wm); |
| 6607 | } else if (DISPLAY_VER(dev_priv) >= 12) { |
Ville Syrjälä | 5f25e6a | 2021-02-26 17:32:02 +0200 | [diff] [blame] | 6608 | wm->sagv.wm0 = wm->wm[0]; |
| 6609 | wm->sagv.trans_wm = wm->trans_wm; |
| 6610 | } |
cpaul@redhat.com | d8c0faf | 2016-10-18 16:09:49 -0200 | [diff] [blame] | 6611 | } |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6612 | } |
| 6613 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6614 | void skl_wm_get_hw_state(struct drm_i915_private *dev_priv) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6615 | { |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6616 | struct intel_dbuf_state *dbuf_state = |
| 6617 | to_intel_dbuf_state(dev_priv->dbuf.obj.state); |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6618 | struct intel_crtc *crtc; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6619 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6620 | if (IS_ALDERLAKE_P(dev_priv)) |
| 6621 | dbuf_state->joined_mbus = intel_de_read(dev_priv, MBUS_CTL) & MBUS_JOIN; |
| 6622 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6623 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6624 | struct intel_crtc_state *crtc_state = |
| 6625 | to_intel_crtc_state(crtc->base.state); |
| 6626 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 6627 | unsigned int mbus_offset; |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6628 | enum plane_id plane_id; |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6629 | |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6630 | 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] | 6631 | crtc_state->wm.skl.raw = crtc_state->wm.skl.optimal; |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6632 | |
| 6633 | memset(&dbuf_state->ddb[pipe], 0, sizeof(dbuf_state->ddb[pipe])); |
| 6634 | |
| 6635 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6636 | struct skl_ddb_entry *ddb_y = |
| 6637 | &crtc_state->wm.skl.plane_ddb_y[plane_id]; |
| 6638 | struct skl_ddb_entry *ddb_uv = |
| 6639 | &crtc_state->wm.skl.plane_ddb_uv[plane_id]; |
| 6640 | |
| 6641 | skl_ddb_get_hw_plane_state(dev_priv, crtc->pipe, |
| 6642 | plane_id, ddb_y, ddb_uv); |
| 6643 | |
| 6644 | skl_ddb_entry_union(&dbuf_state->ddb[pipe], ddb_y); |
| 6645 | skl_ddb_entry_union(&dbuf_state->ddb[pipe], ddb_uv); |
| 6646 | } |
| 6647 | |
| 6648 | dbuf_state->slices[pipe] = |
| 6649 | skl_compute_dbuf_slices(crtc, dbuf_state->active_pipes); |
| 6650 | |
| 6651 | dbuf_state->weight[pipe] = intel_crtc_ddb_weight(crtc_state); |
| 6652 | |
Ville Syrjälä | 835c176 | 2021-05-18 17:06:16 -0700 | [diff] [blame] | 6653 | /* |
| 6654 | * Used for checking overlaps, so we need absolute |
| 6655 | * offsets instead of MBUS relative offsets. |
| 6656 | */ |
| 6657 | mbus_offset = mbus_ddb_offset(dev_priv, dbuf_state->slices[pipe]); |
| 6658 | crtc_state->wm.skl.ddb.start = mbus_offset + dbuf_state->ddb[pipe].start; |
| 6659 | 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] | 6660 | |
| 6661 | drm_dbg_kms(&dev_priv->drm, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6662 | "[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] | 6663 | crtc->base.base.id, crtc->base.name, |
| 6664 | dbuf_state->slices[pipe], dbuf_state->ddb[pipe].start, |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 6665 | dbuf_state->ddb[pipe].end, dbuf_state->active_pipes, |
| 6666 | yesno(dbuf_state->joined_mbus)); |
cpaul@redhat.com | bf9d99a | 2016-10-14 17:31:55 -0400 | [diff] [blame] | 6667 | } |
Ville Syrjälä | 33c9c50 | 2021-01-22 22:56:33 +0200 | [diff] [blame] | 6668 | |
| 6669 | dbuf_state->enabled_slices = dev_priv->dbuf.enabled_slices; |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 6670 | } |
| 6671 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6672 | 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] | 6673 | { |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6674 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6675 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 6676 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Maarten Lankhorst | ec19364 | 2019-06-28 10:55:17 +0200 | [diff] [blame] | 6677 | struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state); |
| 6678 | struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6679 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6680 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6681 | 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] | 6682 | |
Ville Syrjälä | 1560653 | 2016-05-13 17:55:17 +0300 | [diff] [blame] | 6683 | memset(active, 0, sizeof(*active)); |
| 6684 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6685 | active->pipe_enabled = crtc->active; |
Ville Syrjälä | 2a44b76 | 2014-03-07 18:32:09 +0200 | [diff] [blame] | 6686 | |
| 6687 | if (active->pipe_enabled) { |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6688 | u32 tmp = hw->wm_pipe[pipe]; |
| 6689 | |
| 6690 | /* |
| 6691 | * For active pipes LP0 watermark is marked as |
| 6692 | * enabled, and LP1+ watermaks as disabled since |
| 6693 | * we can't really reverse compute them in case |
| 6694 | * multiple pipes are active. |
| 6695 | */ |
| 6696 | active->wm[0].enable = true; |
| 6697 | active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT; |
| 6698 | active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT; |
| 6699 | active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6700 | } else { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6701 | int level, max_level = ilk_wm_max_level(dev_priv); |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6702 | |
| 6703 | /* |
| 6704 | * For inactive pipes, all watermark levels |
| 6705 | * should be marked as enabled but zeroed, |
| 6706 | * which is what we'd compute them to. |
| 6707 | */ |
| 6708 | for (level = 0; level <= max_level; level++) |
| 6709 | active->wm[level].enable = true; |
| 6710 | } |
Matt Roper | 4e0963c | 2015-09-24 15:53:15 -0700 | [diff] [blame] | 6711 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6712 | crtc->wm.active.ilk = *active; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 6713 | } |
| 6714 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6715 | #define _FW_WM(value, plane) \ |
| 6716 | (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT) |
| 6717 | #define _FW_WM_VLV(value, plane) \ |
| 6718 | (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT) |
| 6719 | |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6720 | static void g4x_read_wm_values(struct drm_i915_private *dev_priv, |
| 6721 | struct g4x_wm_values *wm) |
| 6722 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6723 | u32 tmp; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6724 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6725 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6726 | wm->sr.plane = _FW_WM(tmp, SR); |
| 6727 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 6728 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB); |
| 6729 | wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA); |
| 6730 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6731 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW2); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6732 | wm->fbc_en = tmp & DSPFW_FBC_SR_EN; |
| 6733 | wm->sr.fbc = _FW_WM(tmp, FBC_SR); |
| 6734 | wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR); |
| 6735 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB); |
| 6736 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 6737 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA); |
| 6738 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6739 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6740 | wm->hpll_en = tmp & DSPFW_HPLL_SR_EN; |
| 6741 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 6742 | wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR); |
| 6743 | wm->hpll.plane = _FW_WM(tmp, HPLL_SR); |
| 6744 | } |
| 6745 | |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6746 | static void vlv_read_wm_values(struct drm_i915_private *dev_priv, |
| 6747 | struct vlv_wm_values *wm) |
| 6748 | { |
| 6749 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 6750 | u32 tmp; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6751 | |
| 6752 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6753 | tmp = intel_uncore_read(&dev_priv->uncore, VLV_DDL(pipe)); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6754 | |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6755 | wm->ddl[pipe].plane[PLANE_PRIMARY] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6756 | (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6757 | wm->ddl[pipe].plane[PLANE_CURSOR] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6758 | (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6759 | wm->ddl[pipe].plane[PLANE_SPRITE0] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6760 | (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6761 | wm->ddl[pipe].plane[PLANE_SPRITE1] = |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6762 | (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK); |
| 6763 | } |
| 6764 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6765 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW1); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6766 | wm->sr.plane = _FW_WM(tmp, SR); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6767 | wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB); |
| 6768 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB); |
| 6769 | 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] | 6770 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6771 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW2); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6772 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB); |
| 6773 | wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA); |
| 6774 | 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] | 6775 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6776 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW3); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6777 | wm->sr.cursor = _FW_WM(tmp, CURSOR_SR); |
| 6778 | |
| 6779 | if (IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6780 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW7_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6781 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 6782 | 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] | 6783 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6784 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW8_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6785 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF); |
| 6786 | 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] | 6787 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6788 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW9_CHV); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6789 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC); |
| 6790 | wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6791 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6792 | tmp = intel_uncore_read(&dev_priv->uncore, DSPHOWM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6793 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6794 | wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8; |
| 6795 | wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8; |
| 6796 | wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8; |
| 6797 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 6798 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 6799 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 6800 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 6801 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 6802 | 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] | 6803 | } else { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6804 | tmp = intel_uncore_read(&dev_priv->uncore, DSPFW7); |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6805 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED); |
| 6806 | 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] | 6807 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6808 | tmp = intel_uncore_read(&dev_priv->uncore, DSPHOWM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6809 | wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9; |
Ville Syrjälä | 1b31389 | 2016-11-28 19:37:08 +0200 | [diff] [blame] | 6810 | wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8; |
| 6811 | wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8; |
| 6812 | wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8; |
| 6813 | wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8; |
| 6814 | wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8; |
| 6815 | 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] | 6816 | } |
| 6817 | } |
| 6818 | |
| 6819 | #undef _FW_WM |
| 6820 | #undef _FW_WM_VLV |
| 6821 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6822 | 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] | 6823 | { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6824 | struct g4x_wm_values *wm = &dev_priv->wm.g4x; |
| 6825 | struct intel_crtc *crtc; |
| 6826 | |
| 6827 | g4x_read_wm_values(dev_priv, wm); |
| 6828 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6829 | 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] | 6830 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6831 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6832 | struct intel_crtc_state *crtc_state = |
| 6833 | to_intel_crtc_state(crtc->base.state); |
| 6834 | struct g4x_wm_state *active = &crtc->wm.active.g4x; |
| 6835 | struct g4x_pipe_wm *raw; |
| 6836 | enum pipe pipe = crtc->pipe; |
| 6837 | enum plane_id plane_id; |
| 6838 | int level, max_level; |
| 6839 | |
| 6840 | active->cxsr = wm->cxsr; |
| 6841 | active->hpll_en = wm->hpll_en; |
| 6842 | active->fbc_en = wm->fbc_en; |
| 6843 | |
| 6844 | active->sr = wm->sr; |
| 6845 | active->hpll = wm->hpll; |
| 6846 | |
| 6847 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 6848 | active->wm.plane[plane_id] = |
| 6849 | wm->pipe[pipe].plane[plane_id]; |
| 6850 | } |
| 6851 | |
| 6852 | if (wm->cxsr && wm->hpll_en) |
| 6853 | max_level = G4X_WM_LEVEL_HPLL; |
| 6854 | else if (wm->cxsr) |
| 6855 | max_level = G4X_WM_LEVEL_SR; |
| 6856 | else |
| 6857 | max_level = G4X_WM_LEVEL_NORMAL; |
| 6858 | |
| 6859 | level = G4X_WM_LEVEL_NORMAL; |
| 6860 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6861 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6862 | raw->plane[plane_id] = active->wm.plane[plane_id]; |
| 6863 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame] | 6864 | level = G4X_WM_LEVEL_SR; |
| 6865 | if (level > max_level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6866 | goto out; |
| 6867 | |
| 6868 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6869 | raw->plane[PLANE_PRIMARY] = active->sr.plane; |
| 6870 | raw->plane[PLANE_CURSOR] = active->sr.cursor; |
| 6871 | raw->plane[PLANE_SPRITE0] = 0; |
| 6872 | raw->fbc = active->sr.fbc; |
| 6873 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame] | 6874 | level = G4X_WM_LEVEL_HPLL; |
| 6875 | if (level > max_level) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6876 | goto out; |
| 6877 | |
| 6878 | raw = &crtc_state->wm.g4x.raw[level]; |
| 6879 | raw->plane[PLANE_PRIMARY] = active->hpll.plane; |
| 6880 | raw->plane[PLANE_CURSOR] = active->hpll.cursor; |
| 6881 | raw->plane[PLANE_SPRITE0] = 0; |
| 6882 | raw->fbc = active->hpll.fbc; |
| 6883 | |
Ville Syrjälä | ab98ebb | 2021-05-14 15:57:42 +0300 | [diff] [blame] | 6884 | level++; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6885 | out: |
| 6886 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 6887 | g4x_raw_plane_wm_set(crtc_state, level, |
| 6888 | plane_id, USHRT_MAX); |
| 6889 | g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX); |
| 6890 | |
| 6891 | crtc_state->wm.g4x.optimal = *active; |
| 6892 | crtc_state->wm.g4x.intermediate = *active; |
| 6893 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6894 | drm_dbg_kms(&dev_priv->drm, |
| 6895 | "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n", |
| 6896 | pipe_name(pipe), |
| 6897 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 6898 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 6899 | wm->pipe[pipe].plane[PLANE_SPRITE0]); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6900 | } |
| 6901 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 6902 | drm_dbg_kms(&dev_priv->drm, |
| 6903 | "Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n", |
| 6904 | wm->sr.plane, wm->sr.cursor, wm->sr.fbc); |
| 6905 | drm_dbg_kms(&dev_priv->drm, |
| 6906 | "Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n", |
| 6907 | wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc); |
| 6908 | drm_dbg_kms(&dev_priv->drm, "Initial SR=%s HPLL=%s FBC=%s\n", |
| 6909 | yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en)); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6910 | } |
| 6911 | |
| 6912 | void g4x_wm_sanitize(struct drm_i915_private *dev_priv) |
| 6913 | { |
| 6914 | struct intel_plane *plane; |
| 6915 | struct intel_crtc *crtc; |
| 6916 | |
| 6917 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 6918 | |
| 6919 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 6920 | struct intel_crtc *crtc = |
Jani Nikula | 7794b6d | 2021-12-01 15:57:04 +0200 | [diff] [blame] | 6921 | intel_crtc_for_pipe(dev_priv, plane->pipe); |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6922 | struct intel_crtc_state *crtc_state = |
| 6923 | to_intel_crtc_state(crtc->base.state); |
| 6924 | struct intel_plane_state *plane_state = |
| 6925 | to_intel_plane_state(plane->base.state); |
| 6926 | struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal; |
| 6927 | enum plane_id plane_id = plane->id; |
| 6928 | int level; |
| 6929 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 6930 | if (plane_state->uapi.visible) |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 6931 | continue; |
| 6932 | |
| 6933 | for (level = 0; level < 3; level++) { |
| 6934 | struct g4x_pipe_wm *raw = |
| 6935 | &crtc_state->wm.g4x.raw[level]; |
| 6936 | |
| 6937 | raw->plane[plane_id] = 0; |
| 6938 | wm_state->wm.plane[plane_id] = 0; |
| 6939 | } |
| 6940 | |
| 6941 | if (plane_id == PLANE_PRIMARY) { |
| 6942 | for (level = 0; level < 3; level++) { |
| 6943 | struct g4x_pipe_wm *raw = |
| 6944 | &crtc_state->wm.g4x.raw[level]; |
| 6945 | raw->fbc = 0; |
| 6946 | } |
| 6947 | |
| 6948 | wm_state->sr.fbc = 0; |
| 6949 | wm_state->hpll.fbc = 0; |
| 6950 | wm_state->fbc_en = false; |
| 6951 | } |
| 6952 | } |
| 6953 | |
| 6954 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 6955 | struct intel_crtc_state *crtc_state = |
| 6956 | to_intel_crtc_state(crtc->base.state); |
| 6957 | |
| 6958 | crtc_state->wm.g4x.intermediate = |
| 6959 | crtc_state->wm.g4x.optimal; |
| 6960 | crtc->wm.active.g4x = crtc_state->wm.g4x.optimal; |
| 6961 | } |
| 6962 | |
| 6963 | g4x_program_watermarks(dev_priv); |
| 6964 | |
| 6965 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 6966 | } |
| 6967 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 6968 | 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] | 6969 | { |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6970 | struct vlv_wm_values *wm = &dev_priv->wm.vlv; |
Ville Syrjälä | f07d43d | 2017-03-02 19:14:52 +0200 | [diff] [blame] | 6971 | struct intel_crtc *crtc; |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6972 | u32 val; |
| 6973 | |
| 6974 | vlv_read_wm_values(dev_priv, wm); |
| 6975 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 6976 | 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] | 6977 | wm->level = VLV_WM_LEVEL_PM2; |
| 6978 | |
| 6979 | if (IS_CHERRYVIEW(dev_priv)) { |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 6980 | vlv_punit_get(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6981 | |
Ville Syrjälä | c11b813 | 2018-11-29 19:55:03 +0200 | [diff] [blame] | 6982 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6983 | if (val & DSP_MAXFIFO_PM5_ENABLE) |
| 6984 | wm->level = VLV_WM_LEVEL_PM5; |
| 6985 | |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6986 | /* |
| 6987 | * If DDR DVFS is disabled in the BIOS, Punit |
| 6988 | * will never ack the request. So if that happens |
| 6989 | * assume we don't have to enable/disable DDR DVFS |
| 6990 | * dynamically. To test that just set the REQ_ACK |
| 6991 | * bit to poke the Punit, but don't change the |
| 6992 | * HIGH/LOW bits so that we don't actually change |
| 6993 | * the current state. |
| 6994 | */ |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 6995 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 6996 | val |= FORCE_DDR_FREQ_REQ_ACK; |
| 6997 | vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val); |
| 6998 | |
| 6999 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) & |
| 7000 | FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7001 | drm_dbg_kms(&dev_priv->drm, |
| 7002 | "Punit not acking DDR DVFS request, " |
| 7003 | "assuming DDR DVFS is disabled\n"); |
Ville Syrjälä | 58590c1 | 2015-09-08 21:05:12 +0300 | [diff] [blame] | 7004 | dev_priv->wm.max_level = VLV_WM_LEVEL_PM5; |
| 7005 | } else { |
| 7006 | val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2); |
| 7007 | if ((val & FORCE_DDR_HIGH_FREQ) == 0) |
| 7008 | wm->level = VLV_WM_LEVEL_DDR_DVFS; |
| 7009 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 7010 | |
Chris Wilson | 337fa6e | 2019-04-26 09:17:20 +0100 | [diff] [blame] | 7011 | vlv_punit_put(dev_priv); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 7012 | } |
| 7013 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7014 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7015 | struct intel_crtc_state *crtc_state = |
| 7016 | to_intel_crtc_state(crtc->base.state); |
| 7017 | struct vlv_wm_state *active = &crtc->wm.active.vlv; |
| 7018 | const struct vlv_fifo_state *fifo_state = |
| 7019 | &crtc_state->wm.vlv.fifo_state; |
| 7020 | enum pipe pipe = crtc->pipe; |
| 7021 | enum plane_id plane_id; |
| 7022 | int level; |
| 7023 | |
| 7024 | vlv_get_fifo_size(crtc_state); |
| 7025 | |
| 7026 | active->num_levels = wm->level + 1; |
| 7027 | active->cxsr = wm->cxsr; |
| 7028 | |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7029 | for (level = 0; level < active->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 7030 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7031 | &crtc_state->wm.vlv.raw[level]; |
| 7032 | |
| 7033 | active->sr[level].plane = wm->sr.plane; |
| 7034 | active->sr[level].cursor = wm->sr.cursor; |
| 7035 | |
| 7036 | for_each_plane_id_on_crtc(crtc, plane_id) { |
| 7037 | active->wm[level].plane[plane_id] = |
| 7038 | wm->pipe[pipe].plane[plane_id]; |
| 7039 | |
| 7040 | raw->plane[plane_id] = |
| 7041 | vlv_invert_wm_value(active->wm[level].plane[plane_id], |
| 7042 | fifo_state->plane[plane_id]); |
| 7043 | } |
| 7044 | } |
| 7045 | |
| 7046 | for_each_plane_id_on_crtc(crtc, plane_id) |
| 7047 | vlv_raw_plane_wm_set(crtc_state, level, |
| 7048 | plane_id, USHRT_MAX); |
| 7049 | vlv_invalidate_wms(crtc, active, level); |
| 7050 | |
| 7051 | crtc_state->wm.vlv.optimal = *active; |
Ville Syrjälä | 4841da5 | 2017-03-02 19:14:59 +0200 | [diff] [blame] | 7052 | crtc_state->wm.vlv.intermediate = *active; |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7053 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7054 | drm_dbg_kms(&dev_priv->drm, |
| 7055 | "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n", |
| 7056 | pipe_name(pipe), |
| 7057 | wm->pipe[pipe].plane[PLANE_PRIMARY], |
| 7058 | wm->pipe[pipe].plane[PLANE_CURSOR], |
| 7059 | wm->pipe[pipe].plane[PLANE_SPRITE0], |
| 7060 | wm->pipe[pipe].plane[PLANE_SPRITE1]); |
Ville Syrjälä | ff32c54 | 2017-03-02 19:14:57 +0200 | [diff] [blame] | 7061 | } |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 7062 | |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7063 | drm_dbg_kms(&dev_priv->drm, |
| 7064 | "Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n", |
| 7065 | wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr); |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 7066 | } |
| 7067 | |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7068 | void vlv_wm_sanitize(struct drm_i915_private *dev_priv) |
| 7069 | { |
| 7070 | struct intel_plane *plane; |
| 7071 | struct intel_crtc *crtc; |
| 7072 | |
| 7073 | mutex_lock(&dev_priv->wm.wm_mutex); |
| 7074 | |
| 7075 | for_each_intel_plane(&dev_priv->drm, plane) { |
| 7076 | struct intel_crtc *crtc = |
Jani Nikula | 7794b6d | 2021-12-01 15:57:04 +0200 | [diff] [blame] | 7077 | intel_crtc_for_pipe(dev_priv, plane->pipe); |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7078 | struct intel_crtc_state *crtc_state = |
| 7079 | to_intel_crtc_state(crtc->base.state); |
| 7080 | struct intel_plane_state *plane_state = |
| 7081 | to_intel_plane_state(plane->base.state); |
| 7082 | struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal; |
| 7083 | const struct vlv_fifo_state *fifo_state = |
| 7084 | &crtc_state->wm.vlv.fifo_state; |
| 7085 | enum plane_id plane_id = plane->id; |
| 7086 | int level; |
| 7087 | |
Maarten Lankhorst | f90a85e | 2019-10-31 12:26:08 +0100 | [diff] [blame] | 7088 | if (plane_state->uapi.visible) |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7089 | continue; |
| 7090 | |
| 7091 | for (level = 0; level < wm_state->num_levels; level++) { |
Ville Syrjälä | 114d7dc | 2017-04-21 21:14:21 +0300 | [diff] [blame] | 7092 | struct g4x_pipe_wm *raw = |
Ville Syrjälä | 602ae83 | 2017-03-02 19:15:02 +0200 | [diff] [blame] | 7093 | &crtc_state->wm.vlv.raw[level]; |
| 7094 | |
| 7095 | raw->plane[plane_id] = 0; |
| 7096 | |
| 7097 | wm_state->wm[level].plane[plane_id] = |
| 7098 | vlv_invert_wm_value(raw->plane[plane_id], |
| 7099 | fifo_state->plane[plane_id]); |
| 7100 | } |
| 7101 | } |
| 7102 | |
| 7103 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
| 7104 | struct intel_crtc_state *crtc_state = |
| 7105 | to_intel_crtc_state(crtc->base.state); |
| 7106 | |
| 7107 | crtc_state->wm.vlv.intermediate = |
| 7108 | crtc_state->wm.vlv.optimal; |
| 7109 | crtc->wm.active.vlv = crtc_state->wm.vlv.optimal; |
| 7110 | } |
| 7111 | |
| 7112 | vlv_program_watermarks(dev_priv); |
| 7113 | |
| 7114 | mutex_unlock(&dev_priv->wm.wm_mutex); |
| 7115 | } |
| 7116 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 7117 | /* |
| 7118 | * FIXME should probably kill this and improve |
| 7119 | * the real watermark readout/sanitation instead |
| 7120 | */ |
| 7121 | static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv) |
| 7122 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7123 | intel_uncore_write(&dev_priv->uncore, WM3_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM3_LP_ILK) & ~WM1_LP_SR_EN); |
| 7124 | intel_uncore_write(&dev_priv->uncore, WM2_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM2_LP_ILK) & ~WM1_LP_SR_EN); |
| 7125 | 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] | 7126 | |
| 7127 | /* |
| 7128 | * Don't touch WM1S_LP_EN here. |
| 7129 | * Doing so could cause underruns. |
| 7130 | */ |
| 7131 | } |
| 7132 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7133 | 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] | 7134 | { |
Imre Deak | 820c198 | 2013-12-17 14:46:36 +0200 | [diff] [blame] | 7135 | struct ilk_wm_values *hw = &dev_priv->wm.hw; |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7136 | struct intel_crtc *crtc; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7137 | |
Ville Syrjälä | f72b84c | 2017-11-08 15:35:55 +0200 | [diff] [blame] | 7138 | ilk_init_lp_watermarks(dev_priv); |
| 7139 | |
Matt Roper | cd1d3ee | 2018-12-10 13:54:14 -0800 | [diff] [blame] | 7140 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7141 | ilk_pipe_wm_get_hw_state(crtc); |
| 7142 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7143 | hw->wm_lp[0] = intel_uncore_read(&dev_priv->uncore, WM1_LP_ILK); |
| 7144 | hw->wm_lp[1] = intel_uncore_read(&dev_priv->uncore, WM2_LP_ILK); |
| 7145 | 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] | 7146 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7147 | 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] | 7148 | if (DISPLAY_VER(dev_priv) >= 7) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7149 | hw->wm_lp_spr[1] = intel_uncore_read(&dev_priv->uncore, WM2S_LP_IVB); |
| 7150 | 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] | 7151 | } |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7152 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 7153 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7154 | 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] | 7155 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 7156 | else if (IS_IVYBRIDGE(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7157 | 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] | 7158 | INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2; |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 7159 | |
| 7160 | hw->enable_fbc_wm = |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7161 | !(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] | 7162 | } |
| 7163 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7164 | void intel_enable_ipc(struct drm_i915_private *dev_priv) |
| 7165 | { |
| 7166 | u32 val; |
| 7167 | |
José Roberto de Souza | fd847b8 | 2018-09-18 13:47:11 -0700 | [diff] [blame] | 7168 | if (!HAS_IPC(dev_priv)) |
| 7169 | return; |
| 7170 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7171 | val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2); |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7172 | |
| 7173 | if (dev_priv->ipc_enabled) |
| 7174 | val |= DISP_IPC_ENABLE; |
| 7175 | else |
| 7176 | val &= ~DISP_IPC_ENABLE; |
| 7177 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7178 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL2, val); |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7179 | } |
| 7180 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7181 | static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv) |
| 7182 | { |
| 7183 | /* Display WA #0477 WaDisableIPC: skl */ |
| 7184 | if (IS_SKYLAKE(dev_priv)) |
| 7185 | return false; |
| 7186 | |
| 7187 | /* Display WA #1141: SKL:all KBL:all CFL */ |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 7188 | if (IS_KABYLAKE(dev_priv) || |
| 7189 | IS_COFFEELAKE(dev_priv) || |
| 7190 | IS_COMETLAKE(dev_priv)) |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7191 | return dev_priv->dram_info.symmetric_memory; |
| 7192 | |
| 7193 | return true; |
| 7194 | } |
| 7195 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7196 | void intel_init_ipc(struct drm_i915_private *dev_priv) |
| 7197 | { |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7198 | if (!HAS_IPC(dev_priv)) |
| 7199 | return; |
| 7200 | |
Ville Syrjälä | c91a45f | 2019-05-03 20:38:07 +0300 | [diff] [blame] | 7201 | dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv); |
José Roberto de Souza | c9b818d | 2018-09-18 13:47:13 -0700 | [diff] [blame] | 7202 | |
Kumar, Mahesh | 2503a0f | 2017-08-17 19:15:28 +0530 | [diff] [blame] | 7203 | intel_enable_ipc(dev_priv); |
| 7204 | } |
| 7205 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7206 | static void ibx_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7207 | { |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7208 | /* |
| 7209 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7210 | * gating for the panel power sequencer or it will fail to |
| 7211 | * start up when no ports are active. |
| 7212 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7213 | 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] | 7214 | } |
| 7215 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7216 | 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] | 7217 | { |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7218 | enum pipe pipe; |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7219 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7220 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7221 | intel_uncore_write(&dev_priv->uncore, DSPCNTR(pipe), |
| 7222 | intel_uncore_read(&dev_priv->uncore, DSPCNTR(pipe)) | |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7223 | DISPPLANE_TRICKLE_FEED_DISABLE); |
Ville Syrjälä | b12ce1d | 2015-05-26 20:27:23 +0300 | [diff] [blame] | 7224 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7225 | intel_uncore_write(&dev_priv->uncore, DSPSURF(pipe), intel_uncore_read(&dev_priv->uncore, DSPSURF(pipe))); |
| 7226 | intel_uncore_posting_read(&dev_priv->uncore, DSPSURF(pipe)); |
Ville Syrjälä | 0e088b8 | 2013-06-07 10:47:04 +0300 | [diff] [blame] | 7227 | } |
| 7228 | } |
| 7229 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7230 | static void ilk_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7231 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7232 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7233 | |
Damien Lespiau | f1e8fa5 | 2013-06-07 17:41:09 +0100 | [diff] [blame] | 7234 | /* |
| 7235 | * Required for FBC |
| 7236 | * WaFbcDisableDpfcClockGating:ilk |
| 7237 | */ |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7238 | dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE | |
| 7239 | ILK_DPFCUNIT_CLOCK_GATE_DISABLE | |
| 7240 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7241 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7242 | intel_uncore_write(&dev_priv->uncore, PCH_3DCGDIS0, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7243 | MARIUNIT_CLOCK_GATE_DISABLE | |
| 7244 | SVSMUNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7245 | intel_uncore_write(&dev_priv->uncore, PCH_3DCGDIS1, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7246 | VFMUNIT_CLOCK_GATE_DISABLE); |
| 7247 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7248 | /* |
| 7249 | * According to the spec the following bits should be set in |
| 7250 | * order to enable memory self-refresh |
| 7251 | * The bit 22/21 of 0x42004 |
| 7252 | * The bit 5 of 0x42020 |
| 7253 | * The bit 15 of 0x45000 |
| 7254 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7255 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7256 | (intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7257 | ILK_DPARB_GATE | ILK_VSDPFD_FULL)); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7258 | dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7259 | intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, |
| 7260 | (intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7261 | DISP_FBC_WM_DIS)); |
Ville Syrjälä | 017636c | 2013-12-05 15:51:37 +0200 | [diff] [blame] | 7262 | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7263 | /* |
| 7264 | * Based on the document from hardware guys the following bits |
| 7265 | * should be set unconditionally in order to enable FBC. |
| 7266 | * The bit 22 of 0x42000 |
| 7267 | * The bit 22 of 0x42004 |
| 7268 | * The bit 7,8,9 of 0x42020. |
| 7269 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7270 | if (IS_IRONLAKE_M(dev_priv)) { |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7271 | /* WaFbcAsynchFlipDisableFbcQueue:ilk */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7272 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7273 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7274 | ILK_FBCQ_DIS); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7275 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7276 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7277 | ILK_DPARB_GATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7278 | } |
| 7279 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7280 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, dspclk_gate); |
Damien Lespiau | 4d47e4f | 2012-10-19 17:55:42 +0100 | [diff] [blame] | 7281 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7282 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7283 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7284 | ILK_ELPIN_409_SELECT); |
Akash Goel | 4e04632 | 2014-04-04 17:14:38 +0530 | [diff] [blame] | 7285 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7286 | g4x_disable_trickle_feed(dev_priv); |
Ville Syrjälä | bdad2b2 | 2013-06-07 10:47:03 +0300 | [diff] [blame] | 7287 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7288 | ibx_init_clock_gating(dev_priv); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7289 | } |
| 7290 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7291 | static void cpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7292 | { |
Ville Syrjälä | d048a26 | 2019-08-21 20:30:31 +0300 | [diff] [blame] | 7293 | enum pipe pipe; |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7294 | u32 val; |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7295 | |
| 7296 | /* |
| 7297 | * On Ibex Peak and Cougar Point, we need to disable clock |
| 7298 | * gating for the panel power sequencer or it will fail to |
| 7299 | * start up when no ports are active. |
| 7300 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7301 | 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] | 7302 | PCH_DPLUNIT_CLOCK_GATE_DISABLE | |
| 7303 | PCH_CPUNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7304 | 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] | 7305 | DPLS_EDP_PPS_FIX_DIS); |
Takashi Iwai | 335c07b | 2012-12-11 11:46:29 +0100 | [diff] [blame] | 7306 | /* The below fixes the weird display corruption, a few pixels shifted |
| 7307 | * downward, on (only) LVDS of some HP laptops with IVY. |
| 7308 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7309 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7310 | val = intel_uncore_read(&dev_priv->uncore, TRANS_CHICKEN2(pipe)); |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7311 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 7312 | val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7313 | if (dev_priv->vbt.fdi_rx_polarity_inverted) |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7314 | val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED; |
Paulo Zanoni | dc4bd2d | 2013-04-08 15:48:08 -0300 | [diff] [blame] | 7315 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER; |
| 7316 | val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7317 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN2(pipe), val); |
Paulo Zanoni | 3f704fa | 2013-04-08 15:48:07 -0300 | [diff] [blame] | 7318 | } |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7319 | /* WADP0ClockGatingDisable */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7320 | for_each_pipe(dev_priv, pipe) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7321 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN1(pipe), |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7322 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
| 7323 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7324 | } |
| 7325 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7326 | static void gen6_check_mch_setup(struct drm_i915_private *dev_priv) |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7327 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7328 | u32 tmp; |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7329 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7330 | tmp = intel_uncore_read(&dev_priv->uncore, MCH_SSKPD); |
Daniel Vetter | df662a2 | 2014-08-04 11:17:25 +0200 | [diff] [blame] | 7331 | if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL) |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7332 | drm_dbg_kms(&dev_priv->drm, |
| 7333 | "Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n", |
| 7334 | tmp); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7335 | } |
| 7336 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7337 | static void gen6_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7338 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7339 | u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7340 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7341 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, dspclk_gate); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7342 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7343 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7344 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7345 | ILK_ELPIN_409_SELECT); |
| 7346 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7347 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, |
| 7348 | intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7349 | GEN6_BLBUNIT_CLOCK_GATE_DISABLE | |
| 7350 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
| 7351 | |
| 7352 | /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock |
| 7353 | * gating disable must be set. Failure to set it results in |
| 7354 | * flickering pixels due to Z write ordering failures after |
| 7355 | * some amount of runtime in the Mesa "fire" demo, and Unigine |
| 7356 | * Sanctuary and Tropics, and apparently anything else with |
| 7357 | * alpha test or pixel discard. |
| 7358 | * |
| 7359 | * According to the spec, bit 11 (RCCUNIT) must also be set, |
| 7360 | * but we didn't debug actual testcases to find it out. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7361 | * |
Ville Syrjälä | ef59318 | 2014-01-22 21:32:47 +0200 | [diff] [blame] | 7362 | * WaDisableRCCUnitClockGating:snb |
| 7363 | * WaDisableRCPBUnitClockGating:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7364 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7365 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7366 | GEN6_RCPBUNIT_CLOCK_GATE_DISABLE | |
| 7367 | GEN6_RCCUNIT_CLOCK_GATE_DISABLE); |
| 7368 | |
Ville Syrjälä | e927ecd | 2014-02-04 21:59:18 +0200 | [diff] [blame] | 7369 | /* |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7370 | * According to the spec the following bits should be |
| 7371 | * set in order to enable memory self-refresh and fbc: |
| 7372 | * The bit21 and bit22 of 0x42000 |
| 7373 | * The bit21 and bit22 of 0x42004 |
| 7374 | * The bit5 and bit7 of 0x42020 |
| 7375 | * The bit14 of 0x70180 |
| 7376 | * The bit14 of 0x71180 |
Damien Lespiau | 4bb3533 | 2013-06-14 15:23:24 +0100 | [diff] [blame] | 7377 | * |
| 7378 | * WaFbcAsynchFlipDisableFbcQueue:snb |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7379 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7380 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7381 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7382 | ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7383 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2, |
| 7384 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7385 | ILK_DPARB_GATE | ILK_VSDPFD_FULL); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7386 | intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, |
| 7387 | intel_uncore_read(&dev_priv->uncore, ILK_DSPCLK_GATE_D) | |
Damien Lespiau | 231e54f | 2012-10-19 17:55:41 +0100 | [diff] [blame] | 7388 | ILK_DPARBUNIT_CLOCK_GATE_ENABLE | |
| 7389 | ILK_DPFDUNIT_CLOCK_GATE_ENABLE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7390 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7391 | g4x_disable_trickle_feed(dev_priv); |
Ben Widawsky | f8f2ac9 | 2012-10-03 19:34:24 -0700 | [diff] [blame] | 7392 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7393 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7394 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7395 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7396 | } |
| 7397 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7398 | static void lpt_init_clock_gating(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7399 | { |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7400 | /* |
| 7401 | * TODO: this bit should only be enabled when really needed, then |
| 7402 | * disabled when not needed anymore in order to save power. |
| 7403 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7404 | if (HAS_PCH_LPT_LP(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7405 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, |
| 7406 | intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D) | |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7407 | PCH_LP_PARTITION_LEVEL_DISABLE); |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7408 | |
| 7409 | /* WADPOClockGatingDisable:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7410 | intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN1(PIPE_A), |
| 7411 | intel_uncore_read(&dev_priv->uncore, TRANS_CHICKEN1(PIPE_A)) | |
Paulo Zanoni | 0a790cd | 2013-04-17 18:15:49 -0300 | [diff] [blame] | 7412 | TRANS_CHICKEN1_DP0UNIT_GC_DISABLE); |
Paulo Zanoni | 17a303e | 2012-11-20 15:12:07 -0200 | [diff] [blame] | 7413 | } |
| 7414 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7415 | static void lpt_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7416 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 7417 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7418 | u32 val = intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7419 | |
| 7420 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7421 | intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, val); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7422 | } |
| 7423 | } |
| 7424 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7425 | static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv, |
| 7426 | int general_prio_credits, |
| 7427 | int high_prio_credits) |
| 7428 | { |
| 7429 | u32 misccpctl; |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 7430 | u32 val; |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7431 | |
| 7432 | /* WaTempDisableDOPClkGating:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7433 | misccpctl = intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL); |
| 7434 | 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] | 7435 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7436 | val = intel_uncore_read(&dev_priv->uncore, GEN8_L3SQCREG1); |
Oscar Mateo | 930a784 | 2017-10-17 13:25:45 -0700 | [diff] [blame] | 7437 | val &= ~L3_PRIO_CREDITS_MASK; |
| 7438 | val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits); |
| 7439 | val |= L3_HIGH_PRIO_CREDITS(high_prio_credits); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7440 | intel_uncore_write(&dev_priv->uncore, GEN8_L3SQCREG1, val); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7441 | |
| 7442 | /* |
| 7443 | * Wait at least 100 clocks before re-enabling clock gating. |
| 7444 | * See the definition of L3SQCREG1 in BSpec. |
| 7445 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7446 | intel_uncore_posting_read(&dev_priv->uncore, GEN8_L3SQCREG1); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7447 | udelay(1); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7448 | intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl); |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7449 | } |
| 7450 | |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7451 | static void icl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7452 | { |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7453 | /* Wa_1409120013:icl,ehl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7454 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, |
Ville Syrjälä | 73ab6ec | 2021-11-04 16:45:15 +0200 | [diff] [blame] | 7455 | DPFC_CHICKEN_COMP_DUMMY_PIXEL); |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7456 | |
Matt Atwood | 6f4194c | 2020-01-13 23:11:28 -0500 | [diff] [blame] | 7457 | /*Wa_14010594013:icl, ehl */ |
| 7458 | intel_uncore_rmw(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1, |
Lucas De Marchi | dbac4f3 | 2021-07-28 14:59:38 -0700 | [diff] [blame] | 7459 | 0, ICL_DELAY_PMRSP); |
Oscar Mateo | d65dc3e | 2018-05-08 14:29:24 -0700 | [diff] [blame] | 7460 | } |
| 7461 | |
José Roberto de Souza | 35f0837 | 2021-01-13 05:37:59 -0800 | [diff] [blame] | 7462 | static void gen12lp_init_clock_gating(struct drm_i915_private *dev_priv) |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7463 | { |
Matt Atwood | 487970e | 2021-11-16 09:48:18 -0800 | [diff] [blame] | 7464 | /* Wa_1409120013:tgl,rkl,adl-s,dg1,dg2 */ |
Clint Taylor | 8c209f4 | 2021-06-08 10:47:21 -0700 | [diff] [blame] | 7465 | if (IS_TIGERLAKE(dev_priv) || IS_ROCKETLAKE(dev_priv) || |
Matt Atwood | 487970e | 2021-11-16 09:48:18 -0800 | [diff] [blame] | 7466 | IS_ALDERLAKE_S(dev_priv) || IS_DG1(dev_priv) || IS_DG2(dev_priv)) |
Clint Taylor | 8c209f4 | 2021-06-08 10:47:21 -0700 | [diff] [blame] | 7467 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, |
Ville Syrjälä | 73ab6ec | 2021-11-04 16:45:15 +0200 | [diff] [blame] | 7468 | DPFC_CHICKEN_COMP_DUMMY_PIXEL); |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7469 | |
Radhakrishna Sripada | f78d5da | 2020-01-09 14:37:27 -0800 | [diff] [blame] | 7470 | /* Wa_1409825376:tgl (pre-prod)*/ |
Matt Roper | 46b0d70 | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7471 | if (IS_TGL_DISPLAY_STEP(dev_priv, STEP_A0, STEP_C0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7472 | 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] | 7473 | TGL_VRH_GATING_DIS); |
Matt Atwood | f9d7742 | 2020-04-15 15:35:35 -0400 | [diff] [blame] | 7474 | |
José Roberto de Souza | 41c70d2 | 2021-04-08 13:49:16 -0700 | [diff] [blame] | 7475 | /* Wa_14013723622:tgl,rkl,dg1,adl-s */ |
| 7476 | if (DISPLAY_VER(dev_priv) == 12) |
| 7477 | intel_uncore_rmw(&dev_priv->uncore, CLKREQ_POLICY, |
| 7478 | CLKREQ_POLICY_MEM_UP_OVRD, 0); |
Michel Thierry | 5d86923 | 2019-08-23 01:20:34 -0700 | [diff] [blame] | 7479 | } |
| 7480 | |
José Roberto de Souza | a8a56da | 2021-05-14 08:37:09 -0700 | [diff] [blame] | 7481 | static void adlp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7482 | { |
| 7483 | gen12lp_init_clock_gating(dev_priv); |
| 7484 | |
| 7485 | /* Wa_22011091694:adlp */ |
| 7486 | intel_de_rmw(dev_priv, GEN9_CLKGATE_DIS_5, 0, DPCE_GATING_DIS); |
| 7487 | } |
| 7488 | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7489 | static void dg1_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7490 | { |
José Roberto de Souza | 35f0837 | 2021-01-13 05:37:59 -0800 | [diff] [blame] | 7491 | gen12lp_init_clock_gating(dev_priv); |
| 7492 | |
Stuart Summers | da942750 | 2020-10-14 12:19:34 -0700 | [diff] [blame] | 7493 | /* Wa_1409836686:dg1[a0] */ |
Matt Roper | 6b73a7f | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7494 | if (IS_DG1_GT_STEP(dev_priv, STEP_A0, STEP_B0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7495 | 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] | 7496 | DPT_GATING_DIS); |
| 7497 | } |
| 7498 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7499 | static void cnp_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7500 | { |
| 7501 | if (!HAS_PCH_CNP(dev_priv)) |
| 7502 | return; |
| 7503 | |
Rodrigo Vivi | 470e7c6 | 2018-03-05 17:28:12 -0800 | [diff] [blame] | 7504 | /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7505 | 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] | 7506 | CNP_PWM_CGE_GATING_DISABLE); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7507 | } |
| 7508 | |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7509 | static void cfl_init_clock_gating(struct drm_i915_private *dev_priv) |
| 7510 | { |
| 7511 | cnp_init_clock_gating(dev_priv); |
| 7512 | gen9_init_clock_gating(dev_priv); |
| 7513 | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7514 | /* WAC6entrylatency:cfl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7515 | 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] | 7516 | FBC_LLC_FULLY_OPEN); |
| 7517 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7518 | /* |
| 7519 | * WaFbcTurnOffFbcWatermark:cfl |
| 7520 | * Display WA #0562: cfl |
| 7521 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7522 | 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] | 7523 | DISP_FBC_WM_DIS); |
| 7524 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7525 | /* |
| 7526 | * WaFbcNukeOnHostModify:cfl |
| 7527 | * Display WA #0873: cfl |
| 7528 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7529 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Ville Syrjälä | 73ab6ec | 2021-11-04 16:45:15 +0200 | [diff] [blame] | 7530 | DPFC_NUKE_ON_ANY_MODIFICATION); |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7531 | } |
| 7532 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7533 | static void kbl_init_clock_gating(struct drm_i915_private *dev_priv) |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7534 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7535 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7536 | |
Ville Syrjälä | 4d6bde58 | 2020-07-16 22:04:26 +0300 | [diff] [blame] | 7537 | /* WAC6entrylatency:kbl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7538 | 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] | 7539 | FBC_LLC_FULLY_OPEN); |
| 7540 | |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7541 | /* WaDisableSDEUnitClockGating:kbl */ |
Matt Roper | 6b73a7f | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7542 | if (IS_KBL_GT_STEP(dev_priv, 0, STEP_C0)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7543 | 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] | 7544 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 7545 | |
| 7546 | /* WaDisableGamClockGating:kbl */ |
Matt Roper | 6b73a7f | 2021-07-16 22:14:26 -0700 | [diff] [blame] | 7547 | if (IS_KBL_GT_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, GEN6_UCGCTL1, intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) | |
Mika Kuoppala | 8aeb7f6 | 2016-06-07 17:19:05 +0300 | [diff] [blame] | 7549 | GEN6_GAMUNIT_CLOCK_GATE_DISABLE); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7550 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7551 | /* |
| 7552 | * WaFbcTurnOffFbcWatermark:kbl |
| 7553 | * Display WA #0562: kbl |
| 7554 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7555 | 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] | 7556 | DISP_FBC_WM_DIS); |
| 7557 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7558 | /* |
| 7559 | * WaFbcNukeOnHostModify:kbl |
| 7560 | * Display WA #0873: kbl |
| 7561 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7562 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Ville Syrjälä | 73ab6ec | 2021-11-04 16:45:15 +0200 | [diff] [blame] | 7563 | DPFC_NUKE_ON_ANY_MODIFICATION); |
Mika Kuoppala | 9498dba | 2016-06-07 17:19:01 +0300 | [diff] [blame] | 7564 | } |
| 7565 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7566 | static void skl_init_clock_gating(struct drm_i915_private *dev_priv) |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7567 | { |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7568 | gen9_init_clock_gating(dev_priv); |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7569 | |
Ville Syrjälä | f142119 | 2020-07-16 22:04:25 +0300 | [diff] [blame] | 7570 | /* WaDisableDopClockGating:skl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7571 | 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] | 7572 | ~GEN7_DOP_CLOCK_GATE_ENABLE); |
| 7573 | |
Mika Kuoppala | 44fff99 | 2016-06-07 17:19:09 +0300 | [diff] [blame] | 7574 | /* WAC6entrylatency:skl */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7575 | 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] | 7576 | FBC_LLC_FULLY_OPEN); |
Mika Kuoppala | 031cd8c | 2016-06-07 17:19:18 +0300 | [diff] [blame] | 7577 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7578 | /* |
| 7579 | * WaFbcTurnOffFbcWatermark:skl |
| 7580 | * Display WA #0562: skl |
| 7581 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7582 | 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] | 7583 | DISP_FBC_WM_DIS); |
| 7584 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7585 | /* |
| 7586 | * WaFbcNukeOnHostModify:skl |
| 7587 | * Display WA #0873: skl |
| 7588 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7589 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Ville Syrjälä | 73ab6ec | 2021-11-04 16:45:15 +0200 | [diff] [blame] | 7590 | DPFC_NUKE_ON_ANY_MODIFICATION); |
Ville Syrjälä | cd7a881 | 2020-07-08 16:12:22 +0300 | [diff] [blame] | 7591 | |
Ville Syrjälä | 99bcf64e | 2020-07-08 16:12:23 +0300 | [diff] [blame] | 7592 | /* |
| 7593 | * WaFbcHighMemBwCorruptionAvoidance:skl |
| 7594 | * Display WA #0883: skl |
| 7595 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7596 | intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN, intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN) | |
Ville Syrjälä | 73ab6ec | 2021-11-04 16:45:15 +0200 | [diff] [blame] | 7597 | DPFC_DISABLE_DUMMY0); |
Daniel Vetter | dc00b6a | 2016-05-19 09:14:20 +0200 | [diff] [blame] | 7598 | } |
| 7599 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7600 | static void bdw_init_clock_gating(struct drm_i915_private *dev_priv) |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7601 | { |
Damien Lespiau | 07d27e2 | 2014-03-03 17:31:46 +0000 | [diff] [blame] | 7602 | enum pipe pipe; |
Ben Widawsky | 1020a5c | 2013-11-02 21:07:06 -0700 | [diff] [blame] | 7603 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7604 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7605 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A), |
| 7606 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A)) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7607 | HSW_FBCQ_DIS); |
| 7608 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7609 | /* WaSwitchSolVfFArbitrationPriority:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7610 | 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] | 7611 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7612 | /* WaPsrDPAMaskVBlankInSRD:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7613 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1, |
| 7614 | 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] | 7615 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 7616 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | b7a7053 | 2021-02-20 12:33:03 +0200 | [diff] [blame] | 7617 | /* WaPsrDPRSUnmaskVBlankInSRD:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7618 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe), |
| 7619 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe)) | |
Ville Syrjälä | 8f670bb | 2014-03-05 13:05:47 +0200 | [diff] [blame] | 7620 | BDW_DPRS_MASK_VBLANK_SRD); |
Ben Widawsky | fe4ab3c | 2013-11-02 21:07:54 -0700 | [diff] [blame] | 7621 | } |
Ben Widawsky | 63801f2 | 2013-12-12 17:26:03 -0800 | [diff] [blame] | 7622 | |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7623 | /* WaVSRefCountFullforceMissDisable:bdw */ |
| 7624 | /* WaDSRefCountFullforceMissDisable:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7625 | intel_uncore_write(&dev_priv->uncore, GEN7_FF_THREAD_MODE, |
| 7626 | intel_uncore_read(&dev_priv->uncore, GEN7_FF_THREAD_MODE) & |
Ben Widawsky | ab57fff | 2013-12-12 15:28:04 -0800 | [diff] [blame] | 7627 | ~(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] | 7628 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7629 | intel_uncore_write(&dev_priv->uncore, GEN6_RC_SLEEP_PSMI_CONTROL, |
Ville Syrjälä | 295e8bb | 2014-02-27 21:59:01 +0200 | [diff] [blame] | 7630 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 4f1ca9e | 2014-02-27 21:59:02 +0200 | [diff] [blame] | 7631 | |
| 7632 | /* WaDisableSDEUnitClockGating:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7633 | 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] | 7634 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Damien Lespiau | 5d70868 | 2014-03-26 18:41:51 +0000 | [diff] [blame] | 7635 | |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7636 | /* WaProgramL3SqcReg1Default:bdw */ |
| 7637 | gen8_set_l3sqc_credits(dev_priv, 30, 2); |
Ville Syrjälä | 4d487cf | 2015-05-19 20:32:56 +0300 | [diff] [blame] | 7638 | |
Mika Kuoppala | 17e0adf | 2016-06-07 17:19:02 +0300 | [diff] [blame] | 7639 | /* WaKVMNotificationOnConfigChange:bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7640 | 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] | 7641 | | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT); |
| 7642 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7643 | lpt_init_clock_gating(dev_priv); |
Robert Bragg | 9cc1973 | 2017-02-12 13:32:52 +0000 | [diff] [blame] | 7644 | |
| 7645 | /* WaDisableDopClockGating:bdw |
| 7646 | * |
| 7647 | * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP |
| 7648 | * clock gating. |
| 7649 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7650 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, |
| 7651 | 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] | 7652 | } |
| 7653 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7654 | static void hsw_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7655 | { |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7656 | /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7657 | intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A), |
| 7658 | intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A)) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7659 | HSW_FBCQ_DIS); |
| 7660 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7661 | /* This is required by WaCatErrorRejectionIssue:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7662 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7663 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Chris Wilson | f93ec5f | 2020-06-11 10:30:15 +0100 | [diff] [blame] | 7664 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
Kenneth Graunke | 9441159 | 2014-12-31 16:23:00 -0800 | [diff] [blame] | 7665 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7666 | /* WaSwitchSolVfFArbitrationPriority:hsw */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7667 | 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] | 7668 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7669 | lpt_init_clock_gating(dev_priv); |
Eugeni Dodonov | cad2a2d | 2012-07-02 11:51:09 -0300 | [diff] [blame] | 7670 | } |
| 7671 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7672 | static void ivb_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7673 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7674 | u32 snpcr; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7675 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7676 | 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] | 7677 | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7678 | /* WaFbcAsynchFlipDisableFbcQueue:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7679 | intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1, |
| 7680 | intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) | |
Ville Syrjälä | 885f182 | 2020-07-08 16:12:20 +0300 | [diff] [blame] | 7681 | ILK_FBCQ_DIS); |
| 7682 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7683 | /* WaDisableBackToBackFlipFix:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7684 | intel_uncore_write(&dev_priv->uncore, IVB_CHICKEN3, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7685 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7686 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7687 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7688 | if (IS_IVB_GT1(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7689 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7690 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7691 | else { |
| 7692 | /* must write both registers */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7693 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7694 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7695 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2_GT2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7696 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
Ville Syrjälä | 412236c | 2014-01-22 21:32:44 +0200 | [diff] [blame] | 7697 | } |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7698 | |
Ville Syrjälä | 1b80a19a | 2014-01-22 21:32:53 +0200 | [diff] [blame] | 7699 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7700 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7701 | * This implements the WaDisableRCZUnitClockGating:ivb workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7702 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7703 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Ville Syrjälä | 28acf3b | 2014-01-22 21:32:48 +0200 | [diff] [blame] | 7704 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7705 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7706 | /* This is required by WaCatErrorRejectionIssue:ivb */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7707 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7708 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7709 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7710 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7711 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7712 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7713 | snpcr = intel_uncore_read(&dev_priv->uncore, GEN6_MBCUNIT_SNPCR); |
Ben Widawsky | 2084822 | 2012-05-04 18:58:59 -0700 | [diff] [blame] | 7714 | snpcr &= ~GEN6_MBC_SNPCR_MASK; |
| 7715 | snpcr |= GEN6_MBC_SNPCR_MED; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7716 | intel_uncore_write(&dev_priv->uncore, GEN6_MBCUNIT_SNPCR, snpcr); |
Daniel Vetter | 3107bd4 | 2012-10-31 22:52:31 +0100 | [diff] [blame] | 7717 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 7718 | if (!HAS_PCH_NOP(dev_priv)) |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7719 | cpt_init_clock_gating(dev_priv); |
Daniel Vetter | 1d7aaa0 | 2013-02-09 21:03:42 +0100 | [diff] [blame] | 7720 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7721 | gen6_check_mch_setup(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7722 | } |
| 7723 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7724 | static void vlv_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7725 | { |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7726 | /* WaDisableBackToBackFlipFix:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7727 | intel_uncore_write(&dev_priv->uncore, IVB_CHICKEN3, |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7728 | CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE | |
| 7729 | CHICKEN3_DGMG_DONE_FIX_DISABLE); |
| 7730 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7731 | /* WaDisableDopClockGating:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7732 | intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2, |
Jesse Barnes | 8ab4397 | 2012-10-25 12:15:42 -0700 | [diff] [blame] | 7733 | _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE)); |
| 7734 | |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7735 | /* This is required by WaCatErrorRejectionIssue:vlv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7736 | intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG, |
| 7737 | intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) | |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7738 | GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB); |
| 7739 | |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7740 | /* |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7741 | * According to the spec, bit 13 (RCZUNIT) must be set on IVB. |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7742 | * This implements the WaDisableRCZUnitClockGating:vlv workaround. |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7743 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7744 | intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2, |
Ville Syrjälä | 3c0edae | 2014-01-22 21:32:56 +0200 | [diff] [blame] | 7745 | GEN6_RCZUNIT_CLOCK_GATE_DISABLE); |
Jesse Barnes | 0f846f8 | 2012-06-14 11:04:47 -0700 | [diff] [blame] | 7746 | |
Akash Goel | c98f506 | 2014-03-24 23:00:07 +0530 | [diff] [blame] | 7747 | /* WaDisableL3Bank2xClockGate:vlv |
| 7748 | * Disabling L3 clock gating- MMIO 940c[25] = 1 |
| 7749 | * Set bit 25, to disable L3_BANK_2x_CLK_GATING */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7750 | intel_uncore_write(&dev_priv->uncore, GEN7_UCGCTL4, |
| 7751 | 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] | 7752 | |
Ville Syrjälä | afd58e7 | 2014-01-22 21:33:03 +0200 | [diff] [blame] | 7753 | /* |
Damien Lespiau | ecdb4eb7 | 2013-05-03 18:48:10 +0100 | [diff] [blame] | 7754 | * WaDisableVLVClockGating_VBIIssue:vlv |
Jesse Barnes | 2d80957 | 2012-10-25 12:15:44 -0700 | [diff] [blame] | 7755 | * Disable clock gating on th GCFG unit to prevent a delay |
| 7756 | * in the reporting of vblank events. |
| 7757 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7758 | intel_uncore_write(&dev_priv->uncore, VLV_GUNIT_CLOCK_GATE, GCFG_DIS); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7759 | } |
| 7760 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7761 | 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] | 7762 | { |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 7763 | /* WaVSRefCountFullforceMissDisable:chv */ |
| 7764 | /* WaDSRefCountFullforceMissDisable:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7765 | intel_uncore_write(&dev_priv->uncore, GEN7_FF_THREAD_MODE, |
| 7766 | intel_uncore_read(&dev_priv->uncore, GEN7_FF_THREAD_MODE) & |
Ville Syrjälä | 232ce33 | 2014-04-09 13:28:35 +0300 | [diff] [blame] | 7767 | ~(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] | 7768 | |
| 7769 | /* WaDisableSemaphoreAndSyncFlipWait:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7770 | intel_uncore_write(&dev_priv->uncore, GEN6_RC_SLEEP_PSMI_CONTROL, |
Ville Syrjälä | acea6f9 | 2014-04-09 13:28:36 +0300 | [diff] [blame] | 7771 | _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE)); |
Ville Syrjälä | 0846697 | 2014-04-09 13:28:37 +0300 | [diff] [blame] | 7772 | |
| 7773 | /* WaDisableCSUnitClockGating:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7774 | 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] | 7775 | GEN6_CSUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | c631780 | 2014-04-09 13:28:38 +0300 | [diff] [blame] | 7776 | |
| 7777 | /* WaDisableSDEUnitClockGating:chv */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7778 | 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] | 7779 | GEN8_SDEUNIT_CLOCK_GATE_DISABLE); |
Ville Syrjälä | 6d50b06 | 2015-05-19 20:32:57 +0300 | [diff] [blame] | 7780 | |
| 7781 | /* |
Imre Deak | 450174f | 2016-05-03 15:54:21 +0300 | [diff] [blame] | 7782 | * WaProgramL3SqcReg1Default:chv |
| 7783 | * See gfxspecs/Related Documents/Performance Guide/ |
| 7784 | * LSQC Setting Recommendations. |
| 7785 | */ |
| 7786 | gen8_set_l3sqc_credits(dev_priv, 38, 2); |
Ville Syrjälä | a4565da | 2014-04-09 13:28:10 +0300 | [diff] [blame] | 7787 | } |
| 7788 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7789 | static void g4x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7790 | { |
Jani Nikula | 5ce9a649 | 2019-01-18 14:01:20 +0200 | [diff] [blame] | 7791 | u32 dspclk_gate; |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7792 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7793 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D1, 0); |
| 7794 | 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] | 7795 | GS_UNIT_CLOCK_GATE_DISABLE | |
| 7796 | CL_UNIT_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7797 | intel_uncore_write(&dev_priv->uncore, RAMCLK_GATE_D, 0); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7798 | dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE | |
| 7799 | OVRUNIT_CLOCK_GATE_DISABLE | |
| 7800 | OVCUNIT_CLOCK_GATE_DISABLE; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7801 | if (IS_GM45(dev_priv)) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7802 | dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7803 | intel_uncore_write(&dev_priv->uncore, DSPCLK_GATE_D, dspclk_gate); |
Daniel Vetter | 4358a37 | 2012-10-18 11:49:51 +0200 | [diff] [blame] | 7804 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7805 | g4x_disable_trickle_feed(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7806 | } |
| 7807 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7808 | static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7809 | { |
Tvrtko Ursulin | 4f5fd91 | 2019-06-11 11:45:48 +0100 | [diff] [blame] | 7810 | struct intel_uncore *uncore = &dev_priv->uncore; |
| 7811 | |
| 7812 | intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE); |
| 7813 | intel_uncore_write(uncore, RENCLK_GATE_D2, 0); |
| 7814 | intel_uncore_write(uncore, DSPCLK_GATE_D, 0); |
| 7815 | intel_uncore_write(uncore, RAMCLK_GATE_D, 0); |
| 7816 | intel_uncore_write16(uncore, DEUC, 0); |
| 7817 | intel_uncore_write(uncore, |
| 7818 | MI_ARB_STATE, |
| 7819 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7820 | } |
| 7821 | |
Rodrigo Vivi | 91200c0 | 2017-08-28 22:20:26 -0700 | [diff] [blame] | 7822 | static void i965g_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7823 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7824 | 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] | 7825 | I965_RCC_CLOCK_GATE_DISABLE | |
| 7826 | I965_RCPB_CLOCK_GATE_DISABLE | |
| 7827 | I965_ISC_CLOCK_GATE_DISABLE | |
| 7828 | I965_FBC_CLOCK_GATE_DISABLE); |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7829 | intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D2, 0); |
| 7830 | intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE, |
Ville Syrjälä | 20f9496 | 2013-06-07 10:47:02 +0300 | [diff] [blame] | 7831 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7832 | } |
| 7833 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7834 | static void gen3_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7835 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7836 | u32 dstate = intel_uncore_read(&dev_priv->uncore, D_STATE); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7837 | |
| 7838 | dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING | |
| 7839 | DSTATE_DOT_CLOCK_GATING; |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7840 | intel_uncore_write(&dev_priv->uncore, D_STATE, dstate); |
Chris Wilson | 13a86b8 | 2012-04-24 14:51:43 +0100 | [diff] [blame] | 7841 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7842 | if (IS_PINEVIEW(dev_priv)) |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7843 | 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] | 7844 | |
| 7845 | /* IIR "flip pending" means done if this bit is set */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7846 | 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] | 7847 | |
| 7848 | /* interrupts should cause a wake up from C3 */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7849 | 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] | 7850 | |
| 7851 | /* 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] | 7852 | 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] | 7853 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7854 | intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7855 | _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7856 | } |
| 7857 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7858 | static void i85x_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7859 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7860 | 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] | 7861 | |
| 7862 | /* interrupts should cause a wake up from C3 */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7863 | 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] | 7864 | _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE)); |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7865 | |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7866 | intel_uncore_write(&dev_priv->uncore, MEM_MODE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7867 | _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE)); |
Ville Syrjälä | 5cecf50 | 2020-07-02 18:37:23 +0300 | [diff] [blame] | 7868 | |
| 7869 | /* |
| 7870 | * Have FBC ignore 3D activity since we use software |
| 7871 | * render tracking, and otherwise a pure 3D workload |
| 7872 | * (even if it just renders a single frame and then does |
| 7873 | * abosultely nothing) would not allow FBC to recompress |
| 7874 | * until a 2D blit occurs. |
| 7875 | */ |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7876 | intel_uncore_write(&dev_priv->uncore, SCPD0, |
Ville Syrjälä | 5cecf50 | 2020-07-02 18:37:23 +0300 | [diff] [blame] | 7877 | _MASKED_BIT_ENABLE(SCPD_FBC_IGNORE_3D)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7878 | } |
| 7879 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7880 | static void i830_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7881 | { |
Jani Nikula | 5f46166 | 2020-11-30 13:15:58 +0200 | [diff] [blame] | 7882 | intel_uncore_write(&dev_priv->uncore, MEM_MODE, |
Ville Syrjälä | 1038392 | 2014-08-15 01:21:54 +0300 | [diff] [blame] | 7883 | _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) | |
| 7884 | _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE)); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7885 | } |
| 7886 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7887 | void intel_init_clock_gating(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7888 | { |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7889 | dev_priv->clock_gating_funcs->init_clock_gating(dev_priv); |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 7890 | } |
| 7891 | |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7892 | void intel_suspend_hw(struct drm_i915_private *dev_priv) |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7893 | { |
Ville Syrjälä | 712bf36 | 2016-10-31 22:37:23 +0200 | [diff] [blame] | 7894 | if (HAS_PCH_LPT(dev_priv)) |
| 7895 | lpt_suspend_hw(dev_priv); |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 7896 | } |
| 7897 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 7898 | static void nop_init_clock_gating(struct drm_i915_private *dev_priv) |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7899 | { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 7900 | drm_dbg_kms(&dev_priv->drm, |
| 7901 | "No clock gating settings or workarounds applied.\n"); |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7902 | } |
| 7903 | |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7904 | #define CG_FUNCS(platform) \ |
| 7905 | static const struct drm_i915_clock_gating_funcs platform##_clock_gating_funcs = { \ |
| 7906 | .init_clock_gating = platform##_init_clock_gating, \ |
| 7907 | } |
| 7908 | |
| 7909 | CG_FUNCS(adlp); |
| 7910 | CG_FUNCS(dg1); |
| 7911 | CG_FUNCS(gen12lp); |
| 7912 | CG_FUNCS(icl); |
| 7913 | CG_FUNCS(cfl); |
| 7914 | CG_FUNCS(skl); |
| 7915 | CG_FUNCS(kbl); |
| 7916 | CG_FUNCS(bxt); |
| 7917 | CG_FUNCS(glk); |
| 7918 | CG_FUNCS(bdw); |
| 7919 | CG_FUNCS(chv); |
| 7920 | CG_FUNCS(hsw); |
| 7921 | CG_FUNCS(ivb); |
| 7922 | CG_FUNCS(vlv); |
| 7923 | CG_FUNCS(gen6); |
| 7924 | CG_FUNCS(ilk); |
| 7925 | CG_FUNCS(g4x); |
| 7926 | CG_FUNCS(i965gm); |
| 7927 | CG_FUNCS(i965g); |
| 7928 | CG_FUNCS(gen3); |
| 7929 | CG_FUNCS(i85x); |
| 7930 | CG_FUNCS(i830); |
| 7931 | CG_FUNCS(nop); |
| 7932 | #undef CG_FUNCS |
| 7933 | |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7934 | /** |
| 7935 | * intel_init_clock_gating_hooks - setup the clock gating hooks |
| 7936 | * @dev_priv: device private |
| 7937 | * |
| 7938 | * Setup the hooks that configure which clocks of a given platform can be |
| 7939 | * gated and also apply various GT and display specific workarounds for these |
| 7940 | * platforms. Note that some GT specific workarounds are applied separately |
| 7941 | * when GPU contexts or batchbuffers start their execution. |
| 7942 | */ |
| 7943 | void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv) |
| 7944 | { |
José Roberto de Souza | a8a56da | 2021-05-14 08:37:09 -0700 | [diff] [blame] | 7945 | if (IS_ALDERLAKE_P(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7946 | dev_priv->clock_gating_funcs = &adlp_clock_gating_funcs; |
José Roberto de Souza | a8a56da | 2021-05-14 08:37:09 -0700 | [diff] [blame] | 7947 | else if (IS_DG1(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7948 | dev_priv->clock_gating_funcs = &dg1_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7949 | else if (GRAPHICS_VER(dev_priv) == 12) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7950 | dev_priv->clock_gating_funcs = &gen12lp_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7951 | else if (GRAPHICS_VER(dev_priv) == 11) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7952 | dev_priv->clock_gating_funcs = &icl_clock_gating_funcs; |
Chris Wilson | 5f4ae27 | 2020-06-02 15:05:40 +0100 | [diff] [blame] | 7953 | else if (IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7954 | dev_priv->clock_gating_funcs = &cfl_clock_gating_funcs; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 7955 | else if (IS_SKYLAKE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7956 | dev_priv->clock_gating_funcs = &skl_clock_gating_funcs; |
Rodrigo Vivi | 0a46ddd | 2017-08-30 21:52:23 -0700 | [diff] [blame] | 7957 | else if (IS_KABYLAKE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7958 | dev_priv->clock_gating_funcs = &kbl_clock_gating_funcs; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7959 | else if (IS_BROXTON(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7960 | dev_priv->clock_gating_funcs = &bxt_clock_gating_funcs; |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 7961 | else if (IS_GEMINILAKE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7962 | dev_priv->clock_gating_funcs = &glk_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7963 | else if (IS_BROADWELL(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7964 | dev_priv->clock_gating_funcs = &bdw_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7965 | else if (IS_CHERRYVIEW(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7966 | dev_priv->clock_gating_funcs = &chv_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7967 | else if (IS_HASWELL(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7968 | dev_priv->clock_gating_funcs = &hsw_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7969 | else if (IS_IVYBRIDGE(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7970 | dev_priv->clock_gating_funcs = &ivb_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7971 | else if (IS_VALLEYVIEW(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7972 | dev_priv->clock_gating_funcs = &vlv_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7973 | else if (GRAPHICS_VER(dev_priv) == 6) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7974 | dev_priv->clock_gating_funcs = &gen6_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7975 | else if (GRAPHICS_VER(dev_priv) == 5) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7976 | dev_priv->clock_gating_funcs = &ilk_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7977 | else if (IS_G4X(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7978 | dev_priv->clock_gating_funcs = &g4x_clock_gating_funcs; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7979 | else if (IS_I965GM(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7980 | dev_priv->clock_gating_funcs = &i965gm_clock_gating_funcs; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7981 | else if (IS_I965G(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7982 | dev_priv->clock_gating_funcs = &i965g_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7983 | else if (GRAPHICS_VER(dev_priv) == 3) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7984 | dev_priv->clock_gating_funcs = &gen3_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7985 | else if (IS_I85X(dev_priv) || IS_I865G(dev_priv)) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7986 | dev_priv->clock_gating_funcs = &i85x_clock_gating_funcs; |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 7987 | else if (GRAPHICS_VER(dev_priv) == 2) |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7988 | dev_priv->clock_gating_funcs = &i830_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7989 | else { |
| 7990 | MISSING_CASE(INTEL_DEVID(dev_priv)); |
Dave Airlie | eba4b79 | 2021-09-29 01:58:07 +0300 | [diff] [blame] | 7991 | dev_priv->clock_gating_funcs = &nop_clock_gating_funcs; |
Imre Deak | bb400da | 2016-03-16 13:38:54 +0200 | [diff] [blame] | 7992 | } |
| 7993 | } |
| 7994 | |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 7995 | static const struct drm_i915_wm_disp_funcs skl_wm_funcs = { |
| 7996 | .compute_global_watermarks = skl_compute_wm, |
| 7997 | }; |
| 7998 | |
| 7999 | static const struct drm_i915_wm_disp_funcs ilk_wm_funcs = { |
| 8000 | .compute_pipe_wm = ilk_compute_pipe_wm, |
| 8001 | .compute_intermediate_wm = ilk_compute_intermediate_wm, |
| 8002 | .initial_watermarks = ilk_initial_watermarks, |
| 8003 | .optimize_watermarks = ilk_optimize_watermarks, |
| 8004 | }; |
| 8005 | |
| 8006 | static const struct drm_i915_wm_disp_funcs vlv_wm_funcs = { |
| 8007 | .compute_pipe_wm = vlv_compute_pipe_wm, |
| 8008 | .compute_intermediate_wm = vlv_compute_intermediate_wm, |
| 8009 | .initial_watermarks = vlv_initial_watermarks, |
| 8010 | .optimize_watermarks = vlv_optimize_watermarks, |
| 8011 | .atomic_update_watermarks = vlv_atomic_update_fifo, |
| 8012 | }; |
| 8013 | |
| 8014 | static const struct drm_i915_wm_disp_funcs g4x_wm_funcs = { |
| 8015 | .compute_pipe_wm = g4x_compute_pipe_wm, |
| 8016 | .compute_intermediate_wm = g4x_compute_intermediate_wm, |
| 8017 | .initial_watermarks = g4x_initial_watermarks, |
| 8018 | .optimize_watermarks = g4x_optimize_watermarks, |
| 8019 | }; |
| 8020 | |
| 8021 | static const struct drm_i915_wm_disp_funcs pnv_wm_funcs = { |
| 8022 | .update_wm = pnv_update_wm, |
| 8023 | }; |
| 8024 | |
| 8025 | static const struct drm_i915_wm_disp_funcs i965_wm_funcs = { |
| 8026 | .update_wm = i965_update_wm, |
| 8027 | }; |
| 8028 | |
| 8029 | static const struct drm_i915_wm_disp_funcs i9xx_wm_funcs = { |
| 8030 | .update_wm = i9xx_update_wm, |
| 8031 | }; |
| 8032 | |
| 8033 | static const struct drm_i915_wm_disp_funcs i845_wm_funcs = { |
| 8034 | .update_wm = i845_update_wm, |
| 8035 | }; |
| 8036 | |
| 8037 | static const struct drm_i915_wm_disp_funcs nop_funcs = { |
| 8038 | }; |
| 8039 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8040 | /* Set up chip specific power management-related functions */ |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 8041 | void intel_init_pm(struct drm_i915_private *dev_priv) |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8042 | { |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8043 | /* For cxsr */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8044 | if (IS_PINEVIEW(dev_priv)) |
Lucas De Marchi | 1d21822 | 2019-12-24 00:40:04 -0800 | [diff] [blame] | 8045 | pnv_get_mem_freq(dev_priv); |
Lucas De Marchi | 651e7d4 | 2021-06-05 21:50:49 -0700 | [diff] [blame] | 8046 | else if (GRAPHICS_VER(dev_priv) == 5) |
Lucas De Marchi | 9eae5e2 | 2019-12-24 00:40:09 -0800 | [diff] [blame] | 8047 | ilk_get_mem_freq(dev_priv); |
Daniel Vetter | c921aba | 2012-04-26 23:28:17 +0200 | [diff] [blame] | 8048 | |
James Ausmus | b068a86 | 2019-10-09 10:23:14 -0700 | [diff] [blame] | 8049 | if (intel_has_sagv(dev_priv)) |
| 8050 | skl_setup_sagv_block_time(dev_priv); |
| 8051 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8052 | /* For FIFO watermark updates */ |
Matt Roper | 7dadd28 | 2021-03-19 21:42:43 -0700 | [diff] [blame] | 8053 | if (DISPLAY_VER(dev_priv) >= 9) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8054 | skl_setup_wm_latency(dev_priv); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8055 | dev_priv->wm_disp = &skl_wm_funcs; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8056 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8057 | ilk_setup_wm_latency(dev_priv); |
Ville Syrjälä | 53615a5 | 2013-08-01 16:18:50 +0300 | [diff] [blame] | 8058 | |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8059 | 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] | 8060 | 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] | 8061 | (DISPLAY_VER(dev_priv) != 5 && dev_priv->wm.pri_latency[0] && |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8062 | dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) { |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8063 | dev_priv->wm_disp = &ilk_wm_funcs; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8064 | } else { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8065 | drm_dbg_kms(&dev_priv->drm, |
| 8066 | "Failed to read display plane latency. " |
| 8067 | "Disable CxSR\n"); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8068 | dev_priv->wm_disp = &nop_funcs; |
Ville Syrjälä | bd60254 | 2014-01-07 16:14:10 +0200 | [diff] [blame] | 8069 | } |
Ville Syrjälä | 6b6b3ee | 2016-11-28 19:37:07 +0200 | [diff] [blame] | 8070 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | bb72651 | 2016-10-31 22:37:24 +0200 | [diff] [blame] | 8071 | vlv_setup_wm_latency(dev_priv); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8072 | dev_priv->wm_disp = &vlv_wm_funcs; |
Ville Syrjälä | 04548cb | 2017-04-21 21:14:29 +0300 | [diff] [blame] | 8073 | } else if (IS_G4X(dev_priv)) { |
| 8074 | g4x_setup_wm_latency(dev_priv); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8075 | dev_priv->wm_disp = &g4x_wm_funcs; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8076 | } else if (IS_PINEVIEW(dev_priv)) { |
Tvrtko Ursulin | 86d35d4 | 2019-03-26 07:40:54 +0000 | [diff] [blame] | 8077 | if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv), |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8078 | dev_priv->is_ddr3, |
| 8079 | dev_priv->fsb_freq, |
| 8080 | dev_priv->mem_freq)) { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8081 | drm_info(&dev_priv->drm, |
| 8082 | "failed to find known CxSR latency " |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8083 | "(found ddr%s fsb freq %d, mem freq %d), " |
| 8084 | "disabling CxSR\n", |
| 8085 | (dev_priv->is_ddr3 == 1) ? "3" : "2", |
| 8086 | dev_priv->fsb_freq, dev_priv->mem_freq); |
| 8087 | /* Disable CxSR and never update its watermark again */ |
Imre Deak | 5209b1f | 2014-07-01 12:36:17 +0300 | [diff] [blame] | 8088 | intel_set_memory_cxsr(dev_priv, false); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8089 | dev_priv->wm_disp = &nop_funcs; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8090 | } else |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8091 | dev_priv->wm_disp = &pnv_wm_funcs; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8092 | } else if (DISPLAY_VER(dev_priv) == 4) { |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8093 | dev_priv->wm_disp = &i965_wm_funcs; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8094 | } else if (DISPLAY_VER(dev_priv) == 3) { |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8095 | dev_priv->wm_disp = &i9xx_wm_funcs; |
Lucas De Marchi | 93e7e61 | 2021-04-12 22:09:53 -0700 | [diff] [blame] | 8096 | } else if (DISPLAY_VER(dev_priv) == 2) { |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 8097 | if (INTEL_NUM_PIPES(dev_priv) == 1) |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8098 | dev_priv->wm_disp = &i845_wm_funcs; |
Dave Airlie | 758b2fc | 2021-09-29 01:57:46 +0300 | [diff] [blame] | 8099 | else |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8100 | dev_priv->wm_disp = &i9xx_wm_funcs; |
Daniel Vetter | feb56b9 | 2013-12-14 20:38:30 -0200 | [diff] [blame] | 8101 | } else { |
Wambui Karuga | f8d18d5 | 2020-01-07 18:13:30 +0300 | [diff] [blame] | 8102 | drm_err(&dev_priv->drm, |
| 8103 | "unexpected fall-through in %s\n", __func__); |
Dave Airlie | dde98a5 | 2021-09-29 01:58:08 +0300 | [diff] [blame] | 8104 | dev_priv->wm_disp = &nop_funcs; |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8105 | } |
| 8106 | } |
| 8107 | |
Tvrtko Ursulin | 192aa18 | 2016-12-01 14:16:45 +0000 | [diff] [blame] | 8108 | void intel_pm_setup(struct drm_i915_private *dev_priv) |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8109 | { |
Sagar Arun Kamble | ad1443f | 2017-10-10 22:30:04 +0100 | [diff] [blame] | 8110 | dev_priv->runtime_pm.suspended = false; |
| 8111 | atomic_set(&dev_priv->runtime_pm.wakeref_count, 0); |
Chris Wilson | 907b28c | 2013-07-19 20:36:52 +0100 | [diff] [blame] | 8112 | } |
Ville Syrjälä | 3cf43cd | 2020-02-25 19:11:13 +0200 | [diff] [blame] | 8113 | |
| 8114 | static struct intel_global_state *intel_dbuf_duplicate_state(struct intel_global_obj *obj) |
| 8115 | { |
| 8116 | struct intel_dbuf_state *dbuf_state; |
| 8117 | |
| 8118 | dbuf_state = kmemdup(obj->state, sizeof(*dbuf_state), GFP_KERNEL); |
| 8119 | if (!dbuf_state) |
| 8120 | return NULL; |
| 8121 | |
| 8122 | return &dbuf_state->base; |
| 8123 | } |
| 8124 | |
| 8125 | static void intel_dbuf_destroy_state(struct intel_global_obj *obj, |
| 8126 | struct intel_global_state *state) |
| 8127 | { |
| 8128 | kfree(state); |
| 8129 | } |
| 8130 | |
| 8131 | static const struct intel_global_state_funcs intel_dbuf_funcs = { |
| 8132 | .atomic_duplicate_state = intel_dbuf_duplicate_state, |
| 8133 | .atomic_destroy_state = intel_dbuf_destroy_state, |
| 8134 | }; |
| 8135 | |
| 8136 | struct intel_dbuf_state * |
| 8137 | intel_atomic_get_dbuf_state(struct intel_atomic_state *state) |
| 8138 | { |
| 8139 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8140 | struct intel_global_state *dbuf_state; |
| 8141 | |
| 8142 | dbuf_state = intel_atomic_get_global_obj_state(state, &dev_priv->dbuf.obj); |
| 8143 | if (IS_ERR(dbuf_state)) |
| 8144 | return ERR_CAST(dbuf_state); |
| 8145 | |
| 8146 | return to_intel_dbuf_state(dbuf_state); |
| 8147 | } |
| 8148 | |
| 8149 | int intel_dbuf_init(struct drm_i915_private *dev_priv) |
| 8150 | { |
| 8151 | struct intel_dbuf_state *dbuf_state; |
| 8152 | |
| 8153 | dbuf_state = kzalloc(sizeof(*dbuf_state), GFP_KERNEL); |
| 8154 | if (!dbuf_state) |
| 8155 | return -ENOMEM; |
| 8156 | |
| 8157 | intel_atomic_global_obj_init(dev_priv, &dev_priv->dbuf.obj, |
| 8158 | &dbuf_state->base, &intel_dbuf_funcs); |
| 8159 | |
| 8160 | return 0; |
| 8161 | } |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8162 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 8163 | /* |
| 8164 | * Configure MBUS_CTL and all DBUF_CTL_S of each slice to join_mbus state before |
| 8165 | * update the request state of all DBUS slices. |
| 8166 | */ |
| 8167 | static void update_mbus_pre_enable(struct intel_atomic_state *state) |
| 8168 | { |
| 8169 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8170 | u32 mbus_ctl, dbuf_min_tracker_val; |
| 8171 | enum dbuf_slice slice; |
| 8172 | const struct intel_dbuf_state *dbuf_state = |
| 8173 | intel_atomic_get_new_dbuf_state(state); |
| 8174 | |
| 8175 | if (!IS_ALDERLAKE_P(dev_priv)) |
| 8176 | return; |
| 8177 | |
| 8178 | /* |
| 8179 | * TODO: Implement vblank synchronized MBUS joining changes. |
| 8180 | * Must be properly coordinated with dbuf reprogramming. |
| 8181 | */ |
| 8182 | if (dbuf_state->joined_mbus) { |
| 8183 | mbus_ctl = MBUS_HASHING_MODE_1x4 | MBUS_JOIN | |
| 8184 | MBUS_JOIN_PIPE_SELECT_NONE; |
| 8185 | dbuf_min_tracker_val = DBUF_MIN_TRACKER_STATE_SERVICE(3); |
| 8186 | } else { |
| 8187 | mbus_ctl = MBUS_HASHING_MODE_2x2 | |
| 8188 | MBUS_JOIN_PIPE_SELECT_NONE; |
| 8189 | dbuf_min_tracker_val = DBUF_MIN_TRACKER_STATE_SERVICE(1); |
| 8190 | } |
| 8191 | |
| 8192 | intel_de_rmw(dev_priv, MBUS_CTL, |
| 8193 | MBUS_HASHING_MODE_MASK | MBUS_JOIN | |
| 8194 | MBUS_JOIN_PIPE_SELECT_MASK, mbus_ctl); |
| 8195 | |
| 8196 | for_each_dbuf_slice(dev_priv, slice) |
| 8197 | intel_de_rmw(dev_priv, DBUF_CTL_S(slice), |
| 8198 | DBUF_MIN_TRACKER_STATE_SERVICE_MASK, |
| 8199 | dbuf_min_tracker_val); |
| 8200 | } |
| 8201 | |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8202 | void intel_dbuf_pre_plane_update(struct intel_atomic_state *state) |
| 8203 | { |
| 8204 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8205 | const struct intel_dbuf_state *new_dbuf_state = |
| 8206 | intel_atomic_get_new_dbuf_state(state); |
| 8207 | const struct intel_dbuf_state *old_dbuf_state = |
| 8208 | intel_atomic_get_old_dbuf_state(state); |
| 8209 | |
| 8210 | if (!new_dbuf_state || |
Stanislav Lisovskiy | 0d6695b | 2021-05-27 14:01:06 +0300 | [diff] [blame] | 8211 | ((new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices) |
| 8212 | && (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus))) |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8213 | return; |
| 8214 | |
| 8215 | WARN_ON(!new_dbuf_state->base.changed); |
| 8216 | |
Vandita Kulkarni | f4dc008 | 2021-05-18 17:06:17 -0700 | [diff] [blame] | 8217 | update_mbus_pre_enable(state); |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8218 | gen9_dbuf_slices_update(dev_priv, |
| 8219 | old_dbuf_state->enabled_slices | |
| 8220 | new_dbuf_state->enabled_slices); |
| 8221 | } |
| 8222 | |
| 8223 | void intel_dbuf_post_plane_update(struct intel_atomic_state *state) |
| 8224 | { |
| 8225 | struct drm_i915_private *dev_priv = to_i915(state->base.dev); |
| 8226 | const struct intel_dbuf_state *new_dbuf_state = |
| 8227 | intel_atomic_get_new_dbuf_state(state); |
| 8228 | const struct intel_dbuf_state *old_dbuf_state = |
| 8229 | intel_atomic_get_old_dbuf_state(state); |
| 8230 | |
| 8231 | if (!new_dbuf_state || |
Stanislav Lisovskiy | 0d6695b | 2021-05-27 14:01:06 +0300 | [diff] [blame] | 8232 | ((new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices) |
| 8233 | && (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus))) |
Ville Syrjälä | c7c0e7e | 2020-02-25 19:11:15 +0200 | [diff] [blame] | 8234 | return; |
| 8235 | |
| 8236 | WARN_ON(!new_dbuf_state->base.changed); |
| 8237 | |
| 8238 | gen9_dbuf_slices_update(dev_priv, |
| 8239 | new_dbuf_state->enabled_slices); |
| 8240 | } |