blob: 0a0103ecf7bcbadac3b7b165a4ff7957c84ede03 [file] [log] [blame]
Eugeni Dodonov85208be2012-04-16 22:20:34 -03001/*
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 Ravnborgd0e93592019-01-26 13:25:24 +010028#include <linux/module.h>
Chris Wilson08ea70a2018-08-12 23:36:31 +010029#include <linux/pm_runtime.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010030
31#include <drm/drm_atomic_helper.h>
32#include <drm/drm_fourcc.h>
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -070033#include <drm/drm_plane_helper.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010034
Jani Nikuladf0566a2019-06-13 11:44:16 +030035#include "display/intel_atomic.h"
Jani Nikula1d455f82019-08-06 14:39:33 +030036#include "display/intel_display_types.h"
Jani Nikuladf0566a2019-06-13 11:44:16 +030037#include "display/intel_fbc.h"
38#include "display/intel_sprite.h"
39
Andi Shyti0dc3c562019-10-20 19:41:39 +010040#include "gt/intel_llc.h"
41
Eugeni Dodonov85208be2012-04-16 22:20:34 -030042#include "i915_drv.h"
Jani Nikula440e2b32019-04-29 15:29:27 +030043#include "i915_irq.h"
Jani Nikulaa09d9a82019-08-06 13:07:28 +030044#include "i915_trace.h"
Jani Nikula696173b2019-04-05 14:00:15 +030045#include "intel_pm.h"
Chris Wilson56c50982019-04-26 09:17:22 +010046#include "intel_sideband.h"
Daniel Vettereb48eb02012-04-26 23:28:12 +020047#include "../../../platform/x86/intel_ips.h"
Eugeni Dodonov85208be2012-04-16 22:20:34 -030048
Ville Syrjälä46f16e62016-10-31 22:37:22 +020049static void gen9_init_clock_gating(struct drm_i915_private *dev_priv)
Mika Kuoppalab033bb62016-06-07 17:19:04 +030050{
Ville Syrjälä93564042017-08-24 22:10:51 +030051 if (HAS_LLC(dev_priv)) {
52 /*
53 * WaCompressedResourceDisplayNewHashMode:skl,kbl
Lucas De Marchie0403cb2017-12-05 11:01:17 -080054 * Display WA #0390: skl,kbl
Ville Syrjälä93564042017-08-24 22:10:51 +030055 *
56 * Must match Sampler, Pixel Back End, and Media. See
57 * WaCompressedResourceSamplerPbeMediaNewHashMode.
58 */
59 I915_WRITE(CHICKEN_PAR1_1,
60 I915_READ(CHICKEN_PAR1_1) |
61 SKL_DE_COMPRESSED_HASH_MODE);
62 }
63
Rodrigo Vivi82525c12017-06-08 08:50:00 -070064 /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl,cfl */
Mika Kuoppalab033bb62016-06-07 17:19:04 +030065 I915_WRITE(CHICKEN_PAR1_1,
66 I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP);
67
Rodrigo Vivi82525c12017-06-08 08:50:00 -070068 /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */
Mika Kuoppala590e8ff2016-06-07 17:19:13 +030069 I915_WRITE(GEN8_CHICKEN_DCPR_1,
70 I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM);
Mika Kuoppala0f78dee2016-06-07 17:19:16 +030071
Rodrigo Vivi82525c12017-06-08 08:50:00 -070072 /* WaFbcTurnOffFbcWatermark:skl,bxt,kbl,cfl */
73 /* WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl */
Mika Kuoppala303d4ea2016-06-07 17:19:17 +030074 I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
75 DISP_FBC_WM_DIS |
76 DISP_FBC_MEMORY_WAKE);
Mika Kuoppalad1b4eef2016-06-07 17:19:19 +030077
Rodrigo Vivi82525c12017-06-08 08:50:00 -070078 /* WaFbcHighMemBwCorruptionAvoidance:skl,bxt,kbl,cfl */
Mika Kuoppalad1b4eef2016-06-07 17:19:19 +030079 I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
80 ILK_DPFC_DISABLE_DUMMY0);
Praveen Paneri32087d12017-08-03 23:02:10 +053081
82 if (IS_SKYLAKE(dev_priv)) {
83 /* WaDisableDopClockGating */
84 I915_WRITE(GEN7_MISCCPCTL, I915_READ(GEN7_MISCCPCTL)
85 & ~GEN7_DOP_CLOCK_GATE_ENABLE);
86 }
Mika Kuoppalab033bb62016-06-07 17:19:04 +030087}
88
Ville Syrjälä46f16e62016-10-31 22:37:22 +020089static void bxt_init_clock_gating(struct drm_i915_private *dev_priv)
Imre Deaka82abe42015-03-27 14:00:04 +020090{
Ville Syrjälä46f16e62016-10-31 22:37:22 +020091 gen9_init_clock_gating(dev_priv);
Daniel Vetterdc00b6a2016-05-19 09:14:20 +020092
Nick Hoatha7546152015-06-29 14:07:32 +010093 /* WaDisableSDEUnitClockGating:bxt */
94 I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
95 GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
96
Imre Deak32608ca2015-03-11 11:10:27 +020097 /*
98 * FIXME:
Ben Widawsky868434c2015-03-11 10:49:32 +020099 * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only.
Imre Deak32608ca2015-03-11 11:10:27 +0200100 */
Imre Deak32608ca2015-03-11 11:10:27 +0200101 I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
Ben Widawsky868434c2015-03-11 10:49:32 +0200102 GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ);
Imre Deakd965e7ac2015-12-01 10:23:52 +0200103
104 /*
105 * Wa: Backlight PWM may stop in the asserted state, causing backlight
106 * to stay fully on.
107 */
Jani Nikula8aeaf642017-02-15 17:21:37 +0200108 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
109 PWM1_GATING_DIS | PWM2_GATING_DIS);
Imre Deaka82abe42015-03-27 14:00:04 +0200110}
111
Ander Conselvan de Oliveira9fb50262017-01-26 11:16:58 +0200112static void glk_init_clock_gating(struct drm_i915_private *dev_priv)
113{
114 gen9_init_clock_gating(dev_priv);
115
116 /*
117 * WaDisablePWMClockGating:glk
118 * Backlight PWM may stop in the asserted state, causing backlight
119 * to stay fully on.
120 */
121 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
122 PWM1_GATING_DIS | PWM2_GATING_DIS);
Ander Conselvan de Oliveiraf4f4b592017-02-22 08:34:29 +0200123
124 /* WaDDIIOTimeout:glk */
125 if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1)) {
126 u32 val = I915_READ(CHICKEN_MISC_2);
127 val &= ~(GLK_CL0_PWR_DOWN |
128 GLK_CL1_PWR_DOWN |
129 GLK_CL2_PWR_DOWN);
130 I915_WRITE(CHICKEN_MISC_2, val);
131 }
132
Ander Conselvan de Oliveira9fb50262017-01-26 11:16:58 +0200133}
134
Ville Syrjälä148ac1f2016-10-31 22:37:16 +0200135static void i915_pineview_get_mem_freq(struct drm_i915_private *dev_priv)
Daniel Vetterc921aba2012-04-26 23:28:17 +0200136{
Daniel Vetterc921aba2012-04-26 23:28:17 +0200137 u32 tmp;
138
139 tmp = I915_READ(CLKCFG);
140
141 switch (tmp & CLKCFG_FSB_MASK) {
142 case CLKCFG_FSB_533:
143 dev_priv->fsb_freq = 533; /* 133*4 */
144 break;
145 case CLKCFG_FSB_800:
146 dev_priv->fsb_freq = 800; /* 200*4 */
147 break;
148 case CLKCFG_FSB_667:
149 dev_priv->fsb_freq = 667; /* 167*4 */
150 break;
151 case CLKCFG_FSB_400:
152 dev_priv->fsb_freq = 400; /* 100*4 */
153 break;
154 }
155
156 switch (tmp & CLKCFG_MEM_MASK) {
157 case CLKCFG_MEM_533:
158 dev_priv->mem_freq = 533;
159 break;
160 case CLKCFG_MEM_667:
161 dev_priv->mem_freq = 667;
162 break;
163 case CLKCFG_MEM_800:
164 dev_priv->mem_freq = 800;
165 break;
166 }
167
168 /* detect pineview DDR3 setting */
169 tmp = I915_READ(CSHRDDR3CTL);
170 dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0;
171}
172
Ville Syrjälä148ac1f2016-10-31 22:37:16 +0200173static void i915_ironlake_get_mem_freq(struct drm_i915_private *dev_priv)
Daniel Vetterc921aba2012-04-26 23:28:17 +0200174{
Daniel Vetterc921aba2012-04-26 23:28:17 +0200175 u16 ddrpll, csipll;
176
Tvrtko Ursulin4f5fd912019-06-11 11:45:48 +0100177 ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1);
178 csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0);
Daniel Vetterc921aba2012-04-26 23:28:17 +0200179
180 switch (ddrpll & 0xff) {
181 case 0xc:
182 dev_priv->mem_freq = 800;
183 break;
184 case 0x10:
185 dev_priv->mem_freq = 1066;
186 break;
187 case 0x14:
188 dev_priv->mem_freq = 1333;
189 break;
190 case 0x18:
191 dev_priv->mem_freq = 1600;
192 break;
193 default:
194 DRM_DEBUG_DRIVER("unknown memory frequency 0x%02x\n",
195 ddrpll & 0xff);
196 dev_priv->mem_freq = 0;
197 break;
198 }
199
Daniel Vetterc921aba2012-04-26 23:28:17 +0200200 switch (csipll & 0x3ff) {
201 case 0x00c:
202 dev_priv->fsb_freq = 3200;
203 break;
204 case 0x00e:
205 dev_priv->fsb_freq = 3733;
206 break;
207 case 0x010:
208 dev_priv->fsb_freq = 4266;
209 break;
210 case 0x012:
211 dev_priv->fsb_freq = 4800;
212 break;
213 case 0x014:
214 dev_priv->fsb_freq = 5333;
215 break;
216 case 0x016:
217 dev_priv->fsb_freq = 5866;
218 break;
219 case 0x018:
220 dev_priv->fsb_freq = 6400;
221 break;
222 default:
223 DRM_DEBUG_DRIVER("unknown fsb frequency 0x%04x\n",
224 csipll & 0x3ff);
225 dev_priv->fsb_freq = 0;
226 break;
227 }
Daniel Vetterc921aba2012-04-26 23:28:17 +0200228}
229
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300230static const struct cxsr_latency cxsr_latency_table[] = {
231 {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
232 {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
233 {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
234 {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
235 {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
236
237 {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
238 {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
239 {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
240 {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
241 {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
242
243 {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
244 {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
245 {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
246 {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
247 {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
248
249 {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
250 {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
251 {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
252 {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
253 {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
254
255 {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
256 {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
257 {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
258 {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
259 {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
260
261 {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
262 {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
263 {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
264 {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
265 {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
266};
267
Tvrtko Ursulin44a655c2016-10-13 11:09:23 +0100268static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop,
269 bool is_ddr3,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300270 int fsb,
271 int mem)
272{
273 const struct cxsr_latency *latency;
274 int i;
275
276 if (fsb == 0 || mem == 0)
277 return NULL;
278
279 for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
280 latency = &cxsr_latency_table[i];
281 if (is_desktop == latency->is_desktop &&
282 is_ddr3 == latency->is_ddr3 &&
283 fsb == latency->fsb_freq && mem == latency->mem_freq)
284 return latency;
285 }
286
287 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
288
289 return NULL;
290}
291
Ville Syrjäläfc1ac8d2015-03-05 21:19:52 +0200292static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable)
293{
294 u32 val;
295
Chris Wilson337fa6e2019-04-26 09:17:20 +0100296 vlv_punit_get(dev_priv);
Ville Syrjäläfc1ac8d2015-03-05 21:19:52 +0200297
298 val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
299 if (enable)
300 val &= ~FORCE_DDR_HIGH_FREQ;
301 else
302 val |= FORCE_DDR_HIGH_FREQ;
303 val &= ~FORCE_DDR_LOW_FREQ;
304 val |= FORCE_DDR_FREQ_REQ_ACK;
305 vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val);
306
307 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) &
308 FORCE_DDR_FREQ_REQ_ACK) == 0, 3))
309 DRM_ERROR("timed out waiting for Punit DDR DVFS request\n");
310
Chris Wilson337fa6e2019-04-26 09:17:20 +0100311 vlv_punit_put(dev_priv);
Ville Syrjäläfc1ac8d2015-03-05 21:19:52 +0200312}
313
Ville Syrjäläcfb41412015-03-05 21:19:51 +0200314static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable)
315{
316 u32 val;
317
Chris Wilson337fa6e2019-04-26 09:17:20 +0100318 vlv_punit_get(dev_priv);
Ville Syrjäläcfb41412015-03-05 21:19:51 +0200319
Ville Syrjäläc11b8132018-11-29 19:55:03 +0200320 val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM);
Ville Syrjäläcfb41412015-03-05 21:19:51 +0200321 if (enable)
322 val |= DSP_MAXFIFO_PM5_ENABLE;
323 else
324 val &= ~DSP_MAXFIFO_PM5_ENABLE;
Ville Syrjäläc11b8132018-11-29 19:55:03 +0200325 vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val);
Ville Syrjäläcfb41412015-03-05 21:19:51 +0200326
Chris Wilson337fa6e2019-04-26 09:17:20 +0100327 vlv_punit_put(dev_priv);
Ville Syrjäläcfb41412015-03-05 21:19:51 +0200328}
329
Ville Syrjäläf4998962015-03-10 17:02:21 +0200330#define FW_WM(value, plane) \
331 (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK)
332
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200333static bool _intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300334{
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200335 bool was_enabled;
Imre Deak5209b1f2014-07-01 12:36:17 +0300336 u32 val;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300337
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100338 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200339 was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Imre Deak5209b1f2014-07-01 12:36:17 +0300340 I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0);
Ville Syrjäläa7a6c492015-06-24 22:00:01 +0300341 POSTING_READ(FW_BLC_SELF_VLV);
Jani Nikulac0f86832016-12-07 12:13:04 +0200342 } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) {
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200343 was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
Imre Deak5209b1f2014-07-01 12:36:17 +0300344 I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0);
Ville Syrjäläa7a6c492015-06-24 22:00:01 +0300345 POSTING_READ(FW_BLC_SELF);
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +0200346 } else if (IS_PINEVIEW(dev_priv)) {
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200347 val = I915_READ(DSPFW3);
348 was_enabled = val & PINEVIEW_SELF_REFRESH_EN;
349 if (enable)
350 val |= PINEVIEW_SELF_REFRESH_EN;
351 else
352 val &= ~PINEVIEW_SELF_REFRESH_EN;
Imre Deak5209b1f2014-07-01 12:36:17 +0300353 I915_WRITE(DSPFW3, val);
Ville Syrjäläa7a6c492015-06-24 22:00:01 +0300354 POSTING_READ(DSPFW3);
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100355 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) {
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200356 was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
Imre Deak5209b1f2014-07-01 12:36:17 +0300357 val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) :
358 _MASKED_BIT_DISABLE(FW_BLC_SELF_EN);
359 I915_WRITE(FW_BLC_SELF, val);
Ville Syrjäläa7a6c492015-06-24 22:00:01 +0300360 POSTING_READ(FW_BLC_SELF);
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100361 } else if (IS_I915GM(dev_priv)) {
Ville Syrjäläacb91352016-07-29 17:57:02 +0300362 /*
363 * FIXME can't find a bit like this for 915G, and
364 * and yet it does have the related watermark in
365 * FW_BLC_SELF. What's going on?
366 */
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200367 was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
Imre Deak5209b1f2014-07-01 12:36:17 +0300368 val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) :
369 _MASKED_BIT_DISABLE(INSTPM_SELF_EN);
370 I915_WRITE(INSTPM, val);
Ville Syrjäläa7a6c492015-06-24 22:00:01 +0300371 POSTING_READ(INSTPM);
Imre Deak5209b1f2014-07-01 12:36:17 +0300372 } else {
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200373 return false;
Imre Deak5209b1f2014-07-01 12:36:17 +0300374 }
375
Ville Syrjälä1489bba2017-03-02 19:15:07 +0200376 trace_intel_memory_cxsr(dev_priv, was_enabled, enable);
377
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200378 DRM_DEBUG_KMS("memory self-refresh is %s (was %s)\n",
379 enableddisabled(enable),
380 enableddisabled(was_enabled));
381
382 return was_enabled;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300383}
384
Ville Syrjälä62571fc2017-04-21 21:14:23 +0300385/**
386 * intel_set_memory_cxsr - Configure CxSR state
387 * @dev_priv: i915 device
388 * @enable: Allow vs. disallow CxSR
389 *
390 * Allow or disallow the system to enter a special CxSR
391 * (C-state self refresh) state. What typically happens in CxSR mode
392 * is that several display FIFOs may get combined into a single larger
393 * FIFO for a particular plane (so called max FIFO mode) to allow the
394 * system to defer memory fetches longer, and the memory will enter
395 * self refresh.
396 *
397 * Note that enabling CxSR does not guarantee that the system enter
398 * this special mode, nor does it guarantee that the system stays
399 * in that mode once entered. So this just allows/disallows the system
400 * to autonomously utilize the CxSR mode. Other factors such as core
401 * C-states will affect when/if the system actually enters/exits the
402 * CxSR mode.
403 *
404 * Note that on VLV/CHV this actually only controls the max FIFO mode,
405 * and the system is free to enter/exit memory self refresh at any time
406 * even when the use of CxSR has been disallowed.
407 *
408 * While the system is actually in the CxSR/max FIFO mode, some plane
409 * control registers will not get latched on vblank. Thus in order to
410 * guarantee the system will respond to changes in the plane registers
411 * we must always disallow CxSR prior to making changes to those registers.
412 * Unfortunately the system will re-evaluate the CxSR conditions at
413 * frame start which happens after vblank start (which is when the plane
414 * registers would get latched), so we can't proceed with the plane update
415 * during the same frame where we disallowed CxSR.
416 *
417 * Certain platforms also have a deeper HPLL SR mode. Fortunately the
418 * HPLL SR mode depends on CxSR itself, so we don't have to hand hold
419 * the hardware w.r.t. HPLL SR when writing to plane registers.
420 * Disallowing just CxSR is sufficient.
421 */
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200422bool intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable)
Ville Syrjälä3d90e642016-11-28 19:37:11 +0200423{
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200424 bool ret;
425
Ville Syrjälä3d90e642016-11-28 19:37:11 +0200426 mutex_lock(&dev_priv->wm.wm_mutex);
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200427 ret = _intel_set_memory_cxsr(dev_priv, enable);
Ville Syrjälä04548cb2017-04-21 21:14:29 +0300428 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
429 dev_priv->wm.vlv.cxsr = enable;
430 else if (IS_G4X(dev_priv))
431 dev_priv->wm.g4x.cxsr = enable;
Ville Syrjälä3d90e642016-11-28 19:37:11 +0200432 mutex_unlock(&dev_priv->wm.wm_mutex);
Ville Syrjälä11a85d62016-11-28 19:37:12 +0200433
434 return ret;
Ville Syrjälä3d90e642016-11-28 19:37:11 +0200435}
Ville Syrjäläfc1ac8d2015-03-05 21:19:52 +0200436
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300437/*
438 * Latency for FIFO fetches is dependent on several factors:
439 * - memory configuration (speed, channels)
440 * - chipset
441 * - current MCH state
442 * It can be fairly high in some situations, so here we assume a fairly
443 * pessimal value. It's a tradeoff between extra memory fetches (if we
444 * set this value too high, the FIFO will fetch frequently to stay full)
445 * and power consumption (set it too low to save power and we might see
446 * FIFO underruns and display "flicker").
447 *
448 * A value of 5us seems to be a good balance; safe for very low end
449 * platforms but not overly aggressive on lower latency configs.
450 */
Chris Wilson5aef6002014-09-03 11:56:07 +0100451static const int pessimal_latency_ns = 5000;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300452
Ville Syrjäläb5004722015-03-05 21:19:47 +0200453#define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \
454 ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8))
455
Ville Syrjälä814e7f02017-03-02 19:14:55 +0200456static void vlv_get_fifo_size(struct intel_crtc_state *crtc_state)
Ville Syrjäläb5004722015-03-05 21:19:47 +0200457{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +0100458 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjäläf07d43d2017-03-02 19:14:52 +0200459 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä814e7f02017-03-02 19:14:55 +0200460 struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state;
Ville Syrjäläf07d43d2017-03-02 19:14:52 +0200461 enum pipe pipe = crtc->pipe;
462 int sprite0_start, sprite1_start;
Ville Syrjäläb5004722015-03-05 21:19:47 +0200463
Ville Syrjäläf07d43d2017-03-02 19:14:52 +0200464 switch (pipe) {
Jani Nikula5ce9a6492019-01-18 14:01:20 +0200465 u32 dsparb, dsparb2, dsparb3;
Ville Syrjäläb5004722015-03-05 21:19:47 +0200466 case PIPE_A:
467 dsparb = I915_READ(DSPARB);
468 dsparb2 = I915_READ(DSPARB2);
469 sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0);
470 sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4);
471 break;
472 case PIPE_B:
473 dsparb = I915_READ(DSPARB);
474 dsparb2 = I915_READ(DSPARB2);
475 sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8);
476 sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12);
477 break;
478 case PIPE_C:
479 dsparb2 = I915_READ(DSPARB2);
480 dsparb3 = I915_READ(DSPARB3);
481 sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16);
482 sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20);
483 break;
484 default:
Ville Syrjäläf07d43d2017-03-02 19:14:52 +0200485 MISSING_CASE(pipe);
486 return;
Ville Syrjäläb5004722015-03-05 21:19:47 +0200487 }
488
Ville Syrjäläf07d43d2017-03-02 19:14:52 +0200489 fifo_state->plane[PLANE_PRIMARY] = sprite0_start;
490 fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start;
491 fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start;
492 fifo_state->plane[PLANE_CURSOR] = 63;
Ville Syrjäläb5004722015-03-05 21:19:47 +0200493}
494
Ville Syrjäläbdaf8432017-11-17 21:19:11 +0200495static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv,
496 enum i9xx_plane_id i9xx_plane)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300497{
Jani Nikula5ce9a6492019-01-18 14:01:20 +0200498 u32 dsparb = I915_READ(DSPARB);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300499 int size;
500
501 size = dsparb & 0x7f;
Ville Syrjäläbdaf8432017-11-17 21:19:11 +0200502 if (i9xx_plane == PLANE_B)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300503 size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
504
Ville Syrjäläbdaf8432017-11-17 21:19:11 +0200505 DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n",
506 dsparb, plane_name(i9xx_plane), size);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300507
508 return size;
509}
510
Ville Syrjäläbdaf8432017-11-17 21:19:11 +0200511static int i830_get_fifo_size(struct drm_i915_private *dev_priv,
512 enum i9xx_plane_id i9xx_plane)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300513{
Jani Nikula5ce9a6492019-01-18 14:01:20 +0200514 u32 dsparb = I915_READ(DSPARB);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300515 int size;
516
517 size = dsparb & 0x1ff;
Ville Syrjäläbdaf8432017-11-17 21:19:11 +0200518 if (i9xx_plane == PLANE_B)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300519 size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
520 size >>= 1; /* Convert to cachelines */
521
Ville Syrjäläbdaf8432017-11-17 21:19:11 +0200522 DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n",
523 dsparb, plane_name(i9xx_plane), size);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300524
525 return size;
526}
527
Ville Syrjäläbdaf8432017-11-17 21:19:11 +0200528static int i845_get_fifo_size(struct drm_i915_private *dev_priv,
529 enum i9xx_plane_id i9xx_plane)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300530{
Jani Nikula5ce9a6492019-01-18 14:01:20 +0200531 u32 dsparb = I915_READ(DSPARB);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300532 int size;
533
534 size = dsparb & 0x7f;
535 size >>= 2; /* Convert to cachelines */
536
Ville Syrjäläbdaf8432017-11-17 21:19:11 +0200537 DRM_DEBUG_KMS("FIFO size - (0x%08x) %c: %d\n",
538 dsparb, plane_name(i9xx_plane), size);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300539
540 return size;
541}
542
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300543/* Pineview has different values for various configs */
544static const struct intel_watermark_params pineview_display_wm = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300545 .fifo_size = PINEVIEW_DISPLAY_FIFO,
546 .max_wm = PINEVIEW_MAX_WM,
547 .default_wm = PINEVIEW_DFT_WM,
548 .guard_size = PINEVIEW_GUARD_WM,
549 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300550};
551static const struct intel_watermark_params pineview_display_hplloff_wm = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300552 .fifo_size = PINEVIEW_DISPLAY_FIFO,
553 .max_wm = PINEVIEW_MAX_WM,
554 .default_wm = PINEVIEW_DFT_HPLLOFF_WM,
555 .guard_size = PINEVIEW_GUARD_WM,
556 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300557};
558static const struct intel_watermark_params pineview_cursor_wm = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300559 .fifo_size = PINEVIEW_CURSOR_FIFO,
560 .max_wm = PINEVIEW_CURSOR_MAX_WM,
561 .default_wm = PINEVIEW_CURSOR_DFT_WM,
562 .guard_size = PINEVIEW_CURSOR_GUARD_WM,
563 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300564};
565static const struct intel_watermark_params pineview_cursor_hplloff_wm = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300566 .fifo_size = PINEVIEW_CURSOR_FIFO,
567 .max_wm = PINEVIEW_CURSOR_MAX_WM,
568 .default_wm = PINEVIEW_CURSOR_DFT_WM,
569 .guard_size = PINEVIEW_CURSOR_GUARD_WM,
570 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300571};
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300572static const struct intel_watermark_params i965_cursor_wm_info = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300573 .fifo_size = I965_CURSOR_FIFO,
574 .max_wm = I965_CURSOR_MAX_WM,
575 .default_wm = I965_CURSOR_DFT_WM,
576 .guard_size = 2,
577 .cacheline_size = I915_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300578};
579static const struct intel_watermark_params i945_wm_info = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300580 .fifo_size = I945_FIFO_SIZE,
581 .max_wm = I915_MAX_WM,
582 .default_wm = 1,
583 .guard_size = 2,
584 .cacheline_size = I915_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300585};
586static const struct intel_watermark_params i915_wm_info = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300587 .fifo_size = I915_FIFO_SIZE,
588 .max_wm = I915_MAX_WM,
589 .default_wm = 1,
590 .guard_size = 2,
591 .cacheline_size = I915_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300592};
Ville Syrjälä9d539102014-08-15 01:21:53 +0300593static const struct intel_watermark_params i830_a_wm_info = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300594 .fifo_size = I855GM_FIFO_SIZE,
595 .max_wm = I915_MAX_WM,
596 .default_wm = 1,
597 .guard_size = 2,
598 .cacheline_size = I830_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300599};
Ville Syrjälä9d539102014-08-15 01:21:53 +0300600static const struct intel_watermark_params i830_bc_wm_info = {
601 .fifo_size = I855GM_FIFO_SIZE,
602 .max_wm = I915_MAX_WM/2,
603 .default_wm = 1,
604 .guard_size = 2,
605 .cacheline_size = I830_FIFO_LINE_SIZE,
606};
Daniel Vetterfeb56b92013-12-14 20:38:30 -0200607static const struct intel_watermark_params i845_wm_info = {
Ville Syrjäläe0f02732014-06-05 19:15:50 +0300608 .fifo_size = I830_FIFO_SIZE,
609 .max_wm = I915_MAX_WM,
610 .default_wm = 1,
611 .guard_size = 2,
612 .cacheline_size = I830_FIFO_LINE_SIZE,
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300613};
614
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300615/**
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300616 * intel_wm_method1 - Method 1 / "small buffer" watermark formula
617 * @pixel_rate: Pipe pixel rate in kHz
618 * @cpp: Plane bytes per pixel
619 * @latency: Memory wakeup latency in 0.1us units
620 *
621 * Compute the watermark using the method 1 or "small buffer"
622 * formula. The caller may additonally add extra cachelines
623 * to account for TLB misses and clock crossings.
624 *
625 * This method is concerned with the short term drain rate
626 * of the FIFO, ie. it does not account for blanking periods
627 * which would effectively reduce the average drain rate across
628 * a longer period. The name "small" refers to the fact the
629 * FIFO is relatively small compared to the amount of data
630 * fetched.
631 *
632 * The FIFO level vs. time graph might look something like:
633 *
634 * |\ |\
635 * | \ | \
636 * __---__---__ (- plane active, _ blanking)
637 * -> time
638 *
639 * or perhaps like this:
640 *
641 * |\|\ |\|\
642 * __----__----__ (- plane active, _ blanking)
643 * -> time
644 *
645 * Returns:
646 * The watermark in bytes
647 */
648static unsigned int intel_wm_method1(unsigned int pixel_rate,
649 unsigned int cpp,
650 unsigned int latency)
651{
Jani Nikula5ce9a6492019-01-18 14:01:20 +0200652 u64 ret;
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300653
Ville Syrjäläd492a292019-04-08 18:27:01 +0300654 ret = mul_u32_u32(pixel_rate, cpp * latency);
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300655 ret = DIV_ROUND_UP_ULL(ret, 10000);
656
657 return ret;
658}
659
660/**
661 * intel_wm_method2 - Method 2 / "large buffer" watermark formula
662 * @pixel_rate: Pipe pixel rate in kHz
663 * @htotal: Pipe horizontal total
664 * @width: Plane width in pixels
665 * @cpp: Plane bytes per pixel
666 * @latency: Memory wakeup latency in 0.1us units
667 *
668 * Compute the watermark using the method 2 or "large buffer"
669 * formula. The caller may additonally add extra cachelines
670 * to account for TLB misses and clock crossings.
671 *
672 * This method is concerned with the long term drain rate
673 * of the FIFO, ie. it does account for blanking periods
674 * which effectively reduce the average drain rate across
675 * a longer period. The name "large" refers to the fact the
676 * FIFO is relatively large compared to the amount of data
677 * fetched.
678 *
679 * The FIFO level vs. time graph might look something like:
680 *
681 * |\___ |\___
682 * | \___ | \___
683 * | \ | \
684 * __ --__--__--__--__--__--__ (- plane active, _ blanking)
685 * -> time
686 *
687 * Returns:
688 * The watermark in bytes
689 */
690static unsigned int intel_wm_method2(unsigned int pixel_rate,
691 unsigned int htotal,
692 unsigned int width,
693 unsigned int cpp,
694 unsigned int latency)
695{
696 unsigned int ret;
697
698 /*
699 * FIXME remove once all users are computing
700 * watermarks in the correct place.
701 */
702 if (WARN_ON_ONCE(htotal == 0))
703 htotal = 1;
704
705 ret = (latency * pixel_rate) / (htotal * 10000);
706 ret = (ret + 1) * width * cpp;
707
708 return ret;
709}
710
711/**
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300712 * intel_calculate_wm - calculate watermark level
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300713 * @pixel_rate: pixel clock
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300714 * @wm: chip FIFO params
Chris Wilson31383412018-02-14 14:03:03 +0000715 * @fifo_size: size of the FIFO buffer
Ville Syrjäläac484962016-01-20 21:05:26 +0200716 * @cpp: bytes per pixel
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300717 * @latency_ns: memory latency for the platform
718 *
719 * Calculate the watermark level (the level at which the display plane will
720 * start fetching from memory again). Each chip has a different display
721 * FIFO size and allocation, so the caller needs to figure that out and pass
722 * in the correct intel_watermark_params structure.
723 *
724 * As the pixel clock runs, the FIFO will be drained at a rate that depends
725 * on the pixel size. When it reaches the watermark level, it'll start
726 * fetching FIFO line sized based chunks from memory until the FIFO fills
727 * past the watermark point. If the FIFO drains completely, a FIFO underrun
728 * will occur, and a display engine hang could result.
729 */
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300730static unsigned int intel_calculate_wm(int pixel_rate,
731 const struct intel_watermark_params *wm,
732 int fifo_size, int cpp,
733 unsigned int latency_ns)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300734{
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300735 int entries, wm_size;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300736
737 /*
738 * Note: we need to make sure we don't overflow for various clock &
739 * latency values.
740 * clocks go from a few thousand to several hundred thousand.
741 * latency is usually a few thousand
742 */
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300743 entries = intel_wm_method1(pixel_rate, cpp,
744 latency_ns / 100);
745 entries = DIV_ROUND_UP(entries, wm->cacheline_size) +
746 wm->guard_size;
747 DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300748
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300749 wm_size = fifo_size - entries;
750 DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300751
752 /* Don't promote wm_size to unsigned... */
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300753 if (wm_size > wm->max_wm)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300754 wm_size = wm->max_wm;
755 if (wm_size <= 0)
756 wm_size = wm->default_wm;
Ville Syrjäläd6feb192014-09-05 21:54:13 +0300757
758 /*
759 * Bspec seems to indicate that the value shouldn't be lower than
760 * 'burst size + 1'. Certainly 830 is quite unhappy with low values.
761 * Lets go for 8 which is the burst size since certain platforms
762 * already use a hardcoded 8 (which is what the spec says should be
763 * done).
764 */
765 if (wm_size <= 8)
766 wm_size = 8;
767
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300768 return wm_size;
769}
770
Ville Syrjälä04548cb2017-04-21 21:14:29 +0300771static bool is_disabling(int old, int new, int threshold)
772{
773 return old >= threshold && new < threshold;
774}
775
776static bool is_enabling(int old, int new, int threshold)
777{
778 return old < threshold && new >= threshold;
779}
780
Ville Syrjälä6d5019b2017-04-21 21:14:20 +0300781static int intel_wm_num_levels(struct drm_i915_private *dev_priv)
782{
783 return dev_priv->wm.max_level + 1;
784}
785
Ville Syrjälä24304d812017-03-14 17:10:49 +0200786static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state,
787 const struct intel_plane_state *plane_state)
788{
789 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
790
791 /* FIXME check the 'enable' instead */
Maarten Lankhorst1326a922019-10-31 12:26:02 +0100792 if (!crtc_state->hw.active)
Ville Syrjälä24304d812017-03-14 17:10:49 +0200793 return false;
794
795 /*
796 * Treat cursor with fb as always visible since cursor updates
797 * can happen faster than the vrefresh rate, and the current
798 * watermark code doesn't handle that correctly. Cursor updates
799 * which set/clear the fb or change the cursor size are going
800 * to get throttled by intel_legacy_cursor_update() to work
801 * around this problem with the watermark code.
802 */
803 if (plane->id == PLANE_CURSOR)
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +0100804 return plane_state->hw.fb != NULL;
Ville Syrjälä24304d812017-03-14 17:10:49 +0200805 else
806 return plane_state->base.visible;
807}
808
Ville Syrjäläffc7a762016-10-31 22:37:21 +0200809static struct intel_crtc *single_enabled_crtc(struct drm_i915_private *dev_priv)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300810{
Ville Syrjäläefc26112016-10-31 22:37:04 +0200811 struct intel_crtc *crtc, *enabled = NULL;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300812
Ville Syrjäläffc7a762016-10-31 22:37:21 +0200813 for_each_intel_crtc(&dev_priv->drm, crtc) {
Ville Syrjäläefc26112016-10-31 22:37:04 +0200814 if (intel_crtc_active(crtc)) {
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300815 if (enabled)
816 return NULL;
817 enabled = crtc;
818 }
819 }
820
821 return enabled;
822}
823
Ville Syrjälä432081b2016-10-31 22:37:03 +0200824static void pineview_update_wm(struct intel_crtc *unused_crtc)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300825{
Ville Syrjäläffc7a762016-10-31 22:37:21 +0200826 struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev);
Ville Syrjäläefc26112016-10-31 22:37:04 +0200827 struct intel_crtc *crtc;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300828 const struct cxsr_latency *latency;
829 u32 reg;
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +0300830 unsigned int wm;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300831
Tvrtko Ursulin86d35d42019-03-26 07:40:54 +0000832 latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv),
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +0100833 dev_priv->is_ddr3,
834 dev_priv->fsb_freq,
835 dev_priv->mem_freq);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300836 if (!latency) {
837 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
Imre Deak5209b1f2014-07-01 12:36:17 +0300838 intel_set_memory_cxsr(dev_priv, false);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300839 return;
840 }
841
Ville Syrjäläffc7a762016-10-31 22:37:21 +0200842 crtc = single_enabled_crtc(dev_priv);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300843 if (crtc) {
Ville Syrjäläefc26112016-10-31 22:37:04 +0200844 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +0100845 &crtc->config->hw.adjusted_mode;
Ville Syrjäläefc26112016-10-31 22:37:04 +0200846 const struct drm_framebuffer *fb =
847 crtc->base.primary->state->fb;
Ville Syrjälä353c8592016-12-14 23:30:57 +0200848 int cpp = fb->format->cpp[0];
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +0300849 int clock = adjusted_mode->crtc_clock;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300850
851 /* Display SR */
852 wm = intel_calculate_wm(clock, &pineview_display_wm,
853 pineview_display_wm.fifo_size,
Ville Syrjäläac484962016-01-20 21:05:26 +0200854 cpp, latency->display_sr);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300855 reg = I915_READ(DSPFW1);
856 reg &= ~DSPFW_SR_MASK;
Ville Syrjäläf4998962015-03-10 17:02:21 +0200857 reg |= FW_WM(wm, SR);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300858 I915_WRITE(DSPFW1, reg);
859 DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg);
860
861 /* cursor SR */
862 wm = intel_calculate_wm(clock, &pineview_cursor_wm,
863 pineview_display_wm.fifo_size,
Ville Syrjälä99834b12017-04-21 21:14:24 +0300864 4, latency->cursor_sr);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300865 reg = I915_READ(DSPFW3);
866 reg &= ~DSPFW_CURSOR_SR_MASK;
Ville Syrjäläf4998962015-03-10 17:02:21 +0200867 reg |= FW_WM(wm, CURSOR_SR);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300868 I915_WRITE(DSPFW3, reg);
869
870 /* Display HPLL off SR */
871 wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm,
872 pineview_display_hplloff_wm.fifo_size,
Ville Syrjäläac484962016-01-20 21:05:26 +0200873 cpp, latency->display_hpll_disable);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300874 reg = I915_READ(DSPFW3);
875 reg &= ~DSPFW_HPLL_SR_MASK;
Ville Syrjäläf4998962015-03-10 17:02:21 +0200876 reg |= FW_WM(wm, HPLL_SR);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300877 I915_WRITE(DSPFW3, reg);
878
879 /* cursor HPLL off SR */
880 wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm,
881 pineview_display_hplloff_wm.fifo_size,
Ville Syrjälä99834b12017-04-21 21:14:24 +0300882 4, latency->cursor_hpll_disable);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300883 reg = I915_READ(DSPFW3);
884 reg &= ~DSPFW_HPLL_CURSOR_MASK;
Ville Syrjäläf4998962015-03-10 17:02:21 +0200885 reg |= FW_WM(wm, HPLL_CURSOR);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300886 I915_WRITE(DSPFW3, reg);
887 DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg);
888
Imre Deak5209b1f2014-07-01 12:36:17 +0300889 intel_set_memory_cxsr(dev_priv, true);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300890 } else {
Imre Deak5209b1f2014-07-01 12:36:17 +0300891 intel_set_memory_cxsr(dev_priv, false);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300892 }
893}
894
Ville Syrjälä0f95ff82017-04-21 21:14:26 +0300895/*
896 * Documentation says:
897 * "If the line size is small, the TLB fetches can get in the way of the
898 * data fetches, causing some lag in the pixel data return which is not
899 * accounted for in the above formulas. The following adjustment only
900 * needs to be applied if eight whole lines fit in the buffer at once.
901 * The WM is adjusted upwards by the difference between the FIFO size
902 * and the size of 8 whole lines. This adjustment is always performed
903 * in the actual pixel depth regardless of whether FBC is enabled or not."
904 */
Chris Wilson1a1f1282017-11-07 14:03:38 +0000905static unsigned int g4x_tlb_miss_wa(int fifo_size, int width, int cpp)
Ville Syrjälä0f95ff82017-04-21 21:14:26 +0300906{
907 int tlb_miss = fifo_size * 64 - width * cpp * 8;
908
909 return max(0, tlb_miss);
910}
911
Ville Syrjälä04548cb2017-04-21 21:14:29 +0300912static void g4x_write_wm_values(struct drm_i915_private *dev_priv,
913 const struct g4x_wm_values *wm)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300914{
Ville Syrjäläe93329a2017-04-21 21:14:31 +0300915 enum pipe pipe;
916
917 for_each_pipe(dev_priv, pipe)
918 trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm);
919
Ville Syrjälä04548cb2017-04-21 21:14:29 +0300920 I915_WRITE(DSPFW1,
921 FW_WM(wm->sr.plane, SR) |
922 FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) |
923 FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) |
924 FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA));
925 I915_WRITE(DSPFW2,
926 (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) |
927 FW_WM(wm->sr.fbc, FBC_SR) |
928 FW_WM(wm->hpll.fbc, FBC_HPLL_SR) |
929 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) |
930 FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) |
931 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA));
932 I915_WRITE(DSPFW3,
933 (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) |
934 FW_WM(wm->sr.cursor, CURSOR_SR) |
935 FW_WM(wm->hpll.cursor, HPLL_CURSOR) |
936 FW_WM(wm->hpll.plane, HPLL_SR));
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300937
Ville Syrjälä04548cb2017-04-21 21:14:29 +0300938 POSTING_READ(DSPFW1);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -0300939}
940
Ville Syrjälä15665972015-03-10 16:16:28 +0200941#define FW_WM_VLV(value, plane) \
942 (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV)
943
Ville Syrjälä50f4cae2016-11-28 19:37:15 +0200944static void vlv_write_wm_values(struct drm_i915_private *dev_priv,
Ville Syrjälä0018fda2015-03-05 21:19:45 +0200945 const struct vlv_wm_values *wm)
946{
Ville Syrjälä50f4cae2016-11-28 19:37:15 +0200947 enum pipe pipe;
Ville Syrjälä0018fda2015-03-05 21:19:45 +0200948
Ville Syrjälä50f4cae2016-11-28 19:37:15 +0200949 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläc137d662017-03-02 19:15:06 +0200950 trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm);
951
Ville Syrjälä50f4cae2016-11-28 19:37:15 +0200952 I915_WRITE(VLV_DDL(pipe),
953 (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) |
954 (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) |
955 (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) |
956 (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT));
957 }
Ville Syrjälä0018fda2015-03-05 21:19:45 +0200958
Ville Syrjälä6fe6a7f2016-11-28 19:37:14 +0200959 /*
960 * Zero the (unused) WM1 watermarks, and also clear all the
961 * high order bits so that there are no out of bounds values
962 * present in the registers during the reprogramming.
963 */
964 I915_WRITE(DSPHOWM, 0);
965 I915_WRITE(DSPHOWM1, 0);
966 I915_WRITE(DSPFW4, 0);
967 I915_WRITE(DSPFW5, 0);
968 I915_WRITE(DSPFW6, 0);
969
Ville Syrjäläae801522015-03-05 21:19:49 +0200970 I915_WRITE(DSPFW1,
Ville Syrjälä15665972015-03-10 16:16:28 +0200971 FW_WM(wm->sr.plane, SR) |
Ville Syrjälä1b313892016-11-28 19:37:08 +0200972 FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) |
973 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) |
974 FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA));
Ville Syrjäläae801522015-03-05 21:19:49 +0200975 I915_WRITE(DSPFW2,
Ville Syrjälä1b313892016-11-28 19:37:08 +0200976 FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) |
977 FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) |
978 FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA));
Ville Syrjäläae801522015-03-05 21:19:49 +0200979 I915_WRITE(DSPFW3,
Ville Syrjälä15665972015-03-10 16:16:28 +0200980 FW_WM(wm->sr.cursor, CURSOR_SR));
Ville Syrjäläae801522015-03-05 21:19:49 +0200981
982 if (IS_CHERRYVIEW(dev_priv)) {
983 I915_WRITE(DSPFW7_CHV,
Ville Syrjälä1b313892016-11-28 19:37:08 +0200984 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) |
985 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC));
Ville Syrjäläae801522015-03-05 21:19:49 +0200986 I915_WRITE(DSPFW8_CHV,
Ville Syrjälä1b313892016-11-28 19:37:08 +0200987 FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) |
988 FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE));
Ville Syrjäläae801522015-03-05 21:19:49 +0200989 I915_WRITE(DSPFW9_CHV,
Ville Syrjälä1b313892016-11-28 19:37:08 +0200990 FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) |
991 FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC));
Ville Syrjäläae801522015-03-05 21:19:49 +0200992 I915_WRITE(DSPHOWM,
Ville Syrjälä15665972015-03-10 16:16:28 +0200993 FW_WM(wm->sr.plane >> 9, SR_HI) |
Ville Syrjälä1b313892016-11-28 19:37:08 +0200994 FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) |
995 FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) |
996 FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) |
997 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) |
998 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) |
999 FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) |
1000 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) |
1001 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) |
1002 FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY] >> 8, PLANEA_HI));
Ville Syrjäläae801522015-03-05 21:19:49 +02001003 } else {
1004 I915_WRITE(DSPFW7,
Ville Syrjälä1b313892016-11-28 19:37:08 +02001005 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) |
1006 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC));
Ville Syrjäläae801522015-03-05 21:19:49 +02001007 I915_WRITE(DSPHOWM,
Ville Syrjälä15665972015-03-10 16:16:28 +02001008 FW_WM(wm->sr.plane >> 9, SR_HI) |
Ville Syrjälä1b313892016-11-28 19:37:08 +02001009 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) |
1010 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) |
1011 FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) |
1012 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) |
1013 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) |
1014 FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY] >> 8, PLANEA_HI));
Ville Syrjäläae801522015-03-05 21:19:49 +02001015 }
1016
1017 POSTING_READ(DSPFW1);
Ville Syrjälä0018fda2015-03-05 21:19:45 +02001018}
1019
Ville Syrjälä15665972015-03-10 16:16:28 +02001020#undef FW_WM_VLV
1021
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001022static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv)
1023{
1024 /* all latencies in usec */
1025 dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5;
1026 dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12;
Ville Syrjälä79d94302017-04-21 21:14:30 +03001027 dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001028
Ville Syrjälä79d94302017-04-21 21:14:30 +03001029 dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001030}
1031
1032static int g4x_plane_fifo_size(enum plane_id plane_id, int level)
1033{
1034 /*
1035 * DSPCNTR[13] supposedly controls whether the
1036 * primary plane can use the FIFO space otherwise
1037 * reserved for the sprite plane. It's not 100% clear
1038 * what the actual FIFO size is, but it looks like we
1039 * can happily set both primary and sprite watermarks
1040 * up to 127 cachelines. So that would seem to mean
1041 * that either DSPCNTR[13] doesn't do anything, or that
1042 * the total FIFO is >= 256 cachelines in size. Either
1043 * way, we don't seem to have to worry about this
1044 * repartitioning as the maximum watermark value the
1045 * register can hold for each plane is lower than the
1046 * minimum FIFO size.
1047 */
1048 switch (plane_id) {
1049 case PLANE_CURSOR:
1050 return 63;
1051 case PLANE_PRIMARY:
1052 return level == G4X_WM_LEVEL_NORMAL ? 127 : 511;
1053 case PLANE_SPRITE0:
1054 return level == G4X_WM_LEVEL_NORMAL ? 127 : 0;
1055 default:
1056 MISSING_CASE(plane_id);
1057 return 0;
1058 }
1059}
1060
1061static int g4x_fbc_fifo_size(int level)
1062{
1063 switch (level) {
1064 case G4X_WM_LEVEL_SR:
1065 return 7;
1066 case G4X_WM_LEVEL_HPLL:
1067 return 15;
1068 default:
1069 MISSING_CASE(level);
1070 return 0;
1071 }
1072}
1073
Jani Nikula5ce9a6492019-01-18 14:01:20 +02001074static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state,
1075 const struct intel_plane_state *plane_state,
1076 int level)
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001077{
1078 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1079 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1080 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +01001081 &crtc_state->hw.adjusted_mode;
Chris Wilson1a1f1282017-11-07 14:03:38 +00001082 unsigned int latency = dev_priv->wm.pri_latency[level] * 10;
1083 unsigned int clock, htotal, cpp, width, wm;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001084
1085 if (latency == 0)
1086 return USHRT_MAX;
1087
1088 if (!intel_wm_plane_visible(crtc_state, plane_state))
1089 return 0;
1090
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01001091 cpp = plane_state->hw.fb->format->cpp[0];
Ville Syrjäläd56e8232019-07-03 23:08:22 +03001092
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001093 /*
1094 * Not 100% sure which way ELK should go here as the
1095 * spec only says CL/CTG should assume 32bpp and BW
1096 * doesn't need to. But as these things followed the
1097 * mobile vs. desktop lines on gen3 as well, let's
1098 * assume ELK doesn't need this.
1099 *
1100 * The spec also fails to list such a restriction for
1101 * the HPLL watermark, which seems a little strange.
1102 * Let's use 32bpp for the HPLL watermark as well.
1103 */
1104 if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY &&
1105 level != G4X_WM_LEVEL_NORMAL)
Ville Syrjäläd56e8232019-07-03 23:08:22 +03001106 cpp = max(cpp, 4u);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001107
1108 clock = adjusted_mode->crtc_clock;
1109 htotal = adjusted_mode->crtc_htotal;
1110
Maarten Lankhorst3a612762019-10-04 13:34:54 +02001111 width = drm_rect_width(&plane_state->base.dst);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001112
1113 if (plane->id == PLANE_CURSOR) {
1114 wm = intel_wm_method2(clock, htotal, width, cpp, latency);
1115 } else if (plane->id == PLANE_PRIMARY &&
1116 level == G4X_WM_LEVEL_NORMAL) {
1117 wm = intel_wm_method1(clock, cpp, latency);
1118 } else {
Chris Wilson1a1f1282017-11-07 14:03:38 +00001119 unsigned int small, large;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001120
1121 small = intel_wm_method1(clock, cpp, latency);
1122 large = intel_wm_method2(clock, htotal, width, cpp, latency);
1123
1124 wm = min(small, large);
1125 }
1126
1127 wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level),
1128 width, cpp);
1129
1130 wm = DIV_ROUND_UP(wm, 64) + 2;
1131
Chris Wilson1a1f1282017-11-07 14:03:38 +00001132 return min_t(unsigned int, wm, USHRT_MAX);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001133}
1134
1135static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state,
1136 int level, enum plane_id plane_id, u16 value)
1137{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001138 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001139 bool dirty = false;
1140
1141 for (; level < intel_wm_num_levels(dev_priv); level++) {
1142 struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1143
1144 dirty |= raw->plane[plane_id] != value;
1145 raw->plane[plane_id] = value;
1146 }
1147
1148 return dirty;
1149}
1150
1151static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state,
1152 int level, u16 value)
1153{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001154 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001155 bool dirty = false;
1156
1157 /* NORMAL level doesn't have an FBC watermark */
1158 level = max(level, G4X_WM_LEVEL_SR);
1159
1160 for (; level < intel_wm_num_levels(dev_priv); level++) {
1161 struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1162
1163 dirty |= raw->fbc != value;
1164 raw->fbc = value;
1165 }
1166
1167 return dirty;
1168}
1169
Maarten Lankhorstec193642019-06-28 10:55:17 +02001170static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state,
1171 const struct intel_plane_state *plane_state,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02001172 u32 pri_val);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001173
1174static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state,
1175 const struct intel_plane_state *plane_state)
1176{
1177 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1178 int num_levels = intel_wm_num_levels(to_i915(plane->base.dev));
1179 enum plane_id plane_id = plane->id;
1180 bool dirty = false;
1181 int level;
1182
1183 if (!intel_wm_plane_visible(crtc_state, plane_state)) {
1184 dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0);
1185 if (plane_id == PLANE_PRIMARY)
1186 dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0);
1187 goto out;
1188 }
1189
1190 for (level = 0; level < num_levels; level++) {
1191 struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1192 int wm, max_wm;
1193
1194 wm = g4x_compute_wm(crtc_state, plane_state, level);
1195 max_wm = g4x_plane_fifo_size(plane_id, level);
1196
1197 if (wm > max_wm)
1198 break;
1199
1200 dirty |= raw->plane[plane_id] != wm;
1201 raw->plane[plane_id] = wm;
1202
1203 if (plane_id != PLANE_PRIMARY ||
1204 level == G4X_WM_LEVEL_NORMAL)
1205 continue;
1206
1207 wm = ilk_compute_fbc_wm(crtc_state, plane_state,
1208 raw->plane[plane_id]);
1209 max_wm = g4x_fbc_fifo_size(level);
1210
1211 /*
1212 * FBC wm is not mandatory as we
1213 * can always just disable its use.
1214 */
1215 if (wm > max_wm)
1216 wm = USHRT_MAX;
1217
1218 dirty |= raw->fbc != wm;
1219 raw->fbc = wm;
1220 }
1221
1222 /* mark watermarks as invalid */
1223 dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX);
1224
1225 if (plane_id == PLANE_PRIMARY)
1226 dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX);
1227
1228 out:
1229 if (dirty) {
1230 DRM_DEBUG_KMS("%s watermarks: normal=%d, SR=%d, HPLL=%d\n",
1231 plane->base.name,
1232 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id],
1233 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id],
1234 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]);
1235
1236 if (plane_id == PLANE_PRIMARY)
1237 DRM_DEBUG_KMS("FBC watermarks: SR=%d, HPLL=%d\n",
1238 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc,
1239 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc);
1240 }
1241
1242 return dirty;
1243}
1244
1245static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state,
1246 enum plane_id plane_id, int level)
1247{
1248 const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1249
1250 return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level);
1251}
1252
1253static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state,
1254 int level)
1255{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001256 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001257
1258 if (level > dev_priv->wm.max_level)
1259 return false;
1260
1261 return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) &&
1262 g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) &&
1263 g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level);
1264}
1265
1266/* mark all levels starting from 'level' as invalid */
1267static void g4x_invalidate_wms(struct intel_crtc *crtc,
1268 struct g4x_wm_state *wm_state, int level)
1269{
1270 if (level <= G4X_WM_LEVEL_NORMAL) {
1271 enum plane_id plane_id;
1272
1273 for_each_plane_id_on_crtc(crtc, plane_id)
1274 wm_state->wm.plane[plane_id] = USHRT_MAX;
1275 }
1276
1277 if (level <= G4X_WM_LEVEL_SR) {
1278 wm_state->cxsr = false;
1279 wm_state->sr.cursor = USHRT_MAX;
1280 wm_state->sr.plane = USHRT_MAX;
1281 wm_state->sr.fbc = USHRT_MAX;
1282 }
1283
1284 if (level <= G4X_WM_LEVEL_HPLL) {
1285 wm_state->hpll_en = false;
1286 wm_state->hpll.cursor = USHRT_MAX;
1287 wm_state->hpll.plane = USHRT_MAX;
1288 wm_state->hpll.fbc = USHRT_MAX;
1289 }
1290}
1291
1292static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state)
1293{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001294 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001295 struct intel_atomic_state *state =
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001296 to_intel_atomic_state(crtc_state->uapi.state);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001297 struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal;
Ville Syrjälä0b14d962019-08-21 20:30:33 +03001298 int num_active_planes = hweight8(crtc_state->active_planes &
1299 ~BIT(PLANE_CURSOR));
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001300 const struct g4x_pipe_wm *raw;
Ville Syrjälä7b5104512017-08-23 18:22:22 +03001301 const struct intel_plane_state *old_plane_state;
1302 const struct intel_plane_state *new_plane_state;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001303 struct intel_plane *plane;
1304 enum plane_id plane_id;
1305 int i, level;
1306 unsigned int dirty = 0;
1307
Ville Syrjälä7b5104512017-08-23 18:22:22 +03001308 for_each_oldnew_intel_plane_in_state(state, plane,
1309 old_plane_state,
1310 new_plane_state, i) {
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01001311 if (new_plane_state->hw.crtc != &crtc->base &&
1312 old_plane_state->hw.crtc != &crtc->base)
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001313 continue;
1314
Ville Syrjälä7b5104512017-08-23 18:22:22 +03001315 if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state))
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001316 dirty |= BIT(plane->id);
1317 }
1318
1319 if (!dirty)
1320 return 0;
1321
1322 level = G4X_WM_LEVEL_NORMAL;
1323 if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1324 goto out;
1325
1326 raw = &crtc_state->wm.g4x.raw[level];
1327 for_each_plane_id_on_crtc(crtc, plane_id)
1328 wm_state->wm.plane[plane_id] = raw->plane[plane_id];
1329
1330 level = G4X_WM_LEVEL_SR;
1331
1332 if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1333 goto out;
1334
1335 raw = &crtc_state->wm.g4x.raw[level];
1336 wm_state->sr.plane = raw->plane[PLANE_PRIMARY];
1337 wm_state->sr.cursor = raw->plane[PLANE_CURSOR];
1338 wm_state->sr.fbc = raw->fbc;
1339
1340 wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY);
1341
1342 level = G4X_WM_LEVEL_HPLL;
1343
1344 if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1345 goto out;
1346
1347 raw = &crtc_state->wm.g4x.raw[level];
1348 wm_state->hpll.plane = raw->plane[PLANE_PRIMARY];
1349 wm_state->hpll.cursor = raw->plane[PLANE_CURSOR];
1350 wm_state->hpll.fbc = raw->fbc;
1351
1352 wm_state->hpll_en = wm_state->cxsr;
1353
1354 level++;
1355
1356 out:
1357 if (level == G4X_WM_LEVEL_NORMAL)
1358 return -EINVAL;
1359
1360 /* invalidate the higher levels */
1361 g4x_invalidate_wms(crtc, wm_state, level);
1362
1363 /*
1364 * Determine if the FBC watermark(s) can be used. IF
1365 * this isn't the case we prefer to disable the FBC
1366 ( watermark(s) rather than disable the SR/HPLL
1367 * level(s) entirely.
1368 */
1369 wm_state->fbc_en = level > G4X_WM_LEVEL_NORMAL;
1370
1371 if (level >= G4X_WM_LEVEL_SR &&
1372 wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR))
1373 wm_state->fbc_en = false;
1374 else if (level >= G4X_WM_LEVEL_HPLL &&
1375 wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL))
1376 wm_state->fbc_en = false;
1377
1378 return 0;
1379}
1380
Matt Ropercd1d3ee2018-12-10 13:54:14 -08001381static int g4x_compute_intermediate_wm(struct intel_crtc_state *new_crtc_state)
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001382{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001383 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
Maarten Lankhorst248c2432017-11-15 17:31:57 +01001384 struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate;
1385 const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal;
1386 struct intel_atomic_state *intel_state =
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001387 to_intel_atomic_state(new_crtc_state->uapi.state);
Maarten Lankhorst248c2432017-11-15 17:31:57 +01001388 const struct intel_crtc_state *old_crtc_state =
1389 intel_atomic_get_old_crtc_state(intel_state, crtc);
1390 const struct g4x_wm_state *active = &old_crtc_state->wm.g4x.optimal;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001391 enum plane_id plane_id;
1392
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001393 if (!new_crtc_state->hw.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) {
Maarten Lankhorst248c2432017-11-15 17:31:57 +01001394 *intermediate = *optimal;
1395
1396 intermediate->cxsr = false;
1397 intermediate->hpll_en = false;
1398 goto out;
1399 }
1400
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001401 intermediate->cxsr = optimal->cxsr && active->cxsr &&
Maarten Lankhorst248c2432017-11-15 17:31:57 +01001402 !new_crtc_state->disable_cxsr;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001403 intermediate->hpll_en = optimal->hpll_en && active->hpll_en &&
Maarten Lankhorst248c2432017-11-15 17:31:57 +01001404 !new_crtc_state->disable_cxsr;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001405 intermediate->fbc_en = optimal->fbc_en && active->fbc_en;
1406
1407 for_each_plane_id_on_crtc(crtc, plane_id) {
1408 intermediate->wm.plane[plane_id] =
1409 max(optimal->wm.plane[plane_id],
1410 active->wm.plane[plane_id]);
1411
1412 WARN_ON(intermediate->wm.plane[plane_id] >
1413 g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL));
1414 }
1415
1416 intermediate->sr.plane = max(optimal->sr.plane,
1417 active->sr.plane);
1418 intermediate->sr.cursor = max(optimal->sr.cursor,
1419 active->sr.cursor);
1420 intermediate->sr.fbc = max(optimal->sr.fbc,
1421 active->sr.fbc);
1422
1423 intermediate->hpll.plane = max(optimal->hpll.plane,
1424 active->hpll.plane);
1425 intermediate->hpll.cursor = max(optimal->hpll.cursor,
1426 active->hpll.cursor);
1427 intermediate->hpll.fbc = max(optimal->hpll.fbc,
1428 active->hpll.fbc);
1429
1430 WARN_ON((intermediate->sr.plane >
1431 g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) ||
1432 intermediate->sr.cursor >
1433 g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) &&
1434 intermediate->cxsr);
1435 WARN_ON((intermediate->sr.plane >
1436 g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) ||
1437 intermediate->sr.cursor >
1438 g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) &&
1439 intermediate->hpll_en);
1440
1441 WARN_ON(intermediate->sr.fbc > g4x_fbc_fifo_size(1) &&
1442 intermediate->fbc_en && intermediate->cxsr);
1443 WARN_ON(intermediate->hpll.fbc > g4x_fbc_fifo_size(2) &&
1444 intermediate->fbc_en && intermediate->hpll_en);
1445
Maarten Lankhorst248c2432017-11-15 17:31:57 +01001446out:
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001447 /*
1448 * If our intermediate WM are identical to the final WM, then we can
1449 * omit the post-vblank programming; only update if it's different.
1450 */
1451 if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0)
Maarten Lankhorst248c2432017-11-15 17:31:57 +01001452 new_crtc_state->wm.need_postvbl_update = true;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001453
1454 return 0;
1455}
1456
1457static void g4x_merge_wm(struct drm_i915_private *dev_priv,
1458 struct g4x_wm_values *wm)
1459{
1460 struct intel_crtc *crtc;
Ville Syrjäläc08e9132019-08-21 20:30:32 +03001461 int num_active_pipes = 0;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001462
1463 wm->cxsr = true;
1464 wm->hpll_en = true;
1465 wm->fbc_en = true;
1466
1467 for_each_intel_crtc(&dev_priv->drm, crtc) {
1468 const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x;
1469
1470 if (!crtc->active)
1471 continue;
1472
1473 if (!wm_state->cxsr)
1474 wm->cxsr = false;
1475 if (!wm_state->hpll_en)
1476 wm->hpll_en = false;
1477 if (!wm_state->fbc_en)
1478 wm->fbc_en = false;
1479
Ville Syrjäläc08e9132019-08-21 20:30:32 +03001480 num_active_pipes++;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001481 }
1482
Ville Syrjäläc08e9132019-08-21 20:30:32 +03001483 if (num_active_pipes != 1) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001484 wm->cxsr = false;
1485 wm->hpll_en = false;
1486 wm->fbc_en = false;
1487 }
1488
1489 for_each_intel_crtc(&dev_priv->drm, crtc) {
1490 const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x;
1491 enum pipe pipe = crtc->pipe;
1492
1493 wm->pipe[pipe] = wm_state->wm;
1494 if (crtc->active && wm->cxsr)
1495 wm->sr = wm_state->sr;
1496 if (crtc->active && wm->hpll_en)
1497 wm->hpll = wm_state->hpll;
1498 }
1499}
1500
1501static void g4x_program_watermarks(struct drm_i915_private *dev_priv)
1502{
1503 struct g4x_wm_values *old_wm = &dev_priv->wm.g4x;
1504 struct g4x_wm_values new_wm = {};
1505
1506 g4x_merge_wm(dev_priv, &new_wm);
1507
1508 if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0)
1509 return;
1510
1511 if (is_disabling(old_wm->cxsr, new_wm.cxsr, true))
1512 _intel_set_memory_cxsr(dev_priv, false);
1513
1514 g4x_write_wm_values(dev_priv, &new_wm);
1515
1516 if (is_enabling(old_wm->cxsr, new_wm.cxsr, true))
1517 _intel_set_memory_cxsr(dev_priv, true);
1518
1519 *old_wm = new_wm;
1520}
1521
1522static void g4x_initial_watermarks(struct intel_atomic_state *state,
1523 struct intel_crtc_state *crtc_state)
1524{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001525 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1526 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001527
1528 mutex_lock(&dev_priv->wm.wm_mutex);
1529 crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate;
1530 g4x_program_watermarks(dev_priv);
1531 mutex_unlock(&dev_priv->wm.wm_mutex);
1532}
1533
1534static void g4x_optimize_watermarks(struct intel_atomic_state *state,
1535 struct intel_crtc_state *crtc_state)
1536{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001537 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1538 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001539
1540 if (!crtc_state->wm.need_postvbl_update)
1541 return;
1542
1543 mutex_lock(&dev_priv->wm.wm_mutex);
Ville Syrjälä88016a92019-07-01 19:05:45 +03001544 crtc->wm.active.g4x = crtc_state->wm.g4x.optimal;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03001545 g4x_program_watermarks(dev_priv);
1546 mutex_unlock(&dev_priv->wm.wm_mutex);
1547}
1548
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001549/* latency must be in 0.1us units. */
1550static unsigned int vlv_wm_method2(unsigned int pixel_rate,
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03001551 unsigned int htotal,
1552 unsigned int width,
Ville Syrjäläac484962016-01-20 21:05:26 +02001553 unsigned int cpp,
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001554 unsigned int latency)
1555{
1556 unsigned int ret;
1557
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03001558 ret = intel_wm_method2(pixel_rate, htotal,
1559 width, cpp, latency);
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001560 ret = DIV_ROUND_UP(ret, 64);
1561
1562 return ret;
1563}
1564
Ville Syrjäläbb726512016-10-31 22:37:24 +02001565static void vlv_setup_wm_latency(struct drm_i915_private *dev_priv)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001566{
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001567 /* all latencies in usec */
1568 dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3;
1569
Ville Syrjälä58590c12015-09-08 21:05:12 +03001570 dev_priv->wm.max_level = VLV_WM_LEVEL_PM2;
1571
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001572 if (IS_CHERRYVIEW(dev_priv)) {
1573 dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12;
1574 dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33;
Ville Syrjälä58590c12015-09-08 21:05:12 +03001575
1576 dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001577 }
1578}
1579
Jani Nikula5ce9a6492019-01-18 14:01:20 +02001580static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state,
1581 const struct intel_plane_state *plane_state,
1582 int level)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001583{
Ville Syrjäläe339d672016-11-28 19:37:17 +02001584 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001585 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläe339d672016-11-28 19:37:17 +02001586 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +01001587 &crtc_state->hw.adjusted_mode;
Chris Wilson1a1f1282017-11-07 14:03:38 +00001588 unsigned int clock, htotal, cpp, width, wm;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001589
1590 if (dev_priv->wm.pri_latency[level] == 0)
1591 return USHRT_MAX;
1592
Ville Syrjäläa07102f2017-03-03 17:19:27 +02001593 if (!intel_wm_plane_visible(crtc_state, plane_state))
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001594 return 0;
1595
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01001596 cpp = plane_state->hw.fb->format->cpp[0];
Ville Syrjäläe339d672016-11-28 19:37:17 +02001597 clock = adjusted_mode->crtc_clock;
1598 htotal = adjusted_mode->crtc_htotal;
1599 width = crtc_state->pipe_src_w;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001600
Ville Syrjälä709f3fc2017-03-03 17:19:26 +02001601 if (plane->id == PLANE_CURSOR) {
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001602 /*
1603 * FIXME the formula gives values that are
1604 * too big for the cursor FIFO, and hence we
1605 * would never be able to use cursors. For
1606 * now just hardcode the watermark.
1607 */
1608 wm = 63;
1609 } else {
Ville Syrjäläac484962016-01-20 21:05:26 +02001610 wm = vlv_wm_method2(clock, htotal, width, cpp,
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001611 dev_priv->wm.pri_latency[level] * 10);
1612 }
1613
Chris Wilson1a1f1282017-11-07 14:03:38 +00001614 return min_t(unsigned int, wm, USHRT_MAX);
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001615}
1616
Ville Syrjälä1a10ae62017-03-02 19:15:03 +02001617static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes)
1618{
1619 return (active_planes & (BIT(PLANE_SPRITE0) |
1620 BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1);
1621}
1622
Ville Syrjälä5012e602017-03-02 19:14:56 +02001623static int vlv_compute_fifo(struct intel_crtc_state *crtc_state)
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001624{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001625 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjälä114d7dc2017-04-21 21:14:21 +03001626 const struct g4x_pipe_wm *raw =
Ville Syrjälä5012e602017-03-02 19:14:56 +02001627 &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2];
Ville Syrjälä814e7f02017-03-02 19:14:55 +02001628 struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state;
Ville Syrjälä5012e602017-03-02 19:14:56 +02001629 unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
Ville Syrjälä0b14d962019-08-21 20:30:33 +03001630 int num_active_planes = hweight8(active_planes);
Ville Syrjälä5012e602017-03-02 19:14:56 +02001631 const int fifo_size = 511;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001632 int fifo_extra, fifo_left = fifo_size;
Ville Syrjälä1a10ae62017-03-02 19:15:03 +02001633 int sprite0_fifo_extra = 0;
Ville Syrjälä5012e602017-03-02 19:14:56 +02001634 unsigned int total_rate;
1635 enum plane_id plane_id;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001636
Ville Syrjälä1a10ae62017-03-02 19:15:03 +02001637 /*
1638 * When enabling sprite0 after sprite1 has already been enabled
1639 * we tend to get an underrun unless sprite0 already has some
1640 * FIFO space allcoated. Hence we always allocate at least one
1641 * cacheline for sprite0 whenever sprite1 is enabled.
1642 *
1643 * All other plane enable sequences appear immune to this problem.
1644 */
1645 if (vlv_need_sprite0_fifo_workaround(active_planes))
1646 sprite0_fifo_extra = 1;
1647
Ville Syrjälä5012e602017-03-02 19:14:56 +02001648 total_rate = raw->plane[PLANE_PRIMARY] +
1649 raw->plane[PLANE_SPRITE0] +
Ville Syrjälä1a10ae62017-03-02 19:15:03 +02001650 raw->plane[PLANE_SPRITE1] +
1651 sprite0_fifo_extra;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001652
Ville Syrjälä5012e602017-03-02 19:14:56 +02001653 if (total_rate > fifo_size)
1654 return -EINVAL;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001655
Ville Syrjälä5012e602017-03-02 19:14:56 +02001656 if (total_rate == 0)
1657 total_rate = 1;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001658
Ville Syrjälä5012e602017-03-02 19:14:56 +02001659 for_each_plane_id_on_crtc(crtc, plane_id) {
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001660 unsigned int rate;
1661
Ville Syrjälä5012e602017-03-02 19:14:56 +02001662 if ((active_planes & BIT(plane_id)) == 0) {
1663 fifo_state->plane[plane_id] = 0;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001664 continue;
1665 }
1666
Ville Syrjälä5012e602017-03-02 19:14:56 +02001667 rate = raw->plane[plane_id];
1668 fifo_state->plane[plane_id] = fifo_size * rate / total_rate;
1669 fifo_left -= fifo_state->plane[plane_id];
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001670 }
1671
Ville Syrjälä1a10ae62017-03-02 19:15:03 +02001672 fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra;
1673 fifo_left -= sprite0_fifo_extra;
1674
Ville Syrjälä5012e602017-03-02 19:14:56 +02001675 fifo_state->plane[PLANE_CURSOR] = 63;
1676
1677 fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001678
1679 /* spread the remainder evenly */
Ville Syrjälä5012e602017-03-02 19:14:56 +02001680 for_each_plane_id_on_crtc(crtc, plane_id) {
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001681 int plane_extra;
1682
1683 if (fifo_left == 0)
1684 break;
1685
Ville Syrjälä5012e602017-03-02 19:14:56 +02001686 if ((active_planes & BIT(plane_id)) == 0)
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001687 continue;
1688
1689 plane_extra = min(fifo_extra, fifo_left);
Ville Syrjälä5012e602017-03-02 19:14:56 +02001690 fifo_state->plane[plane_id] += plane_extra;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001691 fifo_left -= plane_extra;
1692 }
1693
Ville Syrjälä5012e602017-03-02 19:14:56 +02001694 WARN_ON(active_planes != 0 && fifo_left != 0);
1695
1696 /* give it all to the first plane if none are active */
1697 if (active_planes == 0) {
1698 WARN_ON(fifo_left != fifo_size);
1699 fifo_state->plane[PLANE_PRIMARY] = fifo_left;
1700 }
1701
1702 return 0;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001703}
1704
Ville Syrjäläff32c542017-03-02 19:14:57 +02001705/* mark all levels starting from 'level' as invalid */
1706static void vlv_invalidate_wms(struct intel_crtc *crtc,
1707 struct vlv_wm_state *wm_state, int level)
1708{
1709 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1710
Ville Syrjälä6d5019b2017-04-21 21:14:20 +03001711 for (; level < intel_wm_num_levels(dev_priv); level++) {
Ville Syrjäläff32c542017-03-02 19:14:57 +02001712 enum plane_id plane_id;
1713
1714 for_each_plane_id_on_crtc(crtc, plane_id)
1715 wm_state->wm[level].plane[plane_id] = USHRT_MAX;
1716
1717 wm_state->sr[level].cursor = USHRT_MAX;
1718 wm_state->sr[level].plane = USHRT_MAX;
1719 }
1720}
1721
Ville Syrjälä26cca0e2016-11-28 19:37:09 +02001722static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size)
1723{
1724 if (wm > fifo_size)
1725 return USHRT_MAX;
1726 else
1727 return fifo_size - wm;
1728}
1729
Ville Syrjäläff32c542017-03-02 19:14:57 +02001730/*
1731 * Starting from 'level' set all higher
1732 * levels to 'value' in the "raw" watermarks.
1733 */
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001734static bool vlv_raw_plane_wm_set(struct intel_crtc_state *crtc_state,
Ville Syrjäläff32c542017-03-02 19:14:57 +02001735 int level, enum plane_id plane_id, u16 value)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001736{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001737 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
Ville Syrjälä6d5019b2017-04-21 21:14:20 +03001738 int num_levels = intel_wm_num_levels(dev_priv);
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001739 bool dirty = false;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001740
Ville Syrjäläff32c542017-03-02 19:14:57 +02001741 for (; level < num_levels; level++) {
Ville Syrjälä114d7dc2017-04-21 21:14:21 +03001742 struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001743
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001744 dirty |= raw->plane[plane_id] != value;
Ville Syrjäläff32c542017-03-02 19:14:57 +02001745 raw->plane[plane_id] = value;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001746 }
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001747
1748 return dirty;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001749}
1750
Ville Syrjälä77d14ee2017-04-21 21:14:18 +03001751static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state,
1752 const struct intel_plane_state *plane_state)
Ville Syrjäläff32c542017-03-02 19:14:57 +02001753{
1754 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
1755 enum plane_id plane_id = plane->id;
Ville Syrjälä6d5019b2017-04-21 21:14:20 +03001756 int num_levels = intel_wm_num_levels(to_i915(plane->base.dev));
Ville Syrjäläff32c542017-03-02 19:14:57 +02001757 int level;
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001758 bool dirty = false;
Ville Syrjäläff32c542017-03-02 19:14:57 +02001759
Ville Syrjäläa07102f2017-03-03 17:19:27 +02001760 if (!intel_wm_plane_visible(crtc_state, plane_state)) {
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001761 dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0);
1762 goto out;
Ville Syrjäläff32c542017-03-02 19:14:57 +02001763 }
1764
1765 for (level = 0; level < num_levels; level++) {
Ville Syrjälä114d7dc2017-04-21 21:14:21 +03001766 struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
Ville Syrjäläff32c542017-03-02 19:14:57 +02001767 int wm = vlv_compute_wm_level(crtc_state, plane_state, level);
1768 int max_wm = plane_id == PLANE_CURSOR ? 63 : 511;
1769
Ville Syrjäläff32c542017-03-02 19:14:57 +02001770 if (wm > max_wm)
1771 break;
1772
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001773 dirty |= raw->plane[plane_id] != wm;
Ville Syrjäläff32c542017-03-02 19:14:57 +02001774 raw->plane[plane_id] = wm;
1775 }
1776
1777 /* mark all higher levels as invalid */
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001778 dirty |= vlv_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX);
Ville Syrjäläff32c542017-03-02 19:14:57 +02001779
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001780out:
1781 if (dirty)
Ville Syrjälä57a65282017-04-21 21:14:22 +03001782 DRM_DEBUG_KMS("%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n",
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001783 plane->base.name,
1784 crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id],
1785 crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id],
1786 crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]);
1787
1788 return dirty;
Ville Syrjäläff32c542017-03-02 19:14:57 +02001789}
1790
Ville Syrjälä77d14ee2017-04-21 21:14:18 +03001791static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state,
1792 enum plane_id plane_id, int level)
Ville Syrjäläff32c542017-03-02 19:14:57 +02001793{
Ville Syrjälä114d7dc2017-04-21 21:14:21 +03001794 const struct g4x_pipe_wm *raw =
Ville Syrjäläff32c542017-03-02 19:14:57 +02001795 &crtc_state->wm.vlv.raw[level];
1796 const struct vlv_fifo_state *fifo_state =
1797 &crtc_state->wm.vlv.fifo_state;
1798
1799 return raw->plane[plane_id] <= fifo_state->plane[plane_id];
1800}
1801
Ville Syrjälä77d14ee2017-04-21 21:14:18 +03001802static bool vlv_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, int level)
Ville Syrjäläff32c542017-03-02 19:14:57 +02001803{
Ville Syrjälä77d14ee2017-04-21 21:14:18 +03001804 return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) &&
1805 vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) &&
1806 vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) &&
1807 vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level);
Ville Syrjäläff32c542017-03-02 19:14:57 +02001808}
1809
1810static int vlv_compute_pipe_wm(struct intel_crtc_state *crtc_state)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001811{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001812 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjälä7c951c02016-11-28 19:37:10 +02001813 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläff32c542017-03-02 19:14:57 +02001814 struct intel_atomic_state *state =
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001815 to_intel_atomic_state(crtc_state->uapi.state);
Ville Syrjälä855c79f2017-03-02 19:14:54 +02001816 struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal;
Ville Syrjäläff32c542017-03-02 19:14:57 +02001817 const struct vlv_fifo_state *fifo_state =
1818 &crtc_state->wm.vlv.fifo_state;
Ville Syrjälä0b14d962019-08-21 20:30:33 +03001819 int num_active_planes = hweight8(crtc_state->active_planes &
1820 ~BIT(PLANE_CURSOR));
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001821 bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->uapi);
Ville Syrjälä7b5104512017-08-23 18:22:22 +03001822 const struct intel_plane_state *old_plane_state;
1823 const struct intel_plane_state *new_plane_state;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001824 struct intel_plane *plane;
Ville Syrjäläff32c542017-03-02 19:14:57 +02001825 enum plane_id plane_id;
1826 int level, ret, i;
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001827 unsigned int dirty = 0;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001828
Ville Syrjälä7b5104512017-08-23 18:22:22 +03001829 for_each_oldnew_intel_plane_in_state(state, plane,
1830 old_plane_state,
1831 new_plane_state, i) {
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01001832 if (new_plane_state->hw.crtc != &crtc->base &&
1833 old_plane_state->hw.crtc != &crtc->base)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001834 continue;
1835
Ville Syrjälä7b5104512017-08-23 18:22:22 +03001836 if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state))
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001837 dirty |= BIT(plane->id);
1838 }
1839
1840 /*
1841 * DSPARB registers may have been reset due to the
1842 * power well being turned off. Make sure we restore
1843 * them to a consistent state even if no primary/sprite
1844 * planes are initially active.
1845 */
1846 if (needs_modeset)
1847 crtc_state->fifo_changed = true;
1848
1849 if (!dirty)
1850 return 0;
1851
1852 /* cursor changes don't warrant a FIFO recompute */
1853 if (dirty & ~BIT(PLANE_CURSOR)) {
1854 const struct intel_crtc_state *old_crtc_state =
Ville Syrjälä7b5104512017-08-23 18:22:22 +03001855 intel_atomic_get_old_crtc_state(state, crtc);
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001856 const struct vlv_fifo_state *old_fifo_state =
1857 &old_crtc_state->wm.vlv.fifo_state;
1858
1859 ret = vlv_compute_fifo(crtc_state);
1860 if (ret)
1861 return ret;
1862
1863 if (needs_modeset ||
1864 memcmp(old_fifo_state, fifo_state,
1865 sizeof(*fifo_state)) != 0)
1866 crtc_state->fifo_changed = true;
Ville Syrjälä5012e602017-03-02 19:14:56 +02001867 }
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001868
Ville Syrjäläff32c542017-03-02 19:14:57 +02001869 /* initially allow all levels */
Ville Syrjälä6d5019b2017-04-21 21:14:20 +03001870 wm_state->num_levels = intel_wm_num_levels(dev_priv);
Ville Syrjäläff32c542017-03-02 19:14:57 +02001871 /*
1872 * Note that enabling cxsr with no primary/sprite planes
1873 * enabled can wedge the pipe. Hence we only allow cxsr
1874 * with exactly one enabled primary/sprite plane.
1875 */
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02001876 wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1;
Ville Syrjäläff32c542017-03-02 19:14:57 +02001877
Ville Syrjälä5012e602017-03-02 19:14:56 +02001878 for (level = 0; level < wm_state->num_levels; level++) {
Ville Syrjälä114d7dc2017-04-21 21:14:21 +03001879 const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
Jani Nikula24977872019-09-11 12:26:08 +03001880 const int sr_fifo_size = INTEL_NUM_PIPES(dev_priv) * 512 - 1;
Ville Syrjälä5012e602017-03-02 19:14:56 +02001881
Ville Syrjälä77d14ee2017-04-21 21:14:18 +03001882 if (!vlv_raw_crtc_wm_is_valid(crtc_state, level))
Ville Syrjäläff32c542017-03-02 19:14:57 +02001883 break;
Ville Syrjälä5012e602017-03-02 19:14:56 +02001884
Ville Syrjäläff32c542017-03-02 19:14:57 +02001885 for_each_plane_id_on_crtc(crtc, plane_id) {
1886 wm_state->wm[level].plane[plane_id] =
1887 vlv_invert_wm_value(raw->plane[plane_id],
1888 fifo_state->plane[plane_id]);
1889 }
1890
1891 wm_state->sr[level].plane =
1892 vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY],
Ville Syrjälä5012e602017-03-02 19:14:56 +02001893 raw->plane[PLANE_SPRITE0],
Ville Syrjäläff32c542017-03-02 19:14:57 +02001894 raw->plane[PLANE_SPRITE1]),
1895 sr_fifo_size);
1896
1897 wm_state->sr[level].cursor =
1898 vlv_invert_wm_value(raw->plane[PLANE_CURSOR],
1899 63);
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001900 }
1901
Ville Syrjäläff32c542017-03-02 19:14:57 +02001902 if (level == 0)
1903 return -EINVAL;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001904
Ville Syrjäläff32c542017-03-02 19:14:57 +02001905 /* limit to only levels we can actually handle */
1906 wm_state->num_levels = level;
1907
1908 /* invalidate the higher levels */
1909 vlv_invalidate_wms(crtc, wm_state, level);
1910
1911 return 0;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03001912}
1913
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001914#define VLV_FIFO(plane, value) \
1915 (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV)
1916
Ville Syrjäläff32c542017-03-02 19:14:57 +02001917static void vlv_atomic_update_fifo(struct intel_atomic_state *state,
1918 struct intel_crtc_state *crtc_state)
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001919{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01001920 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjäläf07d43d2017-03-02 19:14:52 +02001921 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01001922 struct intel_uncore *uncore = &dev_priv->uncore;
Ville Syrjälä814e7f02017-03-02 19:14:55 +02001923 const struct vlv_fifo_state *fifo_state =
1924 &crtc_state->wm.vlv.fifo_state;
Ville Syrjäläf07d43d2017-03-02 19:14:52 +02001925 int sprite0_start, sprite1_start, fifo_size;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001926
Ville Syrjälä236c48e2017-03-02 19:14:58 +02001927 if (!crtc_state->fifo_changed)
1928 return;
1929
Ville Syrjäläf07d43d2017-03-02 19:14:52 +02001930 sprite0_start = fifo_state->plane[PLANE_PRIMARY];
1931 sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start;
1932 fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001933
Ville Syrjäläf07d43d2017-03-02 19:14:52 +02001934 WARN_ON(fifo_state->plane[PLANE_CURSOR] != 63);
1935 WARN_ON(fifo_size != 511);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001936
Ville Syrjäläc137d662017-03-02 19:15:06 +02001937 trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size);
1938
Ville Syrjälä44e921d2017-03-09 17:44:34 +02001939 /*
1940 * uncore.lock serves a double purpose here. It allows us to
1941 * use the less expensive I915_{READ,WRITE}_FW() functions, and
1942 * it protects the DSPARB registers from getting clobbered by
1943 * parallel updates from multiple pipes.
1944 *
1945 * intel_pipe_update_start() has already disabled interrupts
1946 * for us, so a plain spin_lock() is sufficient here.
1947 */
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01001948 spin_lock(&uncore->lock);
Ville Syrjälä467a14d2016-12-05 16:13:28 +02001949
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001950 switch (crtc->pipe) {
Jani Nikula5ce9a6492019-01-18 14:01:20 +02001951 u32 dsparb, dsparb2, dsparb3;
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001952 case PIPE_A:
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01001953 dsparb = intel_uncore_read_fw(uncore, DSPARB);
1954 dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001955
1956 dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) |
1957 VLV_FIFO(SPRITEB, 0xff));
1958 dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) |
1959 VLV_FIFO(SPRITEB, sprite1_start));
1960
1961 dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) |
1962 VLV_FIFO(SPRITEB_HI, 0x1));
1963 dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) |
1964 VLV_FIFO(SPRITEB_HI, sprite1_start >> 8));
1965
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01001966 intel_uncore_write_fw(uncore, DSPARB, dsparb);
1967 intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001968 break;
1969 case PIPE_B:
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01001970 dsparb = intel_uncore_read_fw(uncore, DSPARB);
1971 dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001972
1973 dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) |
1974 VLV_FIFO(SPRITED, 0xff));
1975 dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) |
1976 VLV_FIFO(SPRITED, sprite1_start));
1977
1978 dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) |
1979 VLV_FIFO(SPRITED_HI, 0xff));
1980 dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) |
1981 VLV_FIFO(SPRITED_HI, sprite1_start >> 8));
1982
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01001983 intel_uncore_write_fw(uncore, DSPARB, dsparb);
1984 intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001985 break;
1986 case PIPE_C:
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01001987 dsparb3 = intel_uncore_read_fw(uncore, DSPARB3);
1988 dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03001989
1990 dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) |
1991 VLV_FIFO(SPRITEF, 0xff));
1992 dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) |
1993 VLV_FIFO(SPRITEF, sprite1_start));
1994
1995 dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) |
1996 VLV_FIFO(SPRITEF_HI, 0xff));
1997 dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) |
1998 VLV_FIFO(SPRITEF_HI, sprite1_start >> 8));
1999
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01002000 intel_uncore_write_fw(uncore, DSPARB3, dsparb3);
2001 intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03002002 break;
2003 default:
2004 break;
2005 }
Ville Syrjälä467a14d2016-12-05 16:13:28 +02002006
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01002007 intel_uncore_posting_read_fw(uncore, DSPARB);
Ville Syrjälä467a14d2016-12-05 16:13:28 +02002008
Tvrtko Ursuline33a4be2019-06-11 11:45:44 +01002009 spin_unlock(&uncore->lock);
Ville Syrjälä54f1b6e2015-06-24 22:00:05 +03002010}
2011
2012#undef VLV_FIFO
2013
Matt Ropercd1d3ee2018-12-10 13:54:14 -08002014static int vlv_compute_intermediate_wm(struct intel_crtc_state *new_crtc_state)
Ville Syrjälä4841da52017-03-02 19:14:59 +02002015{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01002016 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
Maarten Lankhorst5b9489c2017-11-15 17:31:56 +01002017 struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate;
2018 const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal;
2019 struct intel_atomic_state *intel_state =
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01002020 to_intel_atomic_state(new_crtc_state->uapi.state);
Maarten Lankhorst5b9489c2017-11-15 17:31:56 +01002021 const struct intel_crtc_state *old_crtc_state =
2022 intel_atomic_get_old_crtc_state(intel_state, crtc);
2023 const struct vlv_wm_state *active = &old_crtc_state->wm.vlv.optimal;
Ville Syrjälä4841da52017-03-02 19:14:59 +02002024 int level;
2025
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01002026 if (!new_crtc_state->hw.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) {
Maarten Lankhorst5b9489c2017-11-15 17:31:56 +01002027 *intermediate = *optimal;
2028
2029 intermediate->cxsr = false;
2030 goto out;
2031 }
2032
Ville Syrjälä4841da52017-03-02 19:14:59 +02002033 intermediate->num_levels = min(optimal->num_levels, active->num_levels);
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02002034 intermediate->cxsr = optimal->cxsr && active->cxsr &&
Maarten Lankhorst5b9489c2017-11-15 17:31:56 +01002035 !new_crtc_state->disable_cxsr;
Ville Syrjälä4841da52017-03-02 19:14:59 +02002036
2037 for (level = 0; level < intermediate->num_levels; level++) {
2038 enum plane_id plane_id;
2039
2040 for_each_plane_id_on_crtc(crtc, plane_id) {
2041 intermediate->wm[level].plane[plane_id] =
2042 min(optimal->wm[level].plane[plane_id],
2043 active->wm[level].plane[plane_id]);
2044 }
2045
2046 intermediate->sr[level].plane = min(optimal->sr[level].plane,
2047 active->sr[level].plane);
2048 intermediate->sr[level].cursor = min(optimal->sr[level].cursor,
2049 active->sr[level].cursor);
2050 }
2051
2052 vlv_invalidate_wms(crtc, intermediate, level);
2053
Maarten Lankhorst5b9489c2017-11-15 17:31:56 +01002054out:
Ville Syrjälä4841da52017-03-02 19:14:59 +02002055 /*
2056 * If our intermediate WM are identical to the final WM, then we can
2057 * omit the post-vblank programming; only update if it's different.
2058 */
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02002059 if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0)
Maarten Lankhorst5b9489c2017-11-15 17:31:56 +01002060 new_crtc_state->wm.need_postvbl_update = true;
Ville Syrjälä4841da52017-03-02 19:14:59 +02002061
2062 return 0;
2063}
2064
Ville Syrjälä7c951c02016-11-28 19:37:10 +02002065static void vlv_merge_wm(struct drm_i915_private *dev_priv,
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002066 struct vlv_wm_values *wm)
2067{
2068 struct intel_crtc *crtc;
Ville Syrjäläc08e9132019-08-21 20:30:32 +03002069 int num_active_pipes = 0;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002070
Ville Syrjälä7c951c02016-11-28 19:37:10 +02002071 wm->level = dev_priv->wm.max_level;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002072 wm->cxsr = true;
2073
Ville Syrjälä7c951c02016-11-28 19:37:10 +02002074 for_each_intel_crtc(&dev_priv->drm, crtc) {
Ville Syrjälä7eb49412017-03-02 19:14:53 +02002075 const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002076
2077 if (!crtc->active)
2078 continue;
2079
2080 if (!wm_state->cxsr)
2081 wm->cxsr = false;
2082
Ville Syrjäläc08e9132019-08-21 20:30:32 +03002083 num_active_pipes++;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002084 wm->level = min_t(int, wm->level, wm_state->num_levels - 1);
2085 }
2086
Ville Syrjäläc08e9132019-08-21 20:30:32 +03002087 if (num_active_pipes != 1)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002088 wm->cxsr = false;
2089
Ville Syrjäläc08e9132019-08-21 20:30:32 +03002090 if (num_active_pipes > 1)
Ville Syrjälä6f9c7842015-06-24 22:00:08 +03002091 wm->level = VLV_WM_LEVEL_PM2;
2092
Ville Syrjälä7c951c02016-11-28 19:37:10 +02002093 for_each_intel_crtc(&dev_priv->drm, crtc) {
Ville Syrjälä7eb49412017-03-02 19:14:53 +02002094 const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002095 enum pipe pipe = crtc->pipe;
2096
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002097 wm->pipe[pipe] = wm_state->wm[wm->level];
Ville Syrjäläff32c542017-03-02 19:14:57 +02002098 if (crtc->active && wm->cxsr)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002099 wm->sr = wm_state->sr[wm->level];
2100
Ville Syrjälä1b313892016-11-28 19:37:08 +02002101 wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2;
2102 wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2;
2103 wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2;
2104 wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2;
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002105 }
2106}
2107
Ville Syrjäläff32c542017-03-02 19:14:57 +02002108static void vlv_program_watermarks(struct drm_i915_private *dev_priv)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002109{
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002110 struct vlv_wm_values *old_wm = &dev_priv->wm.vlv;
2111 struct vlv_wm_values new_wm = {};
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002112
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002113 vlv_merge_wm(dev_priv, &new_wm);
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002114
Ville Syrjäläff32c542017-03-02 19:14:57 +02002115 if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0)
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002116 return;
2117
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002118 if (is_disabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_DDR_DVFS))
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002119 chv_set_memory_dvfs(dev_priv, false);
2120
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002121 if (is_disabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_PM5))
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002122 chv_set_memory_pm5(dev_priv, false);
2123
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002124 if (is_disabling(old_wm->cxsr, new_wm.cxsr, true))
Ville Syrjälä3d90e642016-11-28 19:37:11 +02002125 _intel_set_memory_cxsr(dev_priv, false);
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002126
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002127 vlv_write_wm_values(dev_priv, &new_wm);
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002128
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002129 if (is_enabling(old_wm->cxsr, new_wm.cxsr, true))
Ville Syrjälä3d90e642016-11-28 19:37:11 +02002130 _intel_set_memory_cxsr(dev_priv, true);
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002131
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002132 if (is_enabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_PM5))
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002133 chv_set_memory_pm5(dev_priv, true);
2134
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002135 if (is_enabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_DDR_DVFS))
Ville Syrjälä262cd2e2015-06-24 22:00:04 +03002136 chv_set_memory_dvfs(dev_priv, true);
2137
Ville Syrjäläfa292a42016-11-28 19:37:16 +02002138 *old_wm = new_wm;
Ville Syrjälä3c2777f2014-06-26 17:03:06 +03002139}
2140
Ville Syrjäläff32c542017-03-02 19:14:57 +02002141static void vlv_initial_watermarks(struct intel_atomic_state *state,
2142 struct intel_crtc_state *crtc_state)
2143{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01002144 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2145 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjäläff32c542017-03-02 19:14:57 +02002146
2147 mutex_lock(&dev_priv->wm.wm_mutex);
Ville Syrjälä4841da52017-03-02 19:14:59 +02002148 crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate;
2149 vlv_program_watermarks(dev_priv);
2150 mutex_unlock(&dev_priv->wm.wm_mutex);
2151}
2152
2153static void vlv_optimize_watermarks(struct intel_atomic_state *state,
2154 struct intel_crtc_state *crtc_state)
2155{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01002156 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2157 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjälä4841da52017-03-02 19:14:59 +02002158
2159 if (!crtc_state->wm.need_postvbl_update)
2160 return;
2161
2162 mutex_lock(&dev_priv->wm.wm_mutex);
Ville Syrjälä88016a92019-07-01 19:05:45 +03002163 crtc->wm.active.vlv = crtc_state->wm.vlv.optimal;
Ville Syrjäläff32c542017-03-02 19:14:57 +02002164 vlv_program_watermarks(dev_priv);
2165 mutex_unlock(&dev_priv->wm.wm_mutex);
2166}
2167
Ville Syrjälä432081b2016-10-31 22:37:03 +02002168static void i965_update_wm(struct intel_crtc *unused_crtc)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002169{
Ville Syrjäläffc7a762016-10-31 22:37:21 +02002170 struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev);
Ville Syrjäläefc26112016-10-31 22:37:04 +02002171 struct intel_crtc *crtc;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002172 int srwm = 1;
2173 int cursor_sr = 16;
Imre Deak98584252014-06-13 14:54:20 +03002174 bool cxsr_enabled;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002175
2176 /* Calc sr entries for one plane configs */
Ville Syrjäläffc7a762016-10-31 22:37:21 +02002177 crtc = single_enabled_crtc(dev_priv);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002178 if (crtc) {
2179 /* self-refresh has much higher latency */
2180 static const int sr_latency_ns = 12000;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002181 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002182 &crtc->config->hw.adjusted_mode;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002183 const struct drm_framebuffer *fb =
2184 crtc->base.primary->state->fb;
Damien Lespiau241bfc32013-09-25 16:45:37 +01002185 int clock = adjusted_mode->crtc_clock;
Jesse Barnesfec8cba2013-11-27 11:10:26 -08002186 int htotal = adjusted_mode->crtc_htotal;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002187 int hdisplay = crtc->config->pipe_src_w;
Ville Syrjälä353c8592016-12-14 23:30:57 +02002188 int cpp = fb->format->cpp[0];
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002189 int entries;
2190
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002191 entries = intel_wm_method2(clock, htotal,
2192 hdisplay, cpp, sr_latency_ns / 100);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002193 entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
2194 srwm = I965_FIFO_SIZE - entries;
2195 if (srwm < 0)
2196 srwm = 1;
2197 srwm &= 0x1ff;
2198 DRM_DEBUG_KMS("self-refresh entries: %d, wm: %d\n",
2199 entries, srwm);
2200
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002201 entries = intel_wm_method2(clock, htotal,
2202 crtc->base.cursor->state->crtc_w, 4,
2203 sr_latency_ns / 100);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002204 entries = DIV_ROUND_UP(entries,
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002205 i965_cursor_wm_info.cacheline_size) +
2206 i965_cursor_wm_info.guard_size;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002207
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002208 cursor_sr = i965_cursor_wm_info.fifo_size - entries;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002209 if (cursor_sr > i965_cursor_wm_info.max_wm)
2210 cursor_sr = i965_cursor_wm_info.max_wm;
2211
2212 DRM_DEBUG_KMS("self-refresh watermark: display plane %d "
2213 "cursor %d\n", srwm, cursor_sr);
2214
Imre Deak98584252014-06-13 14:54:20 +03002215 cxsr_enabled = true;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002216 } else {
Imre Deak98584252014-06-13 14:54:20 +03002217 cxsr_enabled = false;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002218 /* Turn off self refresh if both pipes are enabled */
Imre Deak5209b1f2014-07-01 12:36:17 +03002219 intel_set_memory_cxsr(dev_priv, false);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002220 }
2221
2222 DRM_DEBUG_KMS("Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
2223 srwm);
2224
2225 /* 965 has limitations... */
Ville Syrjäläf4998962015-03-10 17:02:21 +02002226 I915_WRITE(DSPFW1, FW_WM(srwm, SR) |
2227 FW_WM(8, CURSORB) |
2228 FW_WM(8, PLANEB) |
2229 FW_WM(8, PLANEA));
2230 I915_WRITE(DSPFW2, FW_WM(8, CURSORA) |
2231 FW_WM(8, PLANEC_OLD));
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002232 /* update cursor SR watermark */
Ville Syrjäläf4998962015-03-10 17:02:21 +02002233 I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR));
Imre Deak98584252014-06-13 14:54:20 +03002234
2235 if (cxsr_enabled)
2236 intel_set_memory_cxsr(dev_priv, true);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002237}
2238
Ville Syrjäläf4998962015-03-10 17:02:21 +02002239#undef FW_WM
2240
Ville Syrjälä432081b2016-10-31 22:37:03 +02002241static void i9xx_update_wm(struct intel_crtc *unused_crtc)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002242{
Ville Syrjäläffc7a762016-10-31 22:37:21 +02002243 struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002244 const struct intel_watermark_params *wm_info;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002245 u32 fwater_lo;
2246 u32 fwater_hi;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002247 int cwm, srwm = 1;
2248 int fifo_size;
2249 int planea_wm, planeb_wm;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002250 struct intel_crtc *crtc, *enabled = NULL;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002251
Ville Syrjäläa9097be2016-10-31 22:37:20 +02002252 if (IS_I945GM(dev_priv))
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002253 wm_info = &i945_wm_info;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08002254 else if (!IS_GEN(dev_priv, 2))
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002255 wm_info = &i915_wm_info;
2256 else
Ville Syrjälä9d539102014-08-15 01:21:53 +03002257 wm_info = &i830_a_wm_info;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002258
Ville Syrjäläbdaf8432017-11-17 21:19:11 +02002259 fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_A);
2260 crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A);
Ville Syrjäläefc26112016-10-31 22:37:04 +02002261 if (intel_crtc_active(crtc)) {
2262 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002263 &crtc->config->hw.adjusted_mode;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002264 const struct drm_framebuffer *fb =
2265 crtc->base.primary->state->fb;
2266 int cpp;
2267
Lucas De Marchicf819ef2018-12-12 10:10:43 -08002268 if (IS_GEN(dev_priv, 2))
Chris Wilsonb9e0bda2012-10-22 12:32:15 +01002269 cpp = 4;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002270 else
Ville Syrjälä353c8592016-12-14 23:30:57 +02002271 cpp = fb->format->cpp[0];
Chris Wilsonb9e0bda2012-10-22 12:32:15 +01002272
Damien Lespiau241bfc32013-09-25 16:45:37 +01002273 planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
Chris Wilsonb9e0bda2012-10-22 12:32:15 +01002274 wm_info, fifo_size, cpp,
Chris Wilson5aef6002014-09-03 11:56:07 +01002275 pessimal_latency_ns);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002276 enabled = crtc;
Ville Syrjälä9d539102014-08-15 01:21:53 +03002277 } else {
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002278 planea_wm = fifo_size - wm_info->guard_size;
Ville Syrjälä9d539102014-08-15 01:21:53 +03002279 if (planea_wm > (long)wm_info->max_wm)
2280 planea_wm = wm_info->max_wm;
2281 }
2282
Lucas De Marchicf819ef2018-12-12 10:10:43 -08002283 if (IS_GEN(dev_priv, 2))
Ville Syrjälä9d539102014-08-15 01:21:53 +03002284 wm_info = &i830_bc_wm_info;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002285
Ville Syrjäläbdaf8432017-11-17 21:19:11 +02002286 fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_B);
2287 crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B);
Ville Syrjäläefc26112016-10-31 22:37:04 +02002288 if (intel_crtc_active(crtc)) {
2289 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002290 &crtc->config->hw.adjusted_mode;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002291 const struct drm_framebuffer *fb =
2292 crtc->base.primary->state->fb;
2293 int cpp;
2294
Lucas De Marchicf819ef2018-12-12 10:10:43 -08002295 if (IS_GEN(dev_priv, 2))
Chris Wilsonb9e0bda2012-10-22 12:32:15 +01002296 cpp = 4;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002297 else
Ville Syrjälä353c8592016-12-14 23:30:57 +02002298 cpp = fb->format->cpp[0];
Chris Wilsonb9e0bda2012-10-22 12:32:15 +01002299
Damien Lespiau241bfc32013-09-25 16:45:37 +01002300 planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
Chris Wilsonb9e0bda2012-10-22 12:32:15 +01002301 wm_info, fifo_size, cpp,
Chris Wilson5aef6002014-09-03 11:56:07 +01002302 pessimal_latency_ns);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002303 if (enabled == NULL)
2304 enabled = crtc;
2305 else
2306 enabled = NULL;
Ville Syrjälä9d539102014-08-15 01:21:53 +03002307 } else {
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002308 planeb_wm = fifo_size - wm_info->guard_size;
Ville Syrjälä9d539102014-08-15 01:21:53 +03002309 if (planeb_wm > (long)wm_info->max_wm)
2310 planeb_wm = wm_info->max_wm;
2311 }
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002312
2313 DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
2314
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01002315 if (IS_I915GM(dev_priv) && enabled) {
Matt Roper2ff8fde2014-07-08 07:50:07 -07002316 struct drm_i915_gem_object *obj;
Daniel Vetter2ab1bc92014-04-07 08:54:21 +02002317
Ville Syrjäläefc26112016-10-31 22:37:04 +02002318 obj = intel_fb_obj(enabled->base.primary->state->fb);
Daniel Vetter2ab1bc92014-04-07 08:54:21 +02002319
2320 /* self-refresh seems busted with untiled */
Chris Wilson3e510a82016-08-05 10:14:23 +01002321 if (!i915_gem_object_is_tiled(obj))
Daniel Vetter2ab1bc92014-04-07 08:54:21 +02002322 enabled = NULL;
2323 }
2324
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002325 /*
2326 * Overlay gets an aggressive default since video jitter is bad.
2327 */
2328 cwm = 2;
2329
2330 /* Play safe and disable self-refresh before adjusting watermarks. */
Imre Deak5209b1f2014-07-01 12:36:17 +03002331 intel_set_memory_cxsr(dev_priv, false);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002332
2333 /* Calc sr entries for one plane configs */
Ville Syrjälä03427fc2016-10-31 22:37:18 +02002334 if (HAS_FW_BLC(dev_priv) && enabled) {
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002335 /* self-refresh has much higher latency */
2336 static const int sr_latency_ns = 6000;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002337 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002338 &enabled->config->hw.adjusted_mode;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002339 const struct drm_framebuffer *fb =
2340 enabled->base.primary->state->fb;
Damien Lespiau241bfc32013-09-25 16:45:37 +01002341 int clock = adjusted_mode->crtc_clock;
Jesse Barnesfec8cba2013-11-27 11:10:26 -08002342 int htotal = adjusted_mode->crtc_htotal;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002343 int hdisplay = enabled->config->pipe_src_w;
2344 int cpp;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002345 int entries;
2346
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01002347 if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv))
Ville Syrjälä2d1b5052016-07-29 17:57:01 +03002348 cpp = 4;
Ville Syrjäläefc26112016-10-31 22:37:04 +02002349 else
Ville Syrjälä353c8592016-12-14 23:30:57 +02002350 cpp = fb->format->cpp[0];
Ville Syrjälä2d1b5052016-07-29 17:57:01 +03002351
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002352 entries = intel_wm_method2(clock, htotal, hdisplay, cpp,
2353 sr_latency_ns / 100);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002354 entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
2355 DRM_DEBUG_KMS("self-refresh entries: %d\n", entries);
2356 srwm = wm_info->fifo_size - entries;
2357 if (srwm < 0)
2358 srwm = 1;
2359
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01002360 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv))
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002361 I915_WRITE(FW_BLC_SELF,
2362 FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
Ville Syrjäläacb91352016-07-29 17:57:02 +03002363 else
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002364 I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
2365 }
2366
2367 DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
2368 planea_wm, planeb_wm, cwm, srwm);
2369
2370 fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
2371 fwater_hi = (cwm & 0x1f);
2372
2373 /* Set request length to 8 cachelines per fetch */
2374 fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
2375 fwater_hi = fwater_hi | (1 << 8);
2376
2377 I915_WRITE(FW_BLC, fwater_lo);
2378 I915_WRITE(FW_BLC2, fwater_hi);
2379
Imre Deak5209b1f2014-07-01 12:36:17 +03002380 if (enabled)
2381 intel_set_memory_cxsr(dev_priv, true);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002382}
2383
Ville Syrjälä432081b2016-10-31 22:37:03 +02002384static void i845_update_wm(struct intel_crtc *unused_crtc)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002385{
Ville Syrjäläffc7a762016-10-31 22:37:21 +02002386 struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev);
Ville Syrjäläefc26112016-10-31 22:37:04 +02002387 struct intel_crtc *crtc;
Damien Lespiau241bfc32013-09-25 16:45:37 +01002388 const struct drm_display_mode *adjusted_mode;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002389 u32 fwater_lo;
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002390 int planea_wm;
2391
Ville Syrjäläffc7a762016-10-31 22:37:21 +02002392 crtc = single_enabled_crtc(dev_priv);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002393 if (crtc == NULL)
2394 return;
2395
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002396 adjusted_mode = &crtc->config->hw.adjusted_mode;
Damien Lespiau241bfc32013-09-25 16:45:37 +01002397 planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
Daniel Vetterfeb56b92013-12-14 20:38:30 -02002398 &i845_wm_info,
Ville Syrjäläbdaf8432017-11-17 21:19:11 +02002399 dev_priv->display.get_fifo_size(dev_priv, PLANE_A),
Chris Wilson5aef6002014-09-03 11:56:07 +01002400 4, pessimal_latency_ns);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03002401 fwater_lo = I915_READ(FW_BLC) & ~0xfff;
2402 fwater_lo |= (3<<8) | planea_wm;
2403
2404 DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d\n", planea_wm);
2405
2406 I915_WRITE(FW_BLC, fwater_lo);
2407}
2408
Ville Syrjälä37126462013-08-01 16:18:55 +03002409/* latency must be in 0.1us units. */
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002410static unsigned int ilk_wm_method1(unsigned int pixel_rate,
2411 unsigned int cpp,
2412 unsigned int latency)
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002413{
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002414 unsigned int ret;
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002415
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002416 ret = intel_wm_method1(pixel_rate, cpp, latency);
2417 ret = DIV_ROUND_UP(ret, 64) + 2;
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002418
2419 return ret;
2420}
2421
Ville Syrjälä37126462013-08-01 16:18:55 +03002422/* latency must be in 0.1us units. */
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002423static unsigned int ilk_wm_method2(unsigned int pixel_rate,
2424 unsigned int htotal,
2425 unsigned int width,
2426 unsigned int cpp,
2427 unsigned int latency)
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002428{
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002429 unsigned int ret;
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002430
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002431 ret = intel_wm_method2(pixel_rate, htotal,
2432 width, cpp, latency);
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002433 ret = DIV_ROUND_UP(ret, 64) + 2;
Ville Syrjäläbaf69ca2017-04-21 21:14:27 +03002434
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002435 return ret;
2436}
2437
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002438static u32 ilk_wm_fbc(u32 pri_val, u32 horiz_pixels, u8 cpp)
Paulo Zanonicca32e92013-05-31 11:45:06 -03002439{
Matt Roper15126882015-12-03 11:37:40 -08002440 /*
2441 * Neither of these should be possible since this function shouldn't be
2442 * called if the CRTC is off or the plane is invisible. But let's be
2443 * extra paranoid to avoid a potential divide-by-zero if we screw up
2444 * elsewhere in the driver.
2445 */
Ville Syrjäläac484962016-01-20 21:05:26 +02002446 if (WARN_ON(!cpp))
Matt Roper15126882015-12-03 11:37:40 -08002447 return 0;
2448 if (WARN_ON(!horiz_pixels))
2449 return 0;
2450
Ville Syrjäläac484962016-01-20 21:05:26 +02002451 return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2;
Paulo Zanonicca32e92013-05-31 11:45:06 -03002452}
2453
Imre Deak820c1982013-12-17 14:46:36 +02002454struct ilk_wm_maximums {
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002455 u16 pri;
2456 u16 spr;
2457 u16 cur;
2458 u16 fbc;
Paulo Zanonicca32e92013-05-31 11:45:06 -03002459};
2460
Ville Syrjälä37126462013-08-01 16:18:55 +03002461/*
2462 * For both WM_PIPE and WM_LP.
2463 * mem_value must be in 0.1us units.
2464 */
Maarten Lankhorstec193642019-06-28 10:55:17 +02002465static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state,
2466 const struct intel_plane_state *plane_state,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002467 u32 mem_value, bool is_lp)
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002468{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002469 u32 method1, method2;
Ville Syrjälä83054942016-11-18 21:53:00 +02002470 int cpp;
Paulo Zanonicca32e92013-05-31 11:45:06 -03002471
Ville Syrjälä03981c62018-11-14 19:34:40 +02002472 if (mem_value == 0)
2473 return U32_MAX;
2474
Maarten Lankhorstec193642019-06-28 10:55:17 +02002475 if (!intel_wm_plane_visible(crtc_state, plane_state))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002476 return 0;
2477
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01002478 cpp = plane_state->hw.fb->format->cpp[0];
Ville Syrjälä83054942016-11-18 21:53:00 +02002479
Maarten Lankhorstec193642019-06-28 10:55:17 +02002480 method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value);
Paulo Zanonicca32e92013-05-31 11:45:06 -03002481
2482 if (!is_lp)
2483 return method1;
2484
Maarten Lankhorstec193642019-06-28 10:55:17 +02002485 method2 = ilk_wm_method2(crtc_state->pixel_rate,
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002486 crtc_state->hw.adjusted_mode.crtc_htotal,
Maarten Lankhorstec193642019-06-28 10:55:17 +02002487 drm_rect_width(&plane_state->base.dst),
Ville Syrjäläac484962016-01-20 21:05:26 +02002488 cpp, mem_value);
Paulo Zanonicca32e92013-05-31 11:45:06 -03002489
2490 return min(method1, method2);
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002491}
2492
Ville Syrjälä37126462013-08-01 16:18:55 +03002493/*
2494 * For both WM_PIPE and WM_LP.
2495 * mem_value must be in 0.1us units.
2496 */
Maarten Lankhorstec193642019-06-28 10:55:17 +02002497static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state,
2498 const struct intel_plane_state *plane_state,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002499 u32 mem_value)
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002500{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002501 u32 method1, method2;
Ville Syrjälä83054942016-11-18 21:53:00 +02002502 int cpp;
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002503
Ville Syrjälä03981c62018-11-14 19:34:40 +02002504 if (mem_value == 0)
2505 return U32_MAX;
2506
Maarten Lankhorstec193642019-06-28 10:55:17 +02002507 if (!intel_wm_plane_visible(crtc_state, plane_state))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002508 return 0;
2509
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01002510 cpp = plane_state->hw.fb->format->cpp[0];
Ville Syrjälä83054942016-11-18 21:53:00 +02002511
Maarten Lankhorstec193642019-06-28 10:55:17 +02002512 method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value);
2513 method2 = ilk_wm_method2(crtc_state->pixel_rate,
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002514 crtc_state->hw.adjusted_mode.crtc_htotal,
Maarten Lankhorstec193642019-06-28 10:55:17 +02002515 drm_rect_width(&plane_state->base.dst),
Ville Syrjäläac484962016-01-20 21:05:26 +02002516 cpp, mem_value);
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002517 return min(method1, method2);
2518}
2519
Ville Syrjälä37126462013-08-01 16:18:55 +03002520/*
2521 * For both WM_PIPE and WM_LP.
2522 * mem_value must be in 0.1us units.
2523 */
Maarten Lankhorstec193642019-06-28 10:55:17 +02002524static u32 ilk_compute_cur_wm(const struct intel_crtc_state *crtc_state,
2525 const struct intel_plane_state *plane_state,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002526 u32 mem_value)
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002527{
Ville Syrjäläa5509ab2017-02-17 17:01:59 +02002528 int cpp;
Matt Roper43d59ed2015-09-24 15:53:07 -07002529
Ville Syrjälä03981c62018-11-14 19:34:40 +02002530 if (mem_value == 0)
2531 return U32_MAX;
2532
Maarten Lankhorstec193642019-06-28 10:55:17 +02002533 if (!intel_wm_plane_visible(crtc_state, plane_state))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002534 return 0;
2535
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01002536 cpp = plane_state->hw.fb->format->cpp[0];
Ville Syrjäläa5509ab2017-02-17 17:01:59 +02002537
Maarten Lankhorstec193642019-06-28 10:55:17 +02002538 return ilk_wm_method2(crtc_state->pixel_rate,
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002539 crtc_state->hw.adjusted_mode.crtc_htotal,
Maarten Lankhorst3a612762019-10-04 13:34:54 +02002540 drm_rect_width(&plane_state->base.dst),
2541 cpp, mem_value);
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002542}
2543
Paulo Zanonicca32e92013-05-31 11:45:06 -03002544/* Only for WM_LP. */
Maarten Lankhorstec193642019-06-28 10:55:17 +02002545static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state,
2546 const struct intel_plane_state *plane_state,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002547 u32 pri_val)
Paulo Zanonicca32e92013-05-31 11:45:06 -03002548{
Ville Syrjälä83054942016-11-18 21:53:00 +02002549 int cpp;
Matt Roper43d59ed2015-09-24 15:53:07 -07002550
Maarten Lankhorstec193642019-06-28 10:55:17 +02002551 if (!intel_wm_plane_visible(crtc_state, plane_state))
Paulo Zanonicca32e92013-05-31 11:45:06 -03002552 return 0;
2553
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01002554 cpp = plane_state->hw.fb->format->cpp[0];
Ville Syrjälä83054942016-11-18 21:53:00 +02002555
Maarten Lankhorstec193642019-06-28 10:55:17 +02002556 return ilk_wm_fbc(pri_val, drm_rect_width(&plane_state->base.dst), cpp);
Paulo Zanonicca32e92013-05-31 11:45:06 -03002557}
2558
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002559static unsigned int
2560ilk_display_fifo_size(const struct drm_i915_private *dev_priv)
Ville Syrjälä158ae642013-08-07 13:28:19 +03002561{
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002562 if (INTEL_GEN(dev_priv) >= 8)
Ville Syrjälä416f4722013-11-02 21:07:46 -07002563 return 3072;
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002564 else if (INTEL_GEN(dev_priv) >= 7)
Ville Syrjälä158ae642013-08-07 13:28:19 +03002565 return 768;
2566 else
2567 return 512;
2568}
2569
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002570static unsigned int
2571ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv,
2572 int level, bool is_sprite)
Ville Syrjälä4e975082014-03-07 18:32:11 +02002573{
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002574 if (INTEL_GEN(dev_priv) >= 8)
Ville Syrjälä4e975082014-03-07 18:32:11 +02002575 /* BDW primary/sprite plane watermarks */
2576 return level == 0 ? 255 : 2047;
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002577 else if (INTEL_GEN(dev_priv) >= 7)
Ville Syrjälä4e975082014-03-07 18:32:11 +02002578 /* IVB/HSW primary/sprite plane watermarks */
2579 return level == 0 ? 127 : 1023;
2580 else if (!is_sprite)
2581 /* ILK/SNB primary plane watermarks */
2582 return level == 0 ? 127 : 511;
2583 else
2584 /* ILK/SNB sprite plane watermarks */
2585 return level == 0 ? 63 : 255;
2586}
2587
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002588static unsigned int
2589ilk_cursor_wm_reg_max(const struct drm_i915_private *dev_priv, int level)
Ville Syrjälä4e975082014-03-07 18:32:11 +02002590{
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002591 if (INTEL_GEN(dev_priv) >= 7)
Ville Syrjälä4e975082014-03-07 18:32:11 +02002592 return level == 0 ? 63 : 255;
2593 else
2594 return level == 0 ? 31 : 63;
2595}
2596
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002597static unsigned int ilk_fbc_wm_reg_max(const struct drm_i915_private *dev_priv)
Ville Syrjälä4e975082014-03-07 18:32:11 +02002598{
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002599 if (INTEL_GEN(dev_priv) >= 8)
Ville Syrjälä4e975082014-03-07 18:32:11 +02002600 return 31;
2601 else
2602 return 15;
2603}
2604
Ville Syrjälä158ae642013-08-07 13:28:19 +03002605/* Calculate the maximum primary/sprite plane watermark */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08002606static unsigned int ilk_plane_wm_max(const struct drm_i915_private *dev_priv,
Ville Syrjälä158ae642013-08-07 13:28:19 +03002607 int level,
Ville Syrjälä240264f2013-08-07 13:29:12 +03002608 const struct intel_wm_config *config,
Ville Syrjälä158ae642013-08-07 13:28:19 +03002609 enum intel_ddb_partitioning ddb_partitioning,
2610 bool is_sprite)
2611{
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002612 unsigned int fifo_size = ilk_display_fifo_size(dev_priv);
Ville Syrjälä158ae642013-08-07 13:28:19 +03002613
2614 /* if sprites aren't enabled, sprites get nothing */
Ville Syrjälä240264f2013-08-07 13:29:12 +03002615 if (is_sprite && !config->sprites_enabled)
Ville Syrjälä158ae642013-08-07 13:28:19 +03002616 return 0;
2617
2618 /* HSW allows LP1+ watermarks even with multiple pipes */
Ville Syrjälä240264f2013-08-07 13:29:12 +03002619 if (level == 0 || config->num_pipes_active > 1) {
Jani Nikula24977872019-09-11 12:26:08 +03002620 fifo_size /= INTEL_NUM_PIPES(dev_priv);
Ville Syrjälä158ae642013-08-07 13:28:19 +03002621
2622 /*
2623 * For some reason the non self refresh
2624 * FIFO size is only half of the self
2625 * refresh FIFO size on ILK/SNB.
2626 */
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002627 if (INTEL_GEN(dev_priv) <= 6)
Ville Syrjälä158ae642013-08-07 13:28:19 +03002628 fifo_size /= 2;
2629 }
2630
Ville Syrjälä240264f2013-08-07 13:29:12 +03002631 if (config->sprites_enabled) {
Ville Syrjälä158ae642013-08-07 13:28:19 +03002632 /* level 0 is always calculated with 1:1 split */
2633 if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) {
2634 if (is_sprite)
2635 fifo_size *= 5;
2636 fifo_size /= 6;
2637 } else {
2638 fifo_size /= 2;
2639 }
2640 }
2641
2642 /* clamp to max that the registers can hold */
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002643 return min(fifo_size, ilk_plane_wm_reg_max(dev_priv, level, is_sprite));
Ville Syrjälä158ae642013-08-07 13:28:19 +03002644}
2645
2646/* Calculate the maximum cursor plane watermark */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08002647static unsigned int ilk_cursor_wm_max(const struct drm_i915_private *dev_priv,
Ville Syrjälä240264f2013-08-07 13:29:12 +03002648 int level,
2649 const struct intel_wm_config *config)
Ville Syrjälä158ae642013-08-07 13:28:19 +03002650{
2651 /* HSW LP1+ watermarks w/ multiple pipes */
Ville Syrjälä240264f2013-08-07 13:29:12 +03002652 if (level > 0 && config->num_pipes_active > 1)
Ville Syrjälä158ae642013-08-07 13:28:19 +03002653 return 64;
2654
2655 /* otherwise just report max that registers can hold */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08002656 return ilk_cursor_wm_reg_max(dev_priv, level);
Ville Syrjälä158ae642013-08-07 13:28:19 +03002657}
2658
Matt Ropercd1d3ee2018-12-10 13:54:14 -08002659static void ilk_compute_wm_maximums(const struct drm_i915_private *dev_priv,
Ville Syrjälä34982fe2013-10-09 19:18:09 +03002660 int level,
2661 const struct intel_wm_config *config,
2662 enum intel_ddb_partitioning ddb_partitioning,
Imre Deak820c1982013-12-17 14:46:36 +02002663 struct ilk_wm_maximums *max)
Ville Syrjälä158ae642013-08-07 13:28:19 +03002664{
Matt Ropercd1d3ee2018-12-10 13:54:14 -08002665 max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false);
2666 max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true);
2667 max->cur = ilk_cursor_wm_max(dev_priv, level, config);
2668 max->fbc = ilk_fbc_wm_reg_max(dev_priv);
Ville Syrjälä158ae642013-08-07 13:28:19 +03002669}
2670
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002671static void ilk_compute_wm_reg_maximums(const struct drm_i915_private *dev_priv,
Ville Syrjäläa3cb4042014-04-28 15:44:56 +03002672 int level,
2673 struct ilk_wm_maximums *max)
2674{
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00002675 max->pri = ilk_plane_wm_reg_max(dev_priv, level, false);
2676 max->spr = ilk_plane_wm_reg_max(dev_priv, level, true);
2677 max->cur = ilk_cursor_wm_reg_max(dev_priv, level);
2678 max->fbc = ilk_fbc_wm_reg_max(dev_priv);
Ville Syrjäläa3cb4042014-04-28 15:44:56 +03002679}
2680
Ville Syrjäläd9395652013-10-09 19:18:10 +03002681static bool ilk_validate_wm_level(int level,
Imre Deak820c1982013-12-17 14:46:36 +02002682 const struct ilk_wm_maximums *max,
Ville Syrjäläd9395652013-10-09 19:18:10 +03002683 struct intel_wm_level *result)
Ville Syrjäläa9786a12013-08-07 13:24:47 +03002684{
2685 bool ret;
2686
2687 /* already determined to be invalid? */
2688 if (!result->enable)
2689 return false;
2690
2691 result->enable = result->pri_val <= max->pri &&
2692 result->spr_val <= max->spr &&
2693 result->cur_val <= max->cur;
2694
2695 ret = result->enable;
2696
2697 /*
2698 * HACK until we can pre-compute everything,
2699 * and thus fail gracefully if LP0 watermarks
2700 * are exceeded...
2701 */
2702 if (level == 0 && !result->enable) {
2703 if (result->pri_val > max->pri)
2704 DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n",
2705 level, result->pri_val, max->pri);
2706 if (result->spr_val > max->spr)
2707 DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n",
2708 level, result->spr_val, max->spr);
2709 if (result->cur_val > max->cur)
2710 DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n",
2711 level, result->cur_val, max->cur);
2712
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002713 result->pri_val = min_t(u32, result->pri_val, max->pri);
2714 result->spr_val = min_t(u32, result->spr_val, max->spr);
2715 result->cur_val = min_t(u32, result->cur_val, max->cur);
Ville Syrjäläa9786a12013-08-07 13:24:47 +03002716 result->enable = true;
2717 }
2718
Ville Syrjäläa9786a12013-08-07 13:24:47 +03002719 return ret;
2720}
2721
Damien Lespiaud34ff9c2014-01-06 19:17:23 +00002722static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv,
Matt Roper43d59ed2015-09-24 15:53:07 -07002723 const struct intel_crtc *intel_crtc,
Ville Syrjälä6f5ddd12013-08-06 22:24:02 +03002724 int level,
Maarten Lankhorstec193642019-06-28 10:55:17 +02002725 struct intel_crtc_state *crtc_state,
Maarten Lankhorst28283f42017-10-19 17:13:40 +02002726 const struct intel_plane_state *pristate,
2727 const struct intel_plane_state *sprstate,
2728 const struct intel_plane_state *curstate,
Ville Syrjälä1fd527c2013-08-06 22:24:05 +03002729 struct intel_wm_level *result)
Ville Syrjälä6f5ddd12013-08-06 22:24:02 +03002730{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002731 u16 pri_latency = dev_priv->wm.pri_latency[level];
2732 u16 spr_latency = dev_priv->wm.spr_latency[level];
2733 u16 cur_latency = dev_priv->wm.cur_latency[level];
Ville Syrjälä6f5ddd12013-08-06 22:24:02 +03002734
2735 /* WM1+ latency values stored in 0.5us units */
2736 if (level > 0) {
2737 pri_latency *= 5;
2738 spr_latency *= 5;
2739 cur_latency *= 5;
2740 }
2741
Maarten Lankhorste3bddde2016-03-01 11:07:22 +01002742 if (pristate) {
Maarten Lankhorstec193642019-06-28 10:55:17 +02002743 result->pri_val = ilk_compute_pri_wm(crtc_state, pristate,
Maarten Lankhorste3bddde2016-03-01 11:07:22 +01002744 pri_latency, level);
Maarten Lankhorstec193642019-06-28 10:55:17 +02002745 result->fbc_val = ilk_compute_fbc_wm(crtc_state, pristate, result->pri_val);
Maarten Lankhorste3bddde2016-03-01 11:07:22 +01002746 }
2747
2748 if (sprstate)
Maarten Lankhorstec193642019-06-28 10:55:17 +02002749 result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency);
Maarten Lankhorste3bddde2016-03-01 11:07:22 +01002750
2751 if (curstate)
Maarten Lankhorstec193642019-06-28 10:55:17 +02002752 result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency);
Maarten Lankhorste3bddde2016-03-01 11:07:22 +01002753
Ville Syrjälä6f5ddd12013-08-06 22:24:02 +03002754 result->enable = true;
2755}
2756
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002757static u32
Maarten Lankhorstec193642019-06-28 10:55:17 +02002758hsw_compute_linetime_wm(const struct intel_crtc_state *crtc_state)
Eugeni Dodonov1f8eeab2012-05-09 15:37:24 -03002759{
Ville Syrjälä532f7a72016-04-29 17:31:17 +03002760 const struct intel_atomic_state *intel_state =
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01002761 to_intel_atomic_state(crtc_state->uapi.state);
Matt Roperee91a152015-12-03 11:37:39 -08002762 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002763 &crtc_state->hw.adjusted_mode;
Paulo Zanoni85a02de2013-05-03 17:23:43 -03002764 u32 linetime, ips_linetime;
Eugeni Dodonov1f8eeab2012-05-09 15:37:24 -03002765
Maarten Lankhorst1326a922019-10-31 12:26:02 +01002766 if (!crtc_state->hw.active)
Matt Roperee91a152015-12-03 11:37:39 -08002767 return 0;
2768 if (WARN_ON(adjusted_mode->crtc_clock == 0))
2769 return 0;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02002770 if (WARN_ON(intel_state->cdclk.logical.cdclk == 0))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002771 return 0;
Paulo Zanoni1011d8c2013-05-09 16:55:50 -03002772
Eugeni Dodonov1f8eeab2012-05-09 15:37:24 -03002773 /* The WM are computed with base on how long it takes to fill a single
2774 * row at the given clock rate, multiplied by 8.
2775 * */
Ville Syrjälä124abe02015-09-08 13:40:45 +03002776 linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8,
2777 adjusted_mode->crtc_clock);
2778 ips_linetime = DIV_ROUND_CLOSEST(adjusted_mode->crtc_htotal * 1000 * 8,
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +02002779 intel_state->cdclk.logical.cdclk);
Eugeni Dodonov1f8eeab2012-05-09 15:37:24 -03002780
Paulo Zanoni801bcff2013-05-31 10:08:35 -03002781 return PIPE_WM_LINETIME_IPS_LINETIME(ips_linetime) |
2782 PIPE_WM_LINETIME_TIME(linetime);
Eugeni Dodonov1f8eeab2012-05-09 15:37:24 -03002783}
2784
Ville Syrjäläbb726512016-10-31 22:37:24 +02002785static void intel_read_wm_latency(struct drm_i915_private *dev_priv,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002786 u16 wm[8])
Ville Syrjälä12b134d2013-07-05 11:57:21 +03002787{
Tvrtko Ursulin1cea02d2019-06-10 13:06:07 +01002788 struct intel_uncore *uncore = &dev_priv->uncore;
2789
Paulo Zanoni50682ee2017-08-09 13:52:43 -07002790 if (INTEL_GEN(dev_priv) >= 9) {
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002791 u32 val;
Vandana Kannan4f947382014-11-04 17:06:47 +00002792 int ret, i;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002793 int level, max_level = ilk_wm_max_level(dev_priv);
Pradeep Bhat2af30a52014-11-04 17:06:38 +00002794
2795 /* read the first set of memory latencies[0:3] */
2796 val = 0; /* data0 to be programmed to 0 for first set */
Pradeep Bhat2af30a52014-11-04 17:06:38 +00002797 ret = sandybridge_pcode_read(dev_priv,
2798 GEN9_PCODE_READ_MEM_LATENCY,
Ville Syrjäläd284d512019-05-21 19:40:24 +03002799 &val, NULL);
Pradeep Bhat2af30a52014-11-04 17:06:38 +00002800
2801 if (ret) {
2802 DRM_ERROR("SKL Mailbox read error = %d\n", ret);
2803 return;
2804 }
2805
2806 wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK;
2807 wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
2808 GEN9_MEM_LATENCY_LEVEL_MASK;
2809 wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
2810 GEN9_MEM_LATENCY_LEVEL_MASK;
2811 wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
2812 GEN9_MEM_LATENCY_LEVEL_MASK;
2813
2814 /* read the second set of memory latencies[4:7] */
2815 val = 1; /* data0 to be programmed to 1 for second set */
Pradeep Bhat2af30a52014-11-04 17:06:38 +00002816 ret = sandybridge_pcode_read(dev_priv,
2817 GEN9_PCODE_READ_MEM_LATENCY,
Ville Syrjäläd284d512019-05-21 19:40:24 +03002818 &val, NULL);
Pradeep Bhat2af30a52014-11-04 17:06:38 +00002819 if (ret) {
2820 DRM_ERROR("SKL Mailbox read error = %d\n", ret);
2821 return;
2822 }
2823
2824 wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK;
2825 wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
2826 GEN9_MEM_LATENCY_LEVEL_MASK;
2827 wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
2828 GEN9_MEM_LATENCY_LEVEL_MASK;
2829 wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
2830 GEN9_MEM_LATENCY_LEVEL_MASK;
2831
Vandana Kannan367294b2014-11-04 17:06:46 +00002832 /*
Paulo Zanoni0727e402016-09-22 18:00:30 -03002833 * If a level n (n > 1) has a 0us latency, all levels m (m >= n)
2834 * need to be disabled. We make sure to sanitize the values out
2835 * of the punit to satisfy this requirement.
2836 */
2837 for (level = 1; level <= max_level; level++) {
2838 if (wm[level] == 0) {
2839 for (i = level + 1; i <= max_level; i++)
2840 wm[i] = 0;
2841 break;
2842 }
2843 }
2844
2845 /*
Paulo Zanoni50682ee2017-08-09 13:52:43 -07002846 * WaWmMemoryReadLatency:skl+,glk
Damien Lespiau6f972352015-02-09 19:33:07 +00002847 *
Vandana Kannan367294b2014-11-04 17:06:46 +00002848 * punit doesn't take into account the read latency so we need
Paulo Zanoni0727e402016-09-22 18:00:30 -03002849 * to add 2us to the various latency levels we retrieve from the
2850 * punit when level 0 response data us 0us.
Vandana Kannan367294b2014-11-04 17:06:46 +00002851 */
Paulo Zanoni0727e402016-09-22 18:00:30 -03002852 if (wm[0] == 0) {
2853 wm[0] += 2;
2854 for (level = 1; level <= max_level; level++) {
2855 if (wm[level] == 0)
2856 break;
Vandana Kannan367294b2014-11-04 17:06:46 +00002857 wm[level] += 2;
Vandana Kannan4f947382014-11-04 17:06:47 +00002858 }
Paulo Zanoni0727e402016-09-22 18:00:30 -03002859 }
2860
Mahesh Kumar86b59282018-08-31 16:39:42 +05302861 /*
2862 * WA Level-0 adjustment for 16GB DIMMs: SKL+
2863 * If we could not get dimm info enable this WA to prevent from
2864 * any underrun. If not able to get Dimm info assume 16GB dimm
2865 * to avoid any underrun.
2866 */
Ville Syrjälä5d6f36b2018-10-23 21:21:02 +03002867 if (dev_priv->dram_info.is_16gb_dimm)
Mahesh Kumar86b59282018-08-31 16:39:42 +05302868 wm[0] += 1;
2869
Tvrtko Ursulin86527442016-10-13 11:03:00 +01002870 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Tvrtko Ursulin1cea02d2019-06-10 13:06:07 +01002871 u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD);
Ville Syrjälä12b134d2013-07-05 11:57:21 +03002872
2873 wm[0] = (sskpd >> 56) & 0xFF;
2874 if (wm[0] == 0)
2875 wm[0] = sskpd & 0xF;
Ville Syrjäläe5d50192013-07-05 11:57:22 +03002876 wm[1] = (sskpd >> 4) & 0xFF;
2877 wm[2] = (sskpd >> 12) & 0xFF;
2878 wm[3] = (sskpd >> 20) & 0x1FF;
2879 wm[4] = (sskpd >> 32) & 0x1FF;
Ville Syrjäläbb726512016-10-31 22:37:24 +02002880 } else if (INTEL_GEN(dev_priv) >= 6) {
Tvrtko Ursulin1cea02d2019-06-10 13:06:07 +01002881 u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD);
Ville Syrjälä63cf9a12013-07-05 11:57:23 +03002882
2883 wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK;
2884 wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK;
2885 wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK;
2886 wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK;
Ville Syrjäläbb726512016-10-31 22:37:24 +02002887 } else if (INTEL_GEN(dev_priv) >= 5) {
Tvrtko Ursulin1cea02d2019-06-10 13:06:07 +01002888 u32 mltr = intel_uncore_read(uncore, MLTR_ILK);
Ville Syrjälä3a88d0a2013-08-01 16:18:49 +03002889
2890 /* ILK primary LP0 latency is 700 ns */
2891 wm[0] = 7;
2892 wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK;
2893 wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK;
Paulo Zanoni50682ee2017-08-09 13:52:43 -07002894 } else {
2895 MISSING_CASE(INTEL_DEVID(dev_priv));
Ville Syrjälä12b134d2013-07-05 11:57:21 +03002896 }
2897}
2898
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002899static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002900 u16 wm[5])
Ville Syrjälä53615a52013-08-01 16:18:50 +03002901{
2902 /* ILK sprite LP0 latency is 1300 ns */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08002903 if (IS_GEN(dev_priv, 5))
Ville Syrjälä53615a52013-08-01 16:18:50 +03002904 wm[0] = 13;
2905}
2906
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01002907static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002908 u16 wm[5])
Ville Syrjälä53615a52013-08-01 16:18:50 +03002909{
2910 /* ILK cursor LP0 latency is 1300 ns */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08002911 if (IS_GEN(dev_priv, 5))
Ville Syrjälä53615a52013-08-01 16:18:50 +03002912 wm[0] = 13;
Ville Syrjälä53615a52013-08-01 16:18:50 +03002913}
2914
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002915int ilk_wm_max_level(const struct drm_i915_private *dev_priv)
Ville Syrjäläad0d6dc2013-08-30 14:30:25 +03002916{
2917 /* how many WM levels are we expecting */
Tvrtko Ursulin86527442016-10-13 11:03:00 +01002918 if (INTEL_GEN(dev_priv) >= 9)
Pradeep Bhat2af30a52014-11-04 17:06:38 +00002919 return 7;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01002920 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ville Syrjäläad0d6dc2013-08-30 14:30:25 +03002921 return 4;
Tvrtko Ursulin86527442016-10-13 11:03:00 +01002922 else if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjäläad0d6dc2013-08-30 14:30:25 +03002923 return 3;
2924 else
2925 return 2;
2926}
Daniel Vetter7526ed72014-09-29 15:07:19 +02002927
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002928static void intel_print_wm_latency(struct drm_i915_private *dev_priv,
Ville Syrjälä26ec9712013-08-01 16:18:52 +03002929 const char *name,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002930 const u16 wm[8])
Ville Syrjälä26ec9712013-08-01 16:18:52 +03002931{
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002932 int level, max_level = ilk_wm_max_level(dev_priv);
Ville Syrjälä26ec9712013-08-01 16:18:52 +03002933
2934 for (level = 0; level <= max_level; level++) {
2935 unsigned int latency = wm[level];
2936
2937 if (latency == 0) {
Chris Wilson86c1c872018-07-26 17:15:27 +01002938 DRM_DEBUG_KMS("%s WM%d latency not provided\n",
2939 name, level);
Ville Syrjälä26ec9712013-08-01 16:18:52 +03002940 continue;
2941 }
2942
Pradeep Bhat2af30a52014-11-04 17:06:38 +00002943 /*
2944 * - latencies are in us on gen9.
2945 * - before then, WM1+ latency values are in 0.5us units
2946 */
Paulo Zanonidfc267a2017-08-09 13:52:46 -07002947 if (INTEL_GEN(dev_priv) >= 9)
Pradeep Bhat2af30a52014-11-04 17:06:38 +00002948 latency *= 10;
2949 else if (level > 0)
Ville Syrjälä26ec9712013-08-01 16:18:52 +03002950 latency *= 5;
2951
2952 DRM_DEBUG_KMS("%s WM%d latency %u (%u.%u usec)\n",
2953 name, level, wm[level],
2954 latency / 10, latency % 10);
2955 }
2956}
2957
Ville Syrjäläe95a2f72014-05-08 15:09:19 +03002958static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv,
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002959 u16 wm[5], u16 min)
Ville Syrjäläe95a2f72014-05-08 15:09:19 +03002960{
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002961 int level, max_level = ilk_wm_max_level(dev_priv);
Ville Syrjäläe95a2f72014-05-08 15:09:19 +03002962
2963 if (wm[0] >= min)
2964 return false;
2965
2966 wm[0] = max(wm[0], min);
2967 for (level = 1; level <= max_level; level++)
Jani Nikula5ce9a6492019-01-18 14:01:20 +02002968 wm[level] = max_t(u16, wm[level], DIV_ROUND_UP(min, 5));
Ville Syrjäläe95a2f72014-05-08 15:09:19 +03002969
2970 return true;
2971}
2972
Ville Syrjäläbb726512016-10-31 22:37:24 +02002973static void snb_wm_latency_quirk(struct drm_i915_private *dev_priv)
Ville Syrjäläe95a2f72014-05-08 15:09:19 +03002974{
Ville Syrjäläe95a2f72014-05-08 15:09:19 +03002975 bool changed;
2976
2977 /*
2978 * The BIOS provided WM memory latency values are often
2979 * inadequate for high resolution displays. Adjust them.
2980 */
2981 changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12) |
2982 ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12) |
2983 ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12);
2984
2985 if (!changed)
2986 return;
2987
2988 DRM_DEBUG_KMS("WM latency values increased to avoid potential underruns\n");
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01002989 intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
2990 intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
2991 intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
Ville Syrjäläe95a2f72014-05-08 15:09:19 +03002992}
2993
Ville Syrjälä03981c62018-11-14 19:34:40 +02002994static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv)
2995{
2996 /*
2997 * On some SNB machines (Thinkpad X220 Tablet at least)
2998 * LP3 usage can cause vblank interrupts to be lost.
2999 * The DEIIR bit will go high but it looks like the CPU
3000 * never gets interrupted.
3001 *
3002 * It's not clear whether other interrupt source could
3003 * be affected or if this is somehow limited to vblank
3004 * interrupts only. To play it safe we disable LP3
3005 * watermarks entirely.
3006 */
3007 if (dev_priv->wm.pri_latency[3] == 0 &&
3008 dev_priv->wm.spr_latency[3] == 0 &&
3009 dev_priv->wm.cur_latency[3] == 0)
3010 return;
3011
3012 dev_priv->wm.pri_latency[3] = 0;
3013 dev_priv->wm.spr_latency[3] = 0;
3014 dev_priv->wm.cur_latency[3] = 0;
3015
3016 DRM_DEBUG_KMS("LP3 watermarks disabled due to potential for lost interrupts\n");
3017 intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
3018 intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
3019 intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
3020}
3021
Ville Syrjäläbb726512016-10-31 22:37:24 +02003022static void ilk_setup_wm_latency(struct drm_i915_private *dev_priv)
Ville Syrjälä53615a52013-08-01 16:18:50 +03003023{
Ville Syrjäläbb726512016-10-31 22:37:24 +02003024 intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency);
Ville Syrjälä53615a52013-08-01 16:18:50 +03003025
3026 memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency,
3027 sizeof(dev_priv->wm.pri_latency));
3028 memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency,
3029 sizeof(dev_priv->wm.pri_latency));
3030
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003031 intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency);
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003032 intel_fixup_cur_wm_latency(dev_priv, dev_priv->wm.cur_latency);
Ville Syrjälä26ec9712013-08-01 16:18:52 +03003033
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003034 intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
3035 intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
3036 intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
Ville Syrjäläe95a2f72014-05-08 15:09:19 +03003037
Lucas De Marchicf819ef2018-12-12 10:10:43 -08003038 if (IS_GEN(dev_priv, 6)) {
Ville Syrjäläbb726512016-10-31 22:37:24 +02003039 snb_wm_latency_quirk(dev_priv);
Ville Syrjälä03981c62018-11-14 19:34:40 +02003040 snb_wm_lp3_irq_quirk(dev_priv);
3041 }
Ville Syrjälä53615a52013-08-01 16:18:50 +03003042}
3043
Ville Syrjäläbb726512016-10-31 22:37:24 +02003044static void skl_setup_wm_latency(struct drm_i915_private *dev_priv)
Pradeep Bhat2af30a52014-11-04 17:06:38 +00003045{
Ville Syrjäläbb726512016-10-31 22:37:24 +02003046 intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003047 intel_print_wm_latency(dev_priv, "Gen9 Plane", dev_priv->wm.skl_latency);
Pradeep Bhat2af30a52014-11-04 17:06:38 +00003048}
3049
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003050static bool ilk_validate_pipe_wm(const struct drm_i915_private *dev_priv,
Matt Ropered4a6a72016-02-23 17:20:13 -08003051 struct intel_pipe_wm *pipe_wm)
3052{
3053 /* LP0 watermark maximums depend on this pipe alone */
3054 const struct intel_wm_config config = {
3055 .num_pipes_active = 1,
3056 .sprites_enabled = pipe_wm->sprites_enabled,
3057 .sprites_scaled = pipe_wm->sprites_scaled,
3058 };
3059 struct ilk_wm_maximums max;
3060
3061 /* LP0 watermarks always use 1/2 DDB partitioning */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003062 ilk_compute_wm_maximums(dev_priv, 0, &config, INTEL_DDB_PART_1_2, &max);
Matt Ropered4a6a72016-02-23 17:20:13 -08003063
3064 /* At least LP0 must be valid */
3065 if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) {
3066 DRM_DEBUG_KMS("LP0 watermark invalid\n");
3067 return false;
3068 }
3069
3070 return true;
3071}
3072
Matt Roper261a27d2015-10-08 15:28:25 -07003073/* Compute new watermarks for the pipe */
Maarten Lankhorstec193642019-06-28 10:55:17 +02003074static int ilk_compute_pipe_wm(struct intel_crtc_state *crtc_state)
Matt Roper261a27d2015-10-08 15:28:25 -07003075{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01003076 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3077 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->uapi.crtc);
Matt Roper86c8bbb2015-09-24 15:53:16 -07003078 struct intel_pipe_wm *pipe_wm;
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02003079 struct intel_plane *plane;
3080 const struct intel_plane_state *plane_state;
Maarten Lankhorst28283f42017-10-19 17:13:40 +02003081 const struct intel_plane_state *pristate = NULL;
3082 const struct intel_plane_state *sprstate = NULL;
3083 const struct intel_plane_state *curstate = NULL;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003084 int level, max_level = ilk_wm_max_level(dev_priv), usable_level;
Imre Deak820c1982013-12-17 14:46:36 +02003085 struct ilk_wm_maximums max;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003086
Maarten Lankhorstec193642019-06-28 10:55:17 +02003087 pipe_wm = &crtc_state->wm.ilk.optimal;
Matt Roper86c8bbb2015-09-24 15:53:16 -07003088
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02003089 intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
3090 if (plane->base.type == DRM_PLANE_TYPE_PRIMARY)
3091 pristate = plane_state;
3092 else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY)
3093 sprstate = plane_state;
3094 else if (plane->base.type == DRM_PLANE_TYPE_CURSOR)
3095 curstate = plane_state;
Matt Roper43d59ed2015-09-24 15:53:07 -07003096 }
3097
Maarten Lankhorst1326a922019-10-31 12:26:02 +01003098 pipe_wm->pipe_enabled = crtc_state->hw.active;
Maarten Lankhorste3bddde2016-03-01 11:07:22 +01003099 if (sprstate) {
Ville Syrjälä936e71e2016-07-26 19:06:59 +03003100 pipe_wm->sprites_enabled = sprstate->base.visible;
3101 pipe_wm->sprites_scaled = sprstate->base.visible &&
3102 (drm_rect_width(&sprstate->base.dst) != drm_rect_width(&sprstate->base.src) >> 16 ||
3103 drm_rect_height(&sprstate->base.dst) != drm_rect_height(&sprstate->base.src) >> 16);
Maarten Lankhorste3bddde2016-03-01 11:07:22 +01003104 }
3105
Maarten Lankhorstd81f04c2016-03-02 12:38:06 +01003106 usable_level = max_level;
3107
Ville Syrjälä7b39a0b2013-12-05 15:51:30 +02003108 /* ILK/SNB: LP2+ watermarks only w/o sprites */
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00003109 if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled)
Maarten Lankhorstd81f04c2016-03-02 12:38:06 +01003110 usable_level = 1;
Ville Syrjälä7b39a0b2013-12-05 15:51:30 +02003111
3112 /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */
Matt Ropered4a6a72016-02-23 17:20:13 -08003113 if (pipe_wm->sprites_scaled)
Maarten Lankhorstd81f04c2016-03-02 12:38:06 +01003114 usable_level = 0;
Ville Syrjälä7b39a0b2013-12-05 15:51:30 +02003115
Maarten Lankhorst71f0a622016-03-08 10:57:16 +01003116 memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm));
Maarten Lankhorstec193642019-06-28 10:55:17 +02003117 ilk_compute_wm_level(dev_priv, intel_crtc, 0, crtc_state,
Maarten Lankhorst28283f42017-10-19 17:13:40 +02003118 pristate, sprstate, curstate, &pipe_wm->wm[0]);
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003119
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003120 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Maarten Lankhorstec193642019-06-28 10:55:17 +02003121 pipe_wm->linetime = hsw_compute_linetime_wm(crtc_state);
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003122
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003123 if (!ilk_validate_pipe_wm(dev_priv, pipe_wm))
Maarten Lankhorst1a426d62016-03-02 12:36:03 +01003124 return -EINVAL;
Ville Syrjäläa3cb4042014-04-28 15:44:56 +03003125
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00003126 ilk_compute_wm_reg_maximums(dev_priv, 1, &max);
Ville Syrjäläa3cb4042014-04-28 15:44:56 +03003127
Maarten Lankhorst28283f42017-10-19 17:13:40 +02003128 for (level = 1; level <= usable_level; level++) {
3129 struct intel_wm_level *wm = &pipe_wm->wm[level];
Ville Syrjäläa3cb4042014-04-28 15:44:56 +03003130
Maarten Lankhorstec193642019-06-28 10:55:17 +02003131 ilk_compute_wm_level(dev_priv, intel_crtc, level, crtc_state,
Maarten Lankhorstd81f04c2016-03-02 12:38:06 +01003132 pristate, sprstate, curstate, wm);
Ville Syrjäläa3cb4042014-04-28 15:44:56 +03003133
3134 /*
3135 * Disable any watermark level that exceeds the
3136 * register maximums since such watermarks are
3137 * always invalid.
3138 */
Maarten Lankhorst28283f42017-10-19 17:13:40 +02003139 if (!ilk_validate_wm_level(level, &max, wm)) {
3140 memset(wm, 0, sizeof(*wm));
3141 break;
3142 }
Ville Syrjäläa3cb4042014-04-28 15:44:56 +03003143 }
3144
Matt Roper86c8bbb2015-09-24 15:53:16 -07003145 return 0;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003146}
3147
3148/*
Matt Ropered4a6a72016-02-23 17:20:13 -08003149 * Build a set of 'intermediate' watermark values that satisfy both the old
3150 * state and the new state. These can be programmed to the hardware
3151 * immediately.
3152 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003153static int ilk_compute_intermediate_wm(struct intel_crtc_state *newstate)
Matt Ropered4a6a72016-02-23 17:20:13 -08003154{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01003155 struct intel_crtc *intel_crtc = to_intel_crtc(newstate->uapi.crtc);
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003156 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Matt Ropere8f1f022016-05-12 07:05:55 -07003157 struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate;
Maarten Lankhorstb6b178a2017-10-19 17:13:41 +02003158 struct intel_atomic_state *intel_state =
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01003159 to_intel_atomic_state(newstate->uapi.state);
Maarten Lankhorstb6b178a2017-10-19 17:13:41 +02003160 const struct intel_crtc_state *oldstate =
3161 intel_atomic_get_old_crtc_state(intel_state, intel_crtc);
3162 const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal;
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003163 int level, max_level = ilk_wm_max_level(dev_priv);
Matt Ropered4a6a72016-02-23 17:20:13 -08003164
3165 /*
3166 * Start with the final, target watermarks, then combine with the
3167 * currently active watermarks to get values that are safe both before
3168 * and after the vblank.
3169 */
Matt Ropere8f1f022016-05-12 07:05:55 -07003170 *a = newstate->wm.ilk.optimal;
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01003171 if (!newstate->hw.active || drm_atomic_crtc_needs_modeset(&newstate->uapi) ||
Ville Syrjäläf255c622018-11-08 17:10:13 +02003172 intel_state->skip_intermediate_wm)
Maarten Lankhorstb6b178a2017-10-19 17:13:41 +02003173 return 0;
3174
Matt Ropered4a6a72016-02-23 17:20:13 -08003175 a->pipe_enabled |= b->pipe_enabled;
3176 a->sprites_enabled |= b->sprites_enabled;
3177 a->sprites_scaled |= b->sprites_scaled;
3178
3179 for (level = 0; level <= max_level; level++) {
3180 struct intel_wm_level *a_wm = &a->wm[level];
3181 const struct intel_wm_level *b_wm = &b->wm[level];
3182
3183 a_wm->enable &= b_wm->enable;
3184 a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val);
3185 a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val);
3186 a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val);
3187 a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val);
3188 }
3189
3190 /*
3191 * We need to make sure that these merged watermark values are
3192 * actually a valid configuration themselves. If they're not,
3193 * there's no safe way to transition from the old state to
3194 * the new state, so we need to fail the atomic transaction.
3195 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003196 if (!ilk_validate_pipe_wm(dev_priv, a))
Matt Ropered4a6a72016-02-23 17:20:13 -08003197 return -EINVAL;
3198
3199 /*
3200 * If our intermediate WM are identical to the final WM, then we can
3201 * omit the post-vblank programming; only update if it's different.
3202 */
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02003203 if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0)
3204 newstate->wm.need_postvbl_update = true;
Matt Ropered4a6a72016-02-23 17:20:13 -08003205
3206 return 0;
3207}
3208
3209/*
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003210 * Merge the watermarks from all active pipes for a specific level.
3211 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003212static void ilk_merge_wm_level(struct drm_i915_private *dev_priv,
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003213 int level,
3214 struct intel_wm_level *ret_wm)
3215{
3216 const struct intel_crtc *intel_crtc;
3217
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003218 ret_wm->enable = true;
3219
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003220 for_each_intel_crtc(&dev_priv->drm, intel_crtc) {
Matt Ropered4a6a72016-02-23 17:20:13 -08003221 const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk;
Ville Syrjäläfe392ef2014-03-07 18:32:10 +02003222 const struct intel_wm_level *wm = &active->wm[level];
3223
3224 if (!active->pipe_enabled)
3225 continue;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003226
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003227 /*
3228 * The watermark values may have been used in the past,
3229 * so we must maintain them in the registers for some
3230 * time even if the level is now disabled.
3231 */
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003232 if (!wm->enable)
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003233 ret_wm->enable = false;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003234
3235 ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val);
3236 ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val);
3237 ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val);
3238 ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val);
3239 }
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003240}
3241
3242/*
3243 * Merge all low power watermarks for all active pipes.
3244 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003245static void ilk_wm_merge(struct drm_i915_private *dev_priv,
Ville Syrjälä0ba22e22013-12-05 15:51:34 +02003246 const struct intel_wm_config *config,
Imre Deak820c1982013-12-17 14:46:36 +02003247 const struct ilk_wm_maximums *max,
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003248 struct intel_pipe_wm *merged)
3249{
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003250 int level, max_level = ilk_wm_max_level(dev_priv);
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003251 int last_enabled_level = max_level;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003252
Ville Syrjälä0ba22e22013-12-05 15:51:34 +02003253 /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003254 if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) &&
Ville Syrjälä0ba22e22013-12-05 15:51:34 +02003255 config->num_pipes_active > 1)
Ville Syrjälä1204d5b2016-04-01 21:53:18 +03003256 last_enabled_level = 0;
Ville Syrjälä0ba22e22013-12-05 15:51:34 +02003257
Ville Syrjälä6c8b6c22013-12-05 15:51:35 +02003258 /* ILK: FBC WM must be disabled always */
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00003259 merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003260
3261 /* merge each WM1+ level */
3262 for (level = 1; level <= max_level; level++) {
3263 struct intel_wm_level *wm = &merged->wm[level];
3264
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003265 ilk_merge_wm_level(dev_priv, level, wm);
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003266
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003267 if (level > last_enabled_level)
3268 wm->enable = false;
3269 else if (!ilk_validate_wm_level(level, max, wm))
3270 /* make sure all following levels get disabled */
3271 last_enabled_level = level - 1;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003272
3273 /*
3274 * The spec says it is preferred to disable
3275 * FBC WMs instead of disabling a WM level.
3276 */
3277 if (wm->fbc_val > max->fbc) {
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003278 if (wm->enable)
3279 merged->fbc_wm_enabled = false;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003280 wm->fbc_val = 0;
3281 }
3282 }
Ville Syrjälä6c8b6c22013-12-05 15:51:35 +02003283
3284 /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */
3285 /*
3286 * FIXME this is racy. FBC might get enabled later.
3287 * What we should check here is whether FBC can be
3288 * enabled sometime later.
3289 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08003290 if (IS_GEN(dev_priv, 5) && !merged->fbc_wm_enabled &&
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03003291 intel_fbc_is_active(dev_priv)) {
Ville Syrjälä6c8b6c22013-12-05 15:51:35 +02003292 for (level = 2; level <= max_level; level++) {
3293 struct intel_wm_level *wm = &merged->wm[level];
3294
3295 wm->enable = false;
3296 }
3297 }
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003298}
3299
Ville Syrjäläb380ca32013-10-09 19:18:01 +03003300static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm)
3301{
3302 /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */
3303 return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable);
3304}
3305
Ville Syrjäläa68d68e2013-12-05 15:51:29 +02003306/* The value we need to program into the WM_LPx latency field */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003307static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv,
3308 int level)
Ville Syrjäläa68d68e2013-12-05 15:51:29 +02003309{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003310 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ville Syrjäläa68d68e2013-12-05 15:51:29 +02003311 return 2 * level;
3312 else
3313 return dev_priv->wm.pri_latency[level];
3314}
3315
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003316static void ilk_compute_wm_results(struct drm_i915_private *dev_priv,
Ville Syrjälä0362c782013-10-09 19:17:57 +03003317 const struct intel_pipe_wm *merged,
Ville Syrjälä609cede2013-10-09 19:18:03 +03003318 enum intel_ddb_partitioning partitioning,
Imre Deak820c1982013-12-17 14:46:36 +02003319 struct ilk_wm_values *results)
Paulo Zanoni1011d8c2013-05-09 16:55:50 -03003320{
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003321 struct intel_crtc *intel_crtc;
3322 int level, wm_lp;
Paulo Zanonicca32e92013-05-31 11:45:06 -03003323
Ville Syrjälä0362c782013-10-09 19:17:57 +03003324 results->enable_fbc_wm = merged->fbc_wm_enabled;
Ville Syrjälä609cede2013-10-09 19:18:03 +03003325 results->partitioning = partitioning;
Paulo Zanonicca32e92013-05-31 11:45:06 -03003326
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003327 /* LP1+ register values */
Paulo Zanonicca32e92013-05-31 11:45:06 -03003328 for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
Ville Syrjälä1fd527c2013-08-06 22:24:05 +03003329 const struct intel_wm_level *r;
Paulo Zanonicca32e92013-05-31 11:45:06 -03003330
Ville Syrjäläb380ca32013-10-09 19:18:01 +03003331 level = ilk_wm_lp_to_level(wm_lp, merged);
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003332
Ville Syrjälä0362c782013-10-09 19:17:57 +03003333 r = &merged->wm[level];
Paulo Zanonicca32e92013-05-31 11:45:06 -03003334
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003335 /*
3336 * Maintain the watermark values even if the level is
3337 * disabled. Doing otherwise could cause underruns.
3338 */
3339 results->wm_lp[wm_lp - 1] =
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003340 (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) |
Ville Syrjälä416f4722013-11-02 21:07:46 -07003341 (r->pri_val << WM1_LP_SR_SHIFT) |
3342 r->cur_val;
3343
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003344 if (r->enable)
3345 results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN;
3346
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00003347 if (INTEL_GEN(dev_priv) >= 8)
Ville Syrjälä416f4722013-11-02 21:07:46 -07003348 results->wm_lp[wm_lp - 1] |=
3349 r->fbc_val << WM1_LP_FBC_SHIFT_BDW;
3350 else
3351 results->wm_lp[wm_lp - 1] |=
3352 r->fbc_val << WM1_LP_FBC_SHIFT;
3353
Ville Syrjäläd52fea52014-04-28 15:44:57 +03003354 /*
3355 * Always set WM1S_LP_EN when spr_val != 0, even if the
3356 * level is disabled. Doing otherwise could cause underruns.
3357 */
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00003358 if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) {
Ville Syrjälä6cef2b8a2013-12-05 15:51:32 +02003359 WARN_ON(wm_lp != 1);
3360 results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val;
3361 } else
3362 results->wm_lp_spr[wm_lp - 1] = r->spr_val;
Paulo Zanonicca32e92013-05-31 11:45:06 -03003363 }
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003364
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003365 /* LP0 register values */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003366 for_each_intel_crtc(&dev_priv->drm, intel_crtc) {
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003367 enum pipe pipe = intel_crtc->pipe;
Matt Ropered4a6a72016-02-23 17:20:13 -08003368 const struct intel_wm_level *r =
3369 &intel_crtc->wm.active.ilk.wm[0];
Paulo Zanoni1011d8c2013-05-09 16:55:50 -03003370
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003371 if (WARN_ON(!r->enable))
3372 continue;
3373
Matt Ropered4a6a72016-02-23 17:20:13 -08003374 results->wm_linetime[pipe] = intel_crtc->wm.active.ilk.linetime;
Ville Syrjälä0b2ae6d2013-10-09 19:17:55 +03003375
3376 results->wm_pipe[pipe] =
3377 (r->pri_val << WM0_PIPE_PLANE_SHIFT) |
3378 (r->spr_val << WM0_PIPE_SPRITE_SHIFT) |
3379 r->cur_val;
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003380 }
3381}
3382
Paulo Zanoni861f3382013-05-31 10:19:21 -03003383/* Find the result with the highest level enabled. Check for enable_fbc_wm in
3384 * case both are at the same level. Prefer r1 in case they're the same. */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003385static struct intel_pipe_wm *
3386ilk_find_best_result(struct drm_i915_private *dev_priv,
3387 struct intel_pipe_wm *r1,
3388 struct intel_pipe_wm *r2)
Paulo Zanoni861f3382013-05-31 10:19:21 -03003389{
Matt Ropercd1d3ee2018-12-10 13:54:14 -08003390 int level, max_level = ilk_wm_max_level(dev_priv);
Ville Syrjälä198a1e92013-10-09 19:17:58 +03003391 int level1 = 0, level2 = 0;
Paulo Zanoni861f3382013-05-31 10:19:21 -03003392
Ville Syrjälä198a1e92013-10-09 19:17:58 +03003393 for (level = 1; level <= max_level; level++) {
3394 if (r1->wm[level].enable)
3395 level1 = level;
3396 if (r2->wm[level].enable)
3397 level2 = level;
Paulo Zanoni861f3382013-05-31 10:19:21 -03003398 }
3399
Ville Syrjälä198a1e92013-10-09 19:17:58 +03003400 if (level1 == level2) {
3401 if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled)
Paulo Zanoni861f3382013-05-31 10:19:21 -03003402 return r2;
3403 else
3404 return r1;
Ville Syrjälä198a1e92013-10-09 19:17:58 +03003405 } else if (level1 > level2) {
Paulo Zanoni861f3382013-05-31 10:19:21 -03003406 return r1;
3407 } else {
3408 return r2;
3409 }
3410}
3411
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003412/* dirty bits used to track which watermarks need changes */
3413#define WM_DIRTY_PIPE(pipe) (1 << (pipe))
3414#define WM_DIRTY_LINETIME(pipe) (1 << (8 + (pipe)))
3415#define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp)))
3416#define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3))
3417#define WM_DIRTY_FBC (1 << 24)
3418#define WM_DIRTY_DDB (1 << 25)
3419
Damien Lespiau055e3932014-08-18 13:49:10 +01003420static unsigned int ilk_compute_wm_dirty(struct drm_i915_private *dev_priv,
Imre Deak820c1982013-12-17 14:46:36 +02003421 const struct ilk_wm_values *old,
3422 const struct ilk_wm_values *new)
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003423{
3424 unsigned int dirty = 0;
3425 enum pipe pipe;
3426 int wm_lp;
3427
Damien Lespiau055e3932014-08-18 13:49:10 +01003428 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003429 if (old->wm_linetime[pipe] != new->wm_linetime[pipe]) {
3430 dirty |= WM_DIRTY_LINETIME(pipe);
3431 /* Must disable LP1+ watermarks too */
3432 dirty |= WM_DIRTY_LP_ALL;
3433 }
3434
3435 if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) {
3436 dirty |= WM_DIRTY_PIPE(pipe);
3437 /* Must disable LP1+ watermarks too */
3438 dirty |= WM_DIRTY_LP_ALL;
3439 }
3440 }
3441
3442 if (old->enable_fbc_wm != new->enable_fbc_wm) {
3443 dirty |= WM_DIRTY_FBC;
3444 /* Must disable LP1+ watermarks too */
3445 dirty |= WM_DIRTY_LP_ALL;
3446 }
3447
3448 if (old->partitioning != new->partitioning) {
3449 dirty |= WM_DIRTY_DDB;
3450 /* Must disable LP1+ watermarks too */
3451 dirty |= WM_DIRTY_LP_ALL;
3452 }
3453
3454 /* LP1+ watermarks already deemed dirty, no need to continue */
3455 if (dirty & WM_DIRTY_LP_ALL)
3456 return dirty;
3457
3458 /* Find the lowest numbered LP1+ watermark in need of an update... */
3459 for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
3460 if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] ||
3461 old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1])
3462 break;
3463 }
3464
3465 /* ...and mark it and all higher numbered LP1+ watermarks as dirty */
3466 for (; wm_lp <= 3; wm_lp++)
3467 dirty |= WM_DIRTY_LP(wm_lp);
3468
3469 return dirty;
3470}
3471
Ville Syrjälä8553c182013-12-05 15:51:39 +02003472static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv,
3473 unsigned int dirty)
3474{
Imre Deak820c1982013-12-17 14:46:36 +02003475 struct ilk_wm_values *previous = &dev_priv->wm.hw;
Ville Syrjälä8553c182013-12-05 15:51:39 +02003476 bool changed = false;
3477
3478 if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) {
3479 previous->wm_lp[2] &= ~WM1_LP_SR_EN;
3480 I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]);
3481 changed = true;
3482 }
3483 if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) {
3484 previous->wm_lp[1] &= ~WM1_LP_SR_EN;
3485 I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]);
3486 changed = true;
3487 }
3488 if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) {
3489 previous->wm_lp[0] &= ~WM1_LP_SR_EN;
3490 I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]);
3491 changed = true;
3492 }
3493
3494 /*
3495 * Don't touch WM1S_LP_EN here.
3496 * Doing so could cause underruns.
3497 */
3498
3499 return changed;
3500}
3501
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003502/*
3503 * The spec says we shouldn't write when we don't need, because every write
3504 * causes WMs to be re-evaluated, expending some power.
3505 */
Imre Deak820c1982013-12-17 14:46:36 +02003506static void ilk_write_wm_values(struct drm_i915_private *dev_priv,
3507 struct ilk_wm_values *results)
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003508{
Imre Deak820c1982013-12-17 14:46:36 +02003509 struct ilk_wm_values *previous = &dev_priv->wm.hw;
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003510 unsigned int dirty;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02003511 u32 val;
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003512
Damien Lespiau055e3932014-08-18 13:49:10 +01003513 dirty = ilk_compute_wm_dirty(dev_priv, previous, results);
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003514 if (!dirty)
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003515 return;
3516
Ville Syrjälä8553c182013-12-05 15:51:39 +02003517 _ilk_disable_lp_wm(dev_priv, dirty);
Ville Syrjälä6cef2b8a2013-12-05 15:51:32 +02003518
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003519 if (dirty & WM_DIRTY_PIPE(PIPE_A))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003520 I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]);
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003521 if (dirty & WM_DIRTY_PIPE(PIPE_B))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003522 I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]);
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003523 if (dirty & WM_DIRTY_PIPE(PIPE_C))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003524 I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]);
3525
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003526 if (dirty & WM_DIRTY_LINETIME(PIPE_A))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003527 I915_WRITE(PIPE_WM_LINETIME(PIPE_A), results->wm_linetime[0]);
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003528 if (dirty & WM_DIRTY_LINETIME(PIPE_B))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003529 I915_WRITE(PIPE_WM_LINETIME(PIPE_B), results->wm_linetime[1]);
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003530 if (dirty & WM_DIRTY_LINETIME(PIPE_C))
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003531 I915_WRITE(PIPE_WM_LINETIME(PIPE_C), results->wm_linetime[2]);
3532
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003533 if (dirty & WM_DIRTY_DDB) {
Tvrtko Ursulin86527442016-10-13 11:03:00 +01003534 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjäläac9545f2013-12-05 15:51:28 +02003535 val = I915_READ(WM_MISC);
3536 if (results->partitioning == INTEL_DDB_PART_1_2)
3537 val &= ~WM_MISC_DATA_PARTITION_5_6;
3538 else
3539 val |= WM_MISC_DATA_PARTITION_5_6;
3540 I915_WRITE(WM_MISC, val);
3541 } else {
3542 val = I915_READ(DISP_ARB_CTL2);
3543 if (results->partitioning == INTEL_DDB_PART_1_2)
3544 val &= ~DISP_DATA_PARTITION_5_6;
3545 else
3546 val |= DISP_DATA_PARTITION_5_6;
3547 I915_WRITE(DISP_ARB_CTL2, val);
3548 }
Paulo Zanoni1011d8c2013-05-09 16:55:50 -03003549 }
3550
Ville Syrjälä49a687c2013-10-11 19:39:52 +03003551 if (dirty & WM_DIRTY_FBC) {
Paulo Zanonicca32e92013-05-31 11:45:06 -03003552 val = I915_READ(DISP_ARB_CTL);
3553 if (results->enable_fbc_wm)
3554 val &= ~DISP_FBC_WM_DIS;
3555 else
3556 val |= DISP_FBC_WM_DIS;
3557 I915_WRITE(DISP_ARB_CTL, val);
3558 }
3559
Imre Deak954911e2013-12-17 14:46:34 +02003560 if (dirty & WM_DIRTY_LP(1) &&
3561 previous->wm_lp_spr[0] != results->wm_lp_spr[0])
3562 I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]);
3563
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00003564 if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä6cef2b8a2013-12-05 15:51:32 +02003565 if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1])
3566 I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]);
3567 if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2])
3568 I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]);
3569 }
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003570
Ville Syrjäläfacd619b2013-12-05 15:51:33 +02003571 if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] != results->wm_lp[0])
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003572 I915_WRITE(WM1_LP_ILK, results->wm_lp[0]);
Ville Syrjäläfacd619b2013-12-05 15:51:33 +02003573 if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] != results->wm_lp[1])
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003574 I915_WRITE(WM2_LP_ILK, results->wm_lp[1]);
Ville Syrjäläfacd619b2013-12-05 15:51:33 +02003575 if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] != results->wm_lp[2])
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003576 I915_WRITE(WM3_LP_ILK, results->wm_lp[2]);
Ville Syrjälä609cede2013-10-09 19:18:03 +03003577
3578 dev_priv->wm.hw = *results;
Paulo Zanoni801bcff2013-05-31 10:08:35 -03003579}
3580
Matt Ropered4a6a72016-02-23 17:20:13 -08003581bool ilk_disable_lp_wm(struct drm_device *dev)
Ville Syrjälä8553c182013-12-05 15:51:39 +02003582{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003583 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8553c182013-12-05 15:51:39 +02003584
3585 return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL);
3586}
3587
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303588static u8 intel_enabled_dbuf_slices_num(struct drm_i915_private *dev_priv)
3589{
3590 u8 enabled_slices;
3591
3592 /* Slice 1 will always be enabled */
3593 enabled_slices = 1;
3594
3595 /* Gen prior to GEN11 have only one DBuf slice */
3596 if (INTEL_GEN(dev_priv) < 11)
3597 return enabled_slices;
3598
Imre Deak209d7352019-03-07 12:32:35 +02003599 /*
3600 * FIXME: for now we'll only ever use 1 slice; pretend that we have
3601 * only that 1 slice enabled until we have a proper way for on-demand
3602 * toggling of the second slice.
3603 */
3604 if (0 && I915_READ(DBUF_CTL_S2) & DBUF_POWER_STATE)
Mahesh Kumar74bd8002018-04-26 19:55:15 +05303605 enabled_slices++;
3606
3607 return enabled_slices;
3608}
3609
Matt Roper024c9042015-09-24 15:53:11 -07003610/*
Paulo Zanoniee3d5322016-10-11 15:25:38 -03003611 * FIXME: We still don't have the proper code detect if we need to apply the WA,
3612 * so assume we'll always need it in order to avoid underruns.
3613 */
Ville Syrjälä60e983f2018-12-21 19:14:33 +02003614static bool skl_needs_memory_bw_wa(struct drm_i915_private *dev_priv)
Paulo Zanoniee3d5322016-10-11 15:25:38 -03003615{
Ville Syrjälä60e983f2018-12-21 19:14:33 +02003616 return IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv);
Paulo Zanoniee3d5322016-10-11 15:25:38 -03003617}
3618
Paulo Zanoni56feca92016-09-22 18:00:28 -03003619static bool
3620intel_has_sagv(struct drm_i915_private *dev_priv)
3621{
Lucas De Marchi8ffa4392019-09-04 14:34:18 -07003622 /* HACK! */
3623 if (IS_GEN(dev_priv, 12))
3624 return false;
3625
Rodrigo Vivi1ca2b062018-10-26 13:03:17 -07003626 return (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) &&
3627 dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED;
Paulo Zanoni56feca92016-09-22 18:00:28 -03003628}
3629
James Ausmusb068a862019-10-09 10:23:14 -07003630static void
3631skl_setup_sagv_block_time(struct drm_i915_private *dev_priv)
3632{
James Ausmusda80f042019-10-09 10:23:15 -07003633 if (INTEL_GEN(dev_priv) >= 12) {
3634 u32 val = 0;
3635 int ret;
3636
3637 ret = sandybridge_pcode_read(dev_priv,
3638 GEN12_PCODE_READ_SAGV_BLOCK_TIME_US,
3639 &val, NULL);
3640 if (!ret) {
3641 dev_priv->sagv_block_time_us = val;
3642 return;
3643 }
3644
3645 DRM_DEBUG_DRIVER("Couldn't read SAGV block time!\n");
3646 } else if (IS_GEN(dev_priv, 11)) {
James Ausmusb068a862019-10-09 10:23:14 -07003647 dev_priv->sagv_block_time_us = 10;
3648 return;
3649 } else if (IS_GEN(dev_priv, 10)) {
3650 dev_priv->sagv_block_time_us = 20;
3651 return;
3652 } else if (IS_GEN(dev_priv, 9)) {
3653 dev_priv->sagv_block_time_us = 30;
3654 return;
3655 } else {
3656 MISSING_CASE(INTEL_GEN(dev_priv));
3657 }
3658
3659 /* Default to an unusable block time */
3660 dev_priv->sagv_block_time_us = -1;
3661}
3662
Lyude656d1b82016-08-17 15:55:54 -04003663/*
3664 * SAGV dynamically adjusts the system agent voltage and clock frequencies
3665 * depending on power and performance requirements. The display engine access
3666 * to system memory is blocked during the adjustment time. Because of the
3667 * blocking time, having this enabled can cause full system hangs and/or pipe
3668 * underruns if we don't meet all of the following requirements:
3669 *
3670 * - <= 1 pipe enabled
3671 * - All planes can enable watermarks for latencies >= SAGV engine block time
3672 * - We're not using an interlaced display configuration
3673 */
3674int
Paulo Zanoni16dcdc42016-09-22 18:00:27 -03003675intel_enable_sagv(struct drm_i915_private *dev_priv)
Lyude656d1b82016-08-17 15:55:54 -04003676{
3677 int ret;
3678
Paulo Zanoni56feca92016-09-22 18:00:28 -03003679 if (!intel_has_sagv(dev_priv))
3680 return 0;
3681
3682 if (dev_priv->sagv_status == I915_SAGV_ENABLED)
Lyude656d1b82016-08-17 15:55:54 -04003683 return 0;
3684
Ville Syrjäläff61a972018-12-21 19:14:34 +02003685 DRM_DEBUG_KMS("Enabling SAGV\n");
Lyude656d1b82016-08-17 15:55:54 -04003686 ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL,
3687 GEN9_SAGV_ENABLE);
3688
Ville Syrjäläff61a972018-12-21 19:14:34 +02003689 /* We don't need to wait for SAGV when enabling */
Lyude656d1b82016-08-17 15:55:54 -04003690
3691 /*
3692 * Some skl systems, pre-release machines in particular,
Ville Syrjäläff61a972018-12-21 19:14:34 +02003693 * don't actually have SAGV.
Lyude656d1b82016-08-17 15:55:54 -04003694 */
Paulo Zanoni6e3100e2016-09-22 18:00:29 -03003695 if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) {
Lyude656d1b82016-08-17 15:55:54 -04003696 DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n");
Paulo Zanoni16dcdc42016-09-22 18:00:27 -03003697 dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
Lyude656d1b82016-08-17 15:55:54 -04003698 return 0;
3699 } else if (ret < 0) {
Ville Syrjäläff61a972018-12-21 19:14:34 +02003700 DRM_ERROR("Failed to enable SAGV\n");
Lyude656d1b82016-08-17 15:55:54 -04003701 return ret;
3702 }
3703
Paulo Zanoni16dcdc42016-09-22 18:00:27 -03003704 dev_priv->sagv_status = I915_SAGV_ENABLED;
Lyude656d1b82016-08-17 15:55:54 -04003705 return 0;
3706}
3707
Lyude656d1b82016-08-17 15:55:54 -04003708int
Paulo Zanoni16dcdc42016-09-22 18:00:27 -03003709intel_disable_sagv(struct drm_i915_private *dev_priv)
Lyude656d1b82016-08-17 15:55:54 -04003710{
Imre Deakb3b8e992016-12-05 18:27:38 +02003711 int ret;
Lyude656d1b82016-08-17 15:55:54 -04003712
Paulo Zanoni56feca92016-09-22 18:00:28 -03003713 if (!intel_has_sagv(dev_priv))
3714 return 0;
3715
3716 if (dev_priv->sagv_status == I915_SAGV_DISABLED)
Lyude656d1b82016-08-17 15:55:54 -04003717 return 0;
3718
Ville Syrjäläff61a972018-12-21 19:14:34 +02003719 DRM_DEBUG_KMS("Disabling SAGV\n");
Lyude656d1b82016-08-17 15:55:54 -04003720 /* bspec says to keep retrying for at least 1 ms */
Imre Deakb3b8e992016-12-05 18:27:38 +02003721 ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL,
3722 GEN9_SAGV_DISABLE,
3723 GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED,
3724 1);
Lyude656d1b82016-08-17 15:55:54 -04003725 /*
3726 * Some skl systems, pre-release machines in particular,
Ville Syrjäläff61a972018-12-21 19:14:34 +02003727 * don't actually have SAGV.
Lyude656d1b82016-08-17 15:55:54 -04003728 */
Imre Deakb3b8e992016-12-05 18:27:38 +02003729 if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) {
Lyude656d1b82016-08-17 15:55:54 -04003730 DRM_DEBUG_DRIVER("No SAGV found on system, ignoring\n");
Paulo Zanoni16dcdc42016-09-22 18:00:27 -03003731 dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
Lyude656d1b82016-08-17 15:55:54 -04003732 return 0;
Imre Deakb3b8e992016-12-05 18:27:38 +02003733 } else if (ret < 0) {
Ville Syrjäläff61a972018-12-21 19:14:34 +02003734 DRM_ERROR("Failed to disable SAGV (%d)\n", ret);
Imre Deakb3b8e992016-12-05 18:27:38 +02003735 return ret;
Lyude656d1b82016-08-17 15:55:54 -04003736 }
3737
Paulo Zanoni16dcdc42016-09-22 18:00:27 -03003738 dev_priv->sagv_status = I915_SAGV_DISABLED;
Lyude656d1b82016-08-17 15:55:54 -04003739 return 0;
3740}
3741
Maarten Lankhorst855e0d62019-06-28 10:55:13 +02003742bool intel_can_enable_sagv(struct intel_atomic_state *state)
Lyude656d1b82016-08-17 15:55:54 -04003743{
Maarten Lankhorst855e0d62019-06-28 10:55:13 +02003744 struct drm_device *dev = state->base.dev;
Lyude656d1b82016-08-17 15:55:54 -04003745 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoniee3d5322016-10-11 15:25:38 -03003746 struct intel_crtc *crtc;
3747 struct intel_plane *plane;
Maarten Lankhorstec193642019-06-28 10:55:17 +02003748 struct intel_crtc_state *crtc_state;
Lyude656d1b82016-08-17 15:55:54 -04003749 enum pipe pipe;
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02003750 int level, latency;
Lyude656d1b82016-08-17 15:55:54 -04003751
Paulo Zanoni56feca92016-09-22 18:00:28 -03003752 if (!intel_has_sagv(dev_priv))
3753 return false;
3754
Lyude656d1b82016-08-17 15:55:54 -04003755 /*
Lyude656d1b82016-08-17 15:55:54 -04003756 * If there are no active CRTCs, no additional checks need be performed
3757 */
Ville Syrjälä0b14d962019-08-21 20:30:33 +03003758 if (hweight8(state->active_pipes) == 0)
Lyude656d1b82016-08-17 15:55:54 -04003759 return true;
Lucas De Marchida172232019-04-04 16:04:26 -07003760
3761 /*
3762 * SKL+ workaround: bspec recommends we disable SAGV when we have
3763 * more then one pipe enabled
3764 */
Ville Syrjälä0b14d962019-08-21 20:30:33 +03003765 if (hweight8(state->active_pipes) > 1)
Lyude656d1b82016-08-17 15:55:54 -04003766 return false;
3767
3768 /* Since we're now guaranteed to only have one active CRTC... */
Ville Syrjäläd06a79d2019-08-21 20:30:29 +03003769 pipe = ffs(state->active_pipes) - 1;
Ville Syrjälä98187832016-10-31 22:37:10 +02003770 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Maarten Lankhorstec193642019-06-28 10:55:17 +02003771 crtc_state = to_intel_crtc_state(crtc->base.state);
Lyude656d1b82016-08-17 15:55:54 -04003772
Maarten Lankhorst1326a922019-10-31 12:26:02 +01003773 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Lyude656d1b82016-08-17 15:55:54 -04003774 return false;
3775
Paulo Zanoniee3d5322016-10-11 15:25:38 -03003776 for_each_intel_plane_on_crtc(dev, crtc, plane) {
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02003777 struct skl_plane_wm *wm =
Maarten Lankhorstec193642019-06-28 10:55:17 +02003778 &crtc_state->wm.skl.optimal.planes[plane->id];
Paulo Zanoniee3d5322016-10-11 15:25:38 -03003779
Lyude656d1b82016-08-17 15:55:54 -04003780 /* Skip this plane if it's not enabled */
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02003781 if (!wm->wm[0].plane_en)
Lyude656d1b82016-08-17 15:55:54 -04003782 continue;
3783
3784 /* Find the highest enabled wm level for this plane */
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003785 for (level = ilk_wm_max_level(dev_priv);
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02003786 !wm->wm[level].plane_en; --level)
Lyude656d1b82016-08-17 15:55:54 -04003787 { }
3788
Paulo Zanoniee3d5322016-10-11 15:25:38 -03003789 latency = dev_priv->wm.skl_latency[level];
3790
Ville Syrjälä60e983f2018-12-21 19:14:33 +02003791 if (skl_needs_memory_bw_wa(dev_priv) &&
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003792 plane->base.state->fb->modifier ==
Paulo Zanoniee3d5322016-10-11 15:25:38 -03003793 I915_FORMAT_MOD_X_TILED)
3794 latency += 15;
3795
Lyude656d1b82016-08-17 15:55:54 -04003796 /*
Paulo Zanonifdd11c22017-08-09 13:52:45 -07003797 * If any of the planes on this pipe don't enable wm levels that
3798 * incur memory latencies higher than sagv_block_time_us we
Ville Syrjäläff61a972018-12-21 19:14:34 +02003799 * can't enable SAGV.
Lyude656d1b82016-08-17 15:55:54 -04003800 */
James Ausmusb068a862019-10-09 10:23:14 -07003801 if (latency < dev_priv->sagv_block_time_us)
Lyude656d1b82016-08-17 15:55:54 -04003802 return false;
3803 }
3804
3805 return true;
3806}
3807
Mahesh Kumaraaa02372018-07-31 19:54:44 +05303808static u16 intel_get_ddb_size(struct drm_i915_private *dev_priv,
Maarten Lankhorstec193642019-06-28 10:55:17 +02003809 const struct intel_crtc_state *crtc_state,
Maarten Lankhorst24719e92018-10-22 12:20:00 +02003810 const u64 total_data_rate,
Mahesh Kumaraaa02372018-07-31 19:54:44 +05303811 const int num_active,
3812 struct skl_ddb_allocation *ddb)
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303813{
3814 const struct drm_display_mode *adjusted_mode;
3815 u64 total_data_bw;
3816 u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size;
3817
3818 WARN_ON(ddb_size == 0);
3819
3820 if (INTEL_GEN(dev_priv) < 11)
3821 return ddb_size - 4; /* 4 blocks for bypass path allocation */
3822
Maarten Lankhorst1326a922019-10-31 12:26:02 +01003823 adjusted_mode = &crtc_state->hw.adjusted_mode;
Maarten Lankhorst24719e92018-10-22 12:20:00 +02003824 total_data_bw = total_data_rate * drm_mode_vrefresh(adjusted_mode);
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303825
3826 /*
3827 * 12GB/s is maximum BW supported by single DBuf slice.
Ville Syrjäläad3e7b82019-01-30 17:51:10 +02003828 *
3829 * FIXME dbuf slice code is broken:
3830 * - must wait for planes to stop using the slice before powering it off
3831 * - plane straddling both slices is illegal in multi-pipe scenarios
3832 * - should validate we stay within the hw bandwidth limits
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303833 */
Ville Syrjäläad3e7b82019-01-30 17:51:10 +02003834 if (0 && (num_active > 1 || total_data_bw >= GBps(12))) {
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303835 ddb->enabled_slices = 2;
3836 } else {
3837 ddb->enabled_slices = 1;
3838 ddb_size /= 2;
3839 }
3840
3841 return ddb_size;
3842}
3843
Damien Lespiaub9cec072014-11-04 17:06:43 +00003844static void
Maarten Lankhorstb048a002018-10-18 13:51:30 +02003845skl_ddb_get_pipe_allocation_limits(struct drm_i915_private *dev_priv,
Maarten Lankhorstec193642019-06-28 10:55:17 +02003846 const struct intel_crtc_state *crtc_state,
Maarten Lankhorst24719e92018-10-22 12:20:00 +02003847 const u64 total_data_rate,
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303848 struct skl_ddb_allocation *ddb,
Matt Roperc107acf2016-05-12 07:06:01 -07003849 struct skl_ddb_entry *alloc, /* out */
3850 int *num_active /* out */)
Damien Lespiaub9cec072014-11-04 17:06:43 +00003851{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01003852 struct drm_atomic_state *state = crtc_state->uapi.state;
Matt Roperc107acf2016-05-12 07:06:01 -07003853 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01003854 struct drm_crtc *for_crtc = crtc_state->uapi.crtc;
Maarten Lankhorstec193642019-06-28 10:55:17 +02003855 const struct intel_crtc *crtc;
Mahesh Kumarcf1f6972018-08-01 20:41:13 +05303856 u32 pipe_width = 0, total_width = 0, width_before_pipe = 0;
3857 enum pipe for_pipe = to_intel_crtc(for_crtc)->pipe;
3858 u16 ddb_size;
3859 u32 i;
Matt Roperc107acf2016-05-12 07:06:01 -07003860
Maarten Lankhorst1326a922019-10-31 12:26:02 +01003861 if (WARN_ON(!state) || !crtc_state->hw.active) {
Damien Lespiaub9cec072014-11-04 17:06:43 +00003862 alloc->start = 0;
3863 alloc->end = 0;
Ville Syrjälä0b14d962019-08-21 20:30:33 +03003864 *num_active = hweight8(dev_priv->active_pipes);
Damien Lespiaub9cec072014-11-04 17:06:43 +00003865 return;
3866 }
3867
Matt Ropera6d3460e2016-05-12 07:06:04 -07003868 if (intel_state->active_pipe_changes)
Ville Syrjälä0b14d962019-08-21 20:30:33 +03003869 *num_active = hweight8(intel_state->active_pipes);
Matt Ropera6d3460e2016-05-12 07:06:04 -07003870 else
Ville Syrjälä0b14d962019-08-21 20:30:33 +03003871 *num_active = hweight8(dev_priv->active_pipes);
Matt Ropera6d3460e2016-05-12 07:06:04 -07003872
Maarten Lankhorstec193642019-06-28 10:55:17 +02003873 ddb_size = intel_get_ddb_size(dev_priv, crtc_state, total_data_rate,
Mahesh Kumaraa9664f2018-04-26 19:55:16 +05303874 *num_active, ddb);
Damien Lespiaub9cec072014-11-04 17:06:43 +00003875
Matt Roperc107acf2016-05-12 07:06:01 -07003876 /*
Mahesh Kumarcf1f6972018-08-01 20:41:13 +05303877 * If the state doesn't change the active CRTC's or there is no
3878 * modeset request, then there's no need to recalculate;
3879 * the existing pipe allocation limits should remain unchanged.
3880 * Note that we're safe from racing commits since any racing commit
3881 * that changes the active CRTC list or do modeset would need to
3882 * grab _all_ crtc locks, including the one we currently hold.
Matt Roperc107acf2016-05-12 07:06:01 -07003883 */
Mahesh Kumarcf1f6972018-08-01 20:41:13 +05303884 if (!intel_state->active_pipe_changes && !intel_state->modeset) {
Maarten Lankhorst512b5522016-11-08 13:55:34 +01003885 /*
3886 * alloc may be cleared by clear_intel_crtc_state,
3887 * copy from old state to be sure
3888 */
3889 *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb;
Matt Ropera6d3460e2016-05-12 07:06:04 -07003890 return;
Damien Lespiaub9cec072014-11-04 17:06:43 +00003891 }
Matt Ropera6d3460e2016-05-12 07:06:04 -07003892
Mahesh Kumarcf1f6972018-08-01 20:41:13 +05303893 /*
3894 * Watermark/ddb requirement highly depends upon width of the
3895 * framebuffer, So instead of allocating DDB equally among pipes
3896 * distribute DDB based on resolution/width of the display.
3897 */
Maarten Lankhorstec193642019-06-28 10:55:17 +02003898 for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
3899 const struct drm_display_mode *adjusted_mode =
Maarten Lankhorst1326a922019-10-31 12:26:02 +01003900 &crtc_state->hw.adjusted_mode;
Maarten Lankhorstec193642019-06-28 10:55:17 +02003901 enum pipe pipe = crtc->pipe;
Mahesh Kumarcf1f6972018-08-01 20:41:13 +05303902 int hdisplay, vdisplay;
Mahesh Kumarcf1f6972018-08-01 20:41:13 +05303903
Maarten Lankhorst1326a922019-10-31 12:26:02 +01003904 if (!crtc_state->hw.enable)
Mahesh Kumarcf1f6972018-08-01 20:41:13 +05303905 continue;
3906
Mahesh Kumarcf1f6972018-08-01 20:41:13 +05303907 drm_mode_get_hv_timing(adjusted_mode, &hdisplay, &vdisplay);
3908 total_width += hdisplay;
3909
3910 if (pipe < for_pipe)
3911 width_before_pipe += hdisplay;
3912 else if (pipe == for_pipe)
3913 pipe_width = hdisplay;
3914 }
3915
3916 alloc->start = ddb_size * width_before_pipe / total_width;
3917 alloc->end = ddb_size * (width_before_pipe + pipe_width) / total_width;
Damien Lespiaub9cec072014-11-04 17:06:43 +00003918}
3919
Ville Syrjälädf331de2019-03-19 18:03:11 +02003920static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state,
3921 int width, const struct drm_format_info *format,
3922 u64 modifier, unsigned int rotation,
3923 u32 plane_pixel_rate, struct skl_wm_params *wp,
3924 int color_plane);
Maarten Lankhorstec193642019-06-28 10:55:17 +02003925static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state,
Ville Syrjälädf331de2019-03-19 18:03:11 +02003926 int level,
3927 const struct skl_wm_params *wp,
3928 const struct skl_wm_level *result_prev,
3929 struct skl_wm_level *result /* out */);
Damien Lespiaub9cec072014-11-04 17:06:43 +00003930
Ville Syrjälädf331de2019-03-19 18:03:11 +02003931static unsigned int
3932skl_cursor_allocation(const struct intel_crtc_state *crtc_state,
3933 int num_active)
3934{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01003935 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
Ville Syrjälädf331de2019-03-19 18:03:11 +02003936 int level, max_level = ilk_wm_max_level(dev_priv);
3937 struct skl_wm_level wm = {};
3938 int ret, min_ddb_alloc = 0;
3939 struct skl_wm_params wp;
3940
3941 ret = skl_compute_wm_params(crtc_state, 256,
3942 drm_format_info(DRM_FORMAT_ARGB8888),
3943 DRM_FORMAT_MOD_LINEAR,
3944 DRM_MODE_ROTATE_0,
3945 crtc_state->pixel_rate, &wp, 0);
3946 WARN_ON(ret);
3947
3948 for (level = 0; level <= max_level; level++) {
Ville Syrjälä6086e472019-03-21 19:51:28 +02003949 skl_compute_plane_wm(crtc_state, level, &wp, &wm, &wm);
Ville Syrjälädf331de2019-03-19 18:03:11 +02003950 if (wm.min_ddb_alloc == U16_MAX)
3951 break;
3952
3953 min_ddb_alloc = wm.min_ddb_alloc;
3954 }
3955
3956 return max(num_active == 1 ? 32 : 8, min_ddb_alloc);
Damien Lespiaub9cec072014-11-04 17:06:43 +00003957}
3958
Mahesh Kumar37cde112018-04-26 19:55:17 +05303959static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv,
3960 struct skl_ddb_entry *entry, u32 reg)
Damien Lespiaua269c582014-11-04 17:06:49 +00003961{
Mahesh Kumar37cde112018-04-26 19:55:17 +05303962
Ville Syrjäläd7e449a2019-02-05 22:50:56 +02003963 entry->start = reg & DDB_ENTRY_MASK;
3964 entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK;
Mahesh Kumar37cde112018-04-26 19:55:17 +05303965
Damien Lespiau16160e32014-11-04 17:06:53 +00003966 if (entry->end)
3967 entry->end += 1;
Damien Lespiaua269c582014-11-04 17:06:49 +00003968}
3969
Mahesh Kumarddf34312018-04-09 09:11:03 +05303970static void
3971skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv,
3972 const enum pipe pipe,
3973 const enum plane_id plane_id,
Ville Syrjäläff43bc32018-11-27 18:59:00 +02003974 struct skl_ddb_entry *ddb_y,
3975 struct skl_ddb_entry *ddb_uv)
Mahesh Kumarddf34312018-04-09 09:11:03 +05303976{
Ville Syrjäläff43bc32018-11-27 18:59:00 +02003977 u32 val, val2;
3978 u32 fourcc = 0;
Mahesh Kumarddf34312018-04-09 09:11:03 +05303979
3980 /* Cursor doesn't support NV12/planar, so no extra calculation needed */
3981 if (plane_id == PLANE_CURSOR) {
3982 val = I915_READ(CUR_BUF_CFG(pipe));
Ville Syrjäläff43bc32018-11-27 18:59:00 +02003983 skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val);
Mahesh Kumarddf34312018-04-09 09:11:03 +05303984 return;
3985 }
3986
3987 val = I915_READ(PLANE_CTL(pipe, plane_id));
3988
3989 /* No DDB allocated for disabled planes */
Ville Syrjäläff43bc32018-11-27 18:59:00 +02003990 if (val & PLANE_CTL_ENABLE)
3991 fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK,
3992 val & PLANE_CTL_ORDER_RGBX,
3993 val & PLANE_CTL_ALPHA_MASK);
Mahesh Kumarddf34312018-04-09 09:11:03 +05303994
Ville Syrjäläff43bc32018-11-27 18:59:00 +02003995 if (INTEL_GEN(dev_priv) >= 11) {
3996 val = I915_READ(PLANE_BUF_CFG(pipe, plane_id));
3997 skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val);
3998 } else {
3999 val = I915_READ(PLANE_BUF_CFG(pipe, plane_id));
Paulo Zanoni12a6c932018-07-31 17:46:14 -07004000 val2 = I915_READ(PLANE_NV12_BUF_CFG(pipe, plane_id));
Mahesh Kumarddf34312018-04-09 09:11:03 +05304001
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004002 if (fourcc &&
4003 drm_format_info_is_yuv_semiplanar(drm_format_info(fourcc)))
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004004 swap(val, val2);
4005
4006 skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val);
4007 skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2);
Mahesh Kumarddf34312018-04-09 09:11:03 +05304008 }
4009}
4010
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004011void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc,
4012 struct skl_ddb_entry *ddb_y,
4013 struct skl_ddb_entry *ddb_uv)
4014{
4015 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4016 enum intel_display_power_domain power_domain;
4017 enum pipe pipe = crtc->pipe;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00004018 intel_wakeref_t wakeref;
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004019 enum plane_id plane_id;
4020
4021 power_domain = POWER_DOMAIN_PIPE(pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00004022 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
4023 if (!wakeref)
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004024 return;
4025
4026 for_each_plane_id_on_crtc(crtc, plane_id)
4027 skl_ddb_get_hw_plane_state(dev_priv, pipe,
4028 plane_id,
4029 &ddb_y[plane_id],
4030 &ddb_uv[plane_id]);
4031
Chris Wilson0e6e0be2019-01-14 14:21:24 +00004032 intel_display_power_put(dev_priv, power_domain, wakeref);
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004033}
4034
Damien Lespiau08db6652014-11-04 17:06:52 +00004035void skl_ddb_get_hw_state(struct drm_i915_private *dev_priv,
4036 struct skl_ddb_allocation *ddb /* out */)
Damien Lespiaua269c582014-11-04 17:06:49 +00004037{
Mahesh Kumar74bd8002018-04-26 19:55:15 +05304038 ddb->enabled_slices = intel_enabled_dbuf_slices_num(dev_priv);
Damien Lespiaua269c582014-11-04 17:06:49 +00004039}
4040
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004041/*
4042 * Determines the downscale amount of a plane for the purposes of watermark calculations.
4043 * The bspec defines downscale amount as:
4044 *
4045 * """
4046 * Horizontal down scale amount = maximum[1, Horizontal source size /
4047 * Horizontal destination size]
4048 * Vertical down scale amount = maximum[1, Vertical source size /
4049 * Vertical destination size]
4050 * Total down scale amount = Horizontal down scale amount *
4051 * Vertical down scale amount
4052 * """
4053 *
4054 * Return value is provided in 16.16 fixed point form to retain fractional part.
4055 * Caller should take care of dividing & rounding off the value.
4056 */
Kumar, Mahesh7084b502017-05-17 17:28:23 +05304057static uint_fixed_16_16_t
Maarten Lankhorstec193642019-06-28 10:55:17 +02004058skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state,
4059 const struct intel_plane_state *plane_state)
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004060{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004061 u32 src_w, src_h, dst_w, dst_h;
Kumar, Mahesh7084b502017-05-17 17:28:23 +05304062 uint_fixed_16_16_t fp_w_ratio, fp_h_ratio;
4063 uint_fixed_16_16_t downscale_h, downscale_w;
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004064
Maarten Lankhorstec193642019-06-28 10:55:17 +02004065 if (WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state)))
Kumar, Mahesheac2cb82017-07-05 20:01:46 +05304066 return u32_to_fixed16(0);
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004067
Maarten Lankhorst3a612762019-10-04 13:34:54 +02004068 /*
4069 * Src coordinates are already rotated by 270 degrees for
4070 * the 90/270 degree plane rotation cases (to match the
4071 * GTT mapping), hence no need to account for rotation here.
4072 *
4073 * n.b., src is 16.16 fixed point, dst is whole integer.
4074 */
4075 src_w = drm_rect_width(&plane_state->base.src) >> 16;
4076 src_h = drm_rect_height(&plane_state->base.src) >> 16;
4077 dst_w = drm_rect_width(&plane_state->base.dst);
4078 dst_h = drm_rect_height(&plane_state->base.dst);
Ville Syrjälä93aa2a12017-03-14 17:10:50 +02004079
Kumar, Mahesheac2cb82017-07-05 20:01:46 +05304080 fp_w_ratio = div_fixed16(src_w, dst_w);
4081 fp_h_ratio = div_fixed16(src_h, dst_h);
4082 downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1));
4083 downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1));
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004084
Kumar, Mahesh7084b502017-05-17 17:28:23 +05304085 return mul_fixed16(downscale_w, downscale_h);
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004086}
4087
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004088static u64
Maarten Lankhorstec193642019-06-28 10:55:17 +02004089skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state,
4090 const struct intel_plane_state *plane_state,
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004091 int color_plane)
Damien Lespiaub9cec072014-11-04 17:06:43 +00004092{
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004093 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01004094 const struct drm_framebuffer *fb = plane_state->hw.fb;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004095 u32 data_rate;
4096 u32 width = 0, height = 0;
Kumar, Mahesh7084b502017-05-17 17:28:23 +05304097 uint_fixed_16_16_t down_scale_amount;
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004098 u64 rate;
Matt Ropera1de91e2016-05-12 07:05:57 -07004099
Maarten Lankhorstec193642019-06-28 10:55:17 +02004100 if (!plane_state->base.visible)
Matt Ropera1de91e2016-05-12 07:05:57 -07004101 return 0;
Ville Syrjälä83054942016-11-18 21:53:00 +02004102
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004103 if (plane->id == PLANE_CURSOR)
Matt Ropera1de91e2016-05-12 07:05:57 -07004104 return 0;
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004105
4106 if (color_plane == 1 &&
4107 !drm_format_info_is_yuv_semiplanar(fb->format))
Matt Ropera1de91e2016-05-12 07:05:57 -07004108 return 0;
Kumar, Mahesha280f7d2016-04-06 08:26:39 -07004109
Ville Syrjäläfce5adf2017-03-31 21:00:55 +03004110 /*
4111 * Src coordinates are already rotated by 270 degrees for
4112 * the 90/270 degree plane rotation cases (to match the
4113 * GTT mapping), hence no need to account for rotation here.
4114 */
Maarten Lankhorstec193642019-06-28 10:55:17 +02004115 width = drm_rect_width(&plane_state->base.src) >> 16;
4116 height = drm_rect_height(&plane_state->base.src) >> 16;
Kumar, Mahesha280f7d2016-04-06 08:26:39 -07004117
Mahesh Kumarb879d582018-04-09 09:11:01 +05304118 /* UV plane does 1/2 pixel sub-sampling */
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004119 if (color_plane == 1) {
Mahesh Kumarb879d582018-04-09 09:11:01 +05304120 width /= 2;
4121 height /= 2;
Chandra Konduru2cd601c2015-04-27 15:47:37 -07004122 }
4123
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004124 data_rate = width * height;
Mahesh Kumarb879d582018-04-09 09:11:01 +05304125
Maarten Lankhorstec193642019-06-28 10:55:17 +02004126 down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state);
Kumar, Mahesh8d19d7d2016-05-19 15:03:01 -07004127
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004128 rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount);
4129
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004130 rate *= fb->format->cpp[color_plane];
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004131 return rate;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004132}
4133
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004134static u64
Maarten Lankhorstec193642019-06-28 10:55:17 +02004135skl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state,
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004136 u64 *plane_data_rate,
4137 u64 *uv_plane_data_rate)
Damien Lespiaub9cec072014-11-04 17:06:43 +00004138{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004139 struct drm_atomic_state *state = crtc_state->uapi.state;
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02004140 struct intel_plane *plane;
4141 const struct intel_plane_state *plane_state;
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004142 u64 total_data_rate = 0;
Matt Ropera6d3460e2016-05-12 07:06:04 -07004143
4144 if (WARN_ON(!state))
4145 return 0;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004146
Matt Ropera1de91e2016-05-12 07:05:57 -07004147 /* Calculate and cache data rate for each plane */
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02004148 intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
4149 enum plane_id plane_id = plane->id;
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004150 u64 rate;
Matt Roper024c9042015-09-24 15:53:11 -07004151
Mahesh Kumarb879d582018-04-09 09:11:01 +05304152 /* packed/y */
Maarten Lankhorstec193642019-06-28 10:55:17 +02004153 rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0);
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02004154 plane_data_rate[plane_id] = rate;
Maarten Lankhorst1e6ee542016-10-26 15:41:32 +02004155 total_data_rate += rate;
Matt Roper9c74d822016-05-12 07:05:58 -07004156
Mahesh Kumarb879d582018-04-09 09:11:01 +05304157 /* uv-plane */
Maarten Lankhorstec193642019-06-28 10:55:17 +02004158 rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1);
Mahesh Kumarb879d582018-04-09 09:11:01 +05304159 uv_plane_data_rate[plane_id] = rate;
Maarten Lankhorst1e6ee542016-10-26 15:41:32 +02004160 total_data_rate += rate;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004161 }
4162
4163 return total_data_rate;
4164}
4165
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004166static u64
Maarten Lankhorstec193642019-06-28 10:55:17 +02004167icl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state,
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004168 u64 *plane_data_rate)
4169{
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02004170 struct intel_plane *plane;
4171 const struct intel_plane_state *plane_state;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004172 u64 total_data_rate = 0;
4173
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004174 if (WARN_ON(!crtc_state->uapi.state))
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004175 return 0;
4176
4177 /* Calculate and cache data rate for each plane */
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02004178 intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
4179 enum plane_id plane_id = plane->id;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004180 u64 rate;
4181
Maarten Lankhorstc47b7dd2019-09-20 13:42:20 +02004182 if (!plane_state->planar_linked_plane) {
Maarten Lankhorstec193642019-06-28 10:55:17 +02004183 rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0);
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004184 plane_data_rate[plane_id] = rate;
4185 total_data_rate += rate;
4186 } else {
4187 enum plane_id y_plane_id;
4188
4189 /*
4190 * The slave plane might not iterate in
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02004191 * intel_atomic_crtc_state_for_each_plane_state(),
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004192 * and needs the master plane state which may be
4193 * NULL if we try get_new_plane_state(), so we
4194 * always calculate from the master.
4195 */
Maarten Lankhorstc47b7dd2019-09-20 13:42:20 +02004196 if (plane_state->planar_slave)
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004197 continue;
4198
4199 /* Y plane rate is calculated on the slave */
Maarten Lankhorstec193642019-06-28 10:55:17 +02004200 rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0);
Maarten Lankhorstc47b7dd2019-09-20 13:42:20 +02004201 y_plane_id = plane_state->planar_linked_plane->id;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004202 plane_data_rate[y_plane_id] = rate;
4203 total_data_rate += rate;
4204
Maarten Lankhorstec193642019-06-28 10:55:17 +02004205 rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1);
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004206 plane_data_rate[plane_id] = rate;
4207 total_data_rate += rate;
4208 }
4209 }
4210
4211 return total_data_rate;
4212}
4213
Matt Roperc107acf2016-05-12 07:06:01 -07004214static int
Maarten Lankhorstec193642019-06-28 10:55:17 +02004215skl_allocate_pipe_ddb(struct intel_crtc_state *crtc_state,
Damien Lespiaub9cec072014-11-04 17:06:43 +00004216 struct skl_ddb_allocation *ddb /* out */)
4217{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004218 struct drm_atomic_state *state = crtc_state->uapi.state;
4219 struct drm_crtc *crtc = crtc_state->uapi.crtc;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004220 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Damien Lespiaub9cec072014-11-04 17:06:43 +00004221 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstec193642019-06-28 10:55:17 +02004222 struct skl_ddb_entry *alloc = &crtc_state->wm.skl.ddb;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004223 u16 alloc_size, start = 0;
4224 u16 total[I915_MAX_PLANES] = {};
4225 u16 uv_total[I915_MAX_PLANES] = {};
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004226 u64 total_data_rate;
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02004227 enum plane_id plane_id;
Matt Roperc107acf2016-05-12 07:06:01 -07004228 int num_active;
Maarten Lankhorst24719e92018-10-22 12:20:00 +02004229 u64 plane_data_rate[I915_MAX_PLANES] = {};
4230 u64 uv_plane_data_rate[I915_MAX_PLANES] = {};
Ville Syrjälä0aded172019-02-05 17:50:53 +02004231 u32 blocks;
Matt Roperd8e87492018-12-11 09:31:07 -08004232 int level;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004233
Paulo Zanoni5a920b82016-10-04 14:37:32 -03004234 /* Clear the partitioning for disabled planes. */
Maarten Lankhorstec193642019-06-28 10:55:17 +02004235 memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y));
4236 memset(crtc_state->wm.skl.plane_ddb_uv, 0, sizeof(crtc_state->wm.skl.plane_ddb_uv));
Paulo Zanoni5a920b82016-10-04 14:37:32 -03004237
Matt Ropera6d3460e2016-05-12 07:06:04 -07004238 if (WARN_ON(!state))
4239 return 0;
4240
Maarten Lankhorst1326a922019-10-31 12:26:02 +01004241 if (!crtc_state->hw.active) {
Lyudece0ba282016-09-15 10:46:35 -04004242 alloc->start = alloc->end = 0;
Matt Roperc107acf2016-05-12 07:06:01 -07004243 return 0;
4244 }
4245
Lucas De Marchi323b0a82019-04-04 16:04:25 -07004246 if (INTEL_GEN(dev_priv) >= 11)
4247 total_data_rate =
Maarten Lankhorstec193642019-06-28 10:55:17 +02004248 icl_get_total_relative_data_rate(crtc_state,
Lucas De Marchi323b0a82019-04-04 16:04:25 -07004249 plane_data_rate);
4250 else
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004251 total_data_rate =
Maarten Lankhorstec193642019-06-28 10:55:17 +02004252 skl_get_total_relative_data_rate(crtc_state,
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004253 plane_data_rate,
4254 uv_plane_data_rate);
Lucas De Marchi323b0a82019-04-04 16:04:25 -07004255
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004256
Maarten Lankhorstec193642019-06-28 10:55:17 +02004257 skl_ddb_get_pipe_allocation_limits(dev_priv, crtc_state, total_data_rate,
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004258 ddb, alloc, &num_active);
Damien Lespiau34bb56a2014-11-04 17:07:01 +00004259 alloc_size = skl_ddb_entry_size(alloc);
Kumar, Mahesh336031e2017-05-17 17:28:25 +05304260 if (alloc_size == 0)
Matt Roperc107acf2016-05-12 07:06:01 -07004261 return 0;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004262
Matt Roperd8e87492018-12-11 09:31:07 -08004263 /* Allocate fixed number of blocks for cursor. */
Maarten Lankhorstec193642019-06-28 10:55:17 +02004264 total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active);
Matt Roperd8e87492018-12-11 09:31:07 -08004265 alloc_size -= total[PLANE_CURSOR];
Maarten Lankhorstec193642019-06-28 10:55:17 +02004266 crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start =
Matt Roperd8e87492018-12-11 09:31:07 -08004267 alloc->end - total[PLANE_CURSOR];
Maarten Lankhorstec193642019-06-28 10:55:17 +02004268 crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end;
Maarten Lankhorst49845a72016-10-26 15:41:34 +02004269
Matt Ropera1de91e2016-05-12 07:05:57 -07004270 if (total_data_rate == 0)
Matt Roperc107acf2016-05-12 07:06:01 -07004271 return 0;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004272
Matt Roperd8e87492018-12-11 09:31:07 -08004273 /*
4274 * Find the highest watermark level for which we can satisfy the block
4275 * requirement of active planes.
4276 */
4277 for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) {
Matt Roper25db2ea2018-12-12 11:17:20 -08004278 blocks = 0;
Matt Roperd8e87492018-12-11 09:31:07 -08004279 for_each_plane_id_on_crtc(intel_crtc, plane_id) {
Ville Syrjälä5e6037c2019-03-12 22:58:42 +02004280 const struct skl_plane_wm *wm =
Maarten Lankhorstec193642019-06-28 10:55:17 +02004281 &crtc_state->wm.skl.optimal.planes[plane_id];
Ville Syrjälä10a7e072019-03-12 22:58:40 +02004282
4283 if (plane_id == PLANE_CURSOR) {
4284 if (WARN_ON(wm->wm[level].min_ddb_alloc >
4285 total[PLANE_CURSOR])) {
4286 blocks = U32_MAX;
4287 break;
4288 }
4289 continue;
4290 }
4291
Ville Syrjälä961d95e2018-12-21 19:14:32 +02004292 blocks += wm->wm[level].min_ddb_alloc;
4293 blocks += wm->uv_wm[level].min_ddb_alloc;
Matt Roperd8e87492018-12-11 09:31:07 -08004294 }
4295
Ville Syrjälä3cf963c2019-03-12 22:58:36 +02004296 if (blocks <= alloc_size) {
Matt Roperd8e87492018-12-11 09:31:07 -08004297 alloc_size -= blocks;
4298 break;
4299 }
4300 }
4301
4302 if (level < 0) {
4303 DRM_DEBUG_KMS("Requested display configuration exceeds system DDB limitations");
4304 DRM_DEBUG_KMS("minimum required %d/%d\n", blocks,
4305 alloc_size);
4306 return -EINVAL;
4307 }
4308
4309 /*
4310 * Grant each plane the blocks it requires at the highest achievable
4311 * watermark level, plus an extra share of the leftover blocks
4312 * proportional to its relative data rate.
4313 */
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02004314 for_each_plane_id_on_crtc(intel_crtc, plane_id) {
Ville Syrjälä5e6037c2019-03-12 22:58:42 +02004315 const struct skl_plane_wm *wm =
Maarten Lankhorstec193642019-06-28 10:55:17 +02004316 &crtc_state->wm.skl.optimal.planes[plane_id];
Matt Roperd8e87492018-12-11 09:31:07 -08004317 u64 rate;
4318 u16 extra;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004319
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02004320 if (plane_id == PLANE_CURSOR)
Maarten Lankhorst49845a72016-10-26 15:41:34 +02004321 continue;
4322
Damien Lespiaub9cec072014-11-04 17:06:43 +00004323 /*
Matt Roperd8e87492018-12-11 09:31:07 -08004324 * We've accounted for all active planes; remaining planes are
4325 * all disabled.
Damien Lespiaub9cec072014-11-04 17:06:43 +00004326 */
Matt Roperd8e87492018-12-11 09:31:07 -08004327 if (total_data_rate == 0)
4328 break;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004329
Matt Roperd8e87492018-12-11 09:31:07 -08004330 rate = plane_data_rate[plane_id];
4331 extra = min_t(u16, alloc_size,
4332 DIV64_U64_ROUND_UP(alloc_size * rate,
4333 total_data_rate));
Ville Syrjälä961d95e2018-12-21 19:14:32 +02004334 total[plane_id] = wm->wm[level].min_ddb_alloc + extra;
Matt Roperd8e87492018-12-11 09:31:07 -08004335 alloc_size -= extra;
4336 total_data_rate -= rate;
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07004337
Matt Roperd8e87492018-12-11 09:31:07 -08004338 if (total_data_rate == 0)
4339 break;
Chandra Konduru2cd601c2015-04-27 15:47:37 -07004340
Matt Roperd8e87492018-12-11 09:31:07 -08004341 rate = uv_plane_data_rate[plane_id];
4342 extra = min_t(u16, alloc_size,
4343 DIV64_U64_ROUND_UP(alloc_size * rate,
4344 total_data_rate));
Ville Syrjälä961d95e2018-12-21 19:14:32 +02004345 uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra;
Matt Roperd8e87492018-12-11 09:31:07 -08004346 alloc_size -= extra;
4347 total_data_rate -= rate;
4348 }
4349 WARN_ON(alloc_size != 0 || total_data_rate != 0);
4350
4351 /* Set the actual DDB start/end points for each plane */
4352 start = alloc->start;
4353 for_each_plane_id_on_crtc(intel_crtc, plane_id) {
Ville Syrjälä5e6037c2019-03-12 22:58:42 +02004354 struct skl_ddb_entry *plane_alloc =
Maarten Lankhorstec193642019-06-28 10:55:17 +02004355 &crtc_state->wm.skl.plane_ddb_y[plane_id];
Ville Syrjälä5e6037c2019-03-12 22:58:42 +02004356 struct skl_ddb_entry *uv_plane_alloc =
Maarten Lankhorstec193642019-06-28 10:55:17 +02004357 &crtc_state->wm.skl.plane_ddb_uv[plane_id];
Matt Roperd8e87492018-12-11 09:31:07 -08004358
4359 if (plane_id == PLANE_CURSOR)
4360 continue;
4361
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004362 /* Gen11+ uses a separate plane for UV watermarks */
Matt Roperd8e87492018-12-11 09:31:07 -08004363 WARN_ON(INTEL_GEN(dev_priv) >= 11 && uv_total[plane_id]);
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004364
Matt Roperd8e87492018-12-11 09:31:07 -08004365 /* Leave disabled planes at (0,0) */
4366 if (total[plane_id]) {
4367 plane_alloc->start = start;
4368 start += total[plane_id];
4369 plane_alloc->end = start;
Matt Roperc107acf2016-05-12 07:06:01 -07004370 }
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07004371
Matt Roperd8e87492018-12-11 09:31:07 -08004372 if (uv_total[plane_id]) {
4373 uv_plane_alloc->start = start;
4374 start += uv_total[plane_id];
4375 uv_plane_alloc->end = start;
4376 }
4377 }
4378
4379 /*
4380 * When we calculated watermark values we didn't know how high
4381 * of a level we'd actually be able to hit, so we just marked
4382 * all levels as "enabled." Go back now and disable the ones
4383 * that aren't actually possible.
4384 */
4385 for (level++; level <= ilk_wm_max_level(dev_priv); level++) {
4386 for_each_plane_id_on_crtc(intel_crtc, plane_id) {
Ville Syrjälä5e6037c2019-03-12 22:58:42 +02004387 struct skl_plane_wm *wm =
Maarten Lankhorstec193642019-06-28 10:55:17 +02004388 &crtc_state->wm.skl.optimal.planes[plane_id];
Ville Syrjäläa301cb02019-03-12 22:58:41 +02004389
4390 /*
4391 * We only disable the watermarks for each plane if
4392 * they exceed the ddb allocation of said plane. This
4393 * is done so that we don't end up touching cursor
4394 * watermarks needlessly when some other plane reduces
4395 * our max possible watermark level.
4396 *
4397 * Bspec has this to say about the PLANE_WM enable bit:
4398 * "All the watermarks at this level for all enabled
4399 * planes must be enabled before the level will be used."
4400 * So this is actually safe to do.
4401 */
4402 if (wm->wm[level].min_ddb_alloc > total[plane_id] ||
4403 wm->uv_wm[level].min_ddb_alloc > uv_total[plane_id])
4404 memset(&wm->wm[level], 0, sizeof(wm->wm[level]));
Ville Syrjälä290248c2019-02-13 18:54:24 +02004405
Ville Syrjäläc384afe2019-02-28 19:36:39 +02004406 /*
Bob Paauwe39564ae2019-04-12 11:09:20 -07004407 * Wa_1408961008:icl, ehl
Ville Syrjäläc384afe2019-02-28 19:36:39 +02004408 * Underruns with WM1+ disabled
4409 */
Bob Paauwe39564ae2019-04-12 11:09:20 -07004410 if (IS_GEN(dev_priv, 11) &&
Ville Syrjälä290248c2019-02-13 18:54:24 +02004411 level == 1 && wm->wm[0].plane_en) {
4412 wm->wm[level].plane_res_b = wm->wm[0].plane_res_b;
Ville Syrjäläc384afe2019-02-28 19:36:39 +02004413 wm->wm[level].plane_res_l = wm->wm[0].plane_res_l;
4414 wm->wm[level].ignore_lines = wm->wm[0].ignore_lines;
Ville Syrjälä290248c2019-02-13 18:54:24 +02004415 }
Matt Roperd8e87492018-12-11 09:31:07 -08004416 }
4417 }
4418
4419 /*
4420 * Go back and disable the transition watermark if it turns out we
4421 * don't have enough DDB blocks for it.
4422 */
4423 for_each_plane_id_on_crtc(intel_crtc, plane_id) {
Ville Syrjälä5e6037c2019-03-12 22:58:42 +02004424 struct skl_plane_wm *wm =
Maarten Lankhorstec193642019-06-28 10:55:17 +02004425 &crtc_state->wm.skl.optimal.planes[plane_id];
Ville Syrjälä5e6037c2019-03-12 22:58:42 +02004426
Ville Syrjäläb19c9bc2018-12-21 19:14:31 +02004427 if (wm->trans_wm.plane_res_b >= total[plane_id])
Matt Roperd8e87492018-12-11 09:31:07 -08004428 memset(&wm->trans_wm, 0, sizeof(wm->trans_wm));
Damien Lespiaub9cec072014-11-04 17:06:43 +00004429 }
4430
Matt Roperc107acf2016-05-12 07:06:01 -07004431 return 0;
Damien Lespiaub9cec072014-11-04 17:06:43 +00004432}
4433
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004434/*
4435 * The max latency should be 257 (max the punit can code is 255 and we add 2us
Ville Syrjäläac484962016-01-20 21:05:26 +02004436 * for the read latency) and cpp should always be <= 8, so that
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004437 * should allow pixel_rate up to ~2 GHz which seems sufficient since max
4438 * 2xcdclk is 1350 MHz and the pixel rate should never exceed that.
4439*/
Paulo Zanoni6c64dd32017-08-11 16:38:25 -07004440static uint_fixed_16_16_t
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004441skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate,
4442 u8 cpp, u32 latency, u32 dbuf_block_size)
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004443{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004444 u32 wm_intermediate_val;
Mahesh Kumarb95320b2016-12-01 21:19:37 +05304445 uint_fixed_16_16_t ret;
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004446
4447 if (latency == 0)
Mahesh Kumarb95320b2016-12-01 21:19:37 +05304448 return FP_16_16_MAX;
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004449
Mahesh Kumarb95320b2016-12-01 21:19:37 +05304450 wm_intermediate_val = latency * pixel_rate * cpp;
Mahesh Kumardf8ee192018-01-30 11:49:11 -02004451 ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size);
Paulo Zanoni6c64dd32017-08-11 16:38:25 -07004452
4453 if (INTEL_GEN(dev_priv) >= 10)
4454 ret = add_fixed16_u32(ret, 1);
4455
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004456 return ret;
4457}
4458
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004459static uint_fixed_16_16_t
4460skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency,
4461 uint_fixed_16_16_t plane_blocks_per_line)
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004462{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004463 u32 wm_intermediate_val;
Mahesh Kumarb95320b2016-12-01 21:19:37 +05304464 uint_fixed_16_16_t ret;
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004465
4466 if (latency == 0)
Mahesh Kumarb95320b2016-12-01 21:19:37 +05304467 return FP_16_16_MAX;
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004468
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004469 wm_intermediate_val = latency * pixel_rate;
Mahesh Kumarb95320b2016-12-01 21:19:37 +05304470 wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val,
4471 pipe_htotal * 1000);
Kumar, Mahesheac2cb82017-07-05 20:01:46 +05304472 ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line);
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004473 return ret;
4474}
4475
Kumar, Maheshd555cb52017-05-17 17:28:29 +05304476static uint_fixed_16_16_t
Maarten Lankhorstec193642019-06-28 10:55:17 +02004477intel_get_linetime_us(const struct intel_crtc_state *crtc_state)
Kumar, Maheshd555cb52017-05-17 17:28:29 +05304478{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004479 u32 pixel_rate;
4480 u32 crtc_htotal;
Kumar, Maheshd555cb52017-05-17 17:28:29 +05304481 uint_fixed_16_16_t linetime_us;
4482
Maarten Lankhorst1326a922019-10-31 12:26:02 +01004483 if (!crtc_state->hw.active)
Kumar, Mahesheac2cb82017-07-05 20:01:46 +05304484 return u32_to_fixed16(0);
Kumar, Maheshd555cb52017-05-17 17:28:29 +05304485
Maarten Lankhorstec193642019-06-28 10:55:17 +02004486 pixel_rate = crtc_state->pixel_rate;
Kumar, Maheshd555cb52017-05-17 17:28:29 +05304487
4488 if (WARN_ON(pixel_rate == 0))
Kumar, Mahesheac2cb82017-07-05 20:01:46 +05304489 return u32_to_fixed16(0);
Kumar, Maheshd555cb52017-05-17 17:28:29 +05304490
Maarten Lankhorst1326a922019-10-31 12:26:02 +01004491 crtc_htotal = crtc_state->hw.adjusted_mode.crtc_htotal;
Kumar, Mahesheac2cb82017-07-05 20:01:46 +05304492 linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate);
Kumar, Maheshd555cb52017-05-17 17:28:29 +05304493
4494 return linetime_us;
4495}
4496
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004497static u32
Maarten Lankhorstec193642019-06-28 10:55:17 +02004498skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *crtc_state,
4499 const struct intel_plane_state *plane_state)
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004500{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004501 u64 adjusted_pixel_rate;
Kumar, Mahesh7084b502017-05-17 17:28:23 +05304502 uint_fixed_16_16_t downscale_amount;
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004503
4504 /* Shouldn't reach here on disabled planes... */
Maarten Lankhorstec193642019-06-28 10:55:17 +02004505 if (WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state)))
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004506 return 0;
4507
4508 /*
4509 * Adjusted plane pixel rate is just the pipe's adjusted pixel rate
4510 * with additional adjustments for plane-specific scaling.
4511 */
Maarten Lankhorstec193642019-06-28 10:55:17 +02004512 adjusted_pixel_rate = crtc_state->pixel_rate;
4513 downscale_amount = skl_plane_downscale_amount(crtc_state, plane_state);
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004514
Kumar, Mahesh7084b502017-05-17 17:28:23 +05304515 return mul_round_up_u32_fixed16(adjusted_pixel_rate,
4516 downscale_amount);
Kumar, Mahesh9c2f7a92016-05-16 15:52:00 -07004517}
4518
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304519static int
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004520skl_compute_wm_params(const struct intel_crtc_state *crtc_state,
4521 int width, const struct drm_format_info *format,
4522 u64 modifier, unsigned int rotation,
4523 u32 plane_pixel_rate, struct skl_wm_params *wp,
4524 int color_plane)
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304525{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004526 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004527 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004528 u32 interm_pbpl;
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304529
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05304530 /* only planar format has two planes */
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004531 if (color_plane == 1 && !drm_format_info_is_yuv_semiplanar(format)) {
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05304532 DRM_DEBUG_KMS("Non planar format have single plane\n");
Mahesh Kumar942aa2d2018-04-09 09:11:04 +05304533 return -EINVAL;
4534 }
4535
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004536 wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED ||
4537 modifier == I915_FORMAT_MOD_Yf_TILED ||
4538 modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
4539 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
4540 wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED;
4541 wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
4542 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
Ville Syrjäläd1d23d72019-09-13 22:31:54 +03004543 wp->is_planar = drm_format_info_is_yuv_semiplanar(format);
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304544
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004545 wp->width = width;
Ville Syrjälä45bee432018-11-14 23:07:28 +02004546 if (color_plane == 1 && wp->is_planar)
Mahesh Kumar942aa2d2018-04-09 09:11:04 +05304547 wp->width /= 2;
4548
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004549 wp->cpp = format->cpp[color_plane];
4550 wp->plane_pixel_rate = plane_pixel_rate;
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304551
Mahesh Kumardf8ee192018-01-30 11:49:11 -02004552 if (INTEL_GEN(dev_priv) >= 11 &&
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004553 modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1)
Mahesh Kumardf8ee192018-01-30 11:49:11 -02004554 wp->dbuf_block_size = 256;
4555 else
4556 wp->dbuf_block_size = 512;
4557
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004558 if (drm_rotation_90_or_270(rotation)) {
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304559 switch (wp->cpp) {
4560 case 1:
4561 wp->y_min_scanlines = 16;
4562 break;
4563 case 2:
4564 wp->y_min_scanlines = 8;
4565 break;
4566 case 4:
4567 wp->y_min_scanlines = 4;
4568 break;
4569 default:
4570 MISSING_CASE(wp->cpp);
4571 return -EINVAL;
4572 }
4573 } else {
4574 wp->y_min_scanlines = 4;
4575 }
4576
Ville Syrjälä60e983f2018-12-21 19:14:33 +02004577 if (skl_needs_memory_bw_wa(dev_priv))
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304578 wp->y_min_scanlines *= 2;
4579
4580 wp->plane_bytes_per_line = wp->width * wp->cpp;
4581 if (wp->y_tiled) {
4582 interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line *
Mahesh Kumardf8ee192018-01-30 11:49:11 -02004583 wp->y_min_scanlines,
4584 wp->dbuf_block_size);
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304585
4586 if (INTEL_GEN(dev_priv) >= 10)
4587 interm_pbpl++;
4588
4589 wp->plane_blocks_per_line = div_fixed16(interm_pbpl,
4590 wp->y_min_scanlines);
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004591 } else if (wp->x_tiled && IS_GEN(dev_priv, 9)) {
Mahesh Kumardf8ee192018-01-30 11:49:11 -02004592 interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line,
4593 wp->dbuf_block_size);
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304594 wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl);
4595 } else {
Mahesh Kumardf8ee192018-01-30 11:49:11 -02004596 interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line,
4597 wp->dbuf_block_size) + 1;
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304598 wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl);
4599 }
4600
4601 wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines,
4602 wp->plane_blocks_per_line);
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004603
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304604 wp->linetime_us = fixed16_to_u32_round_up(
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004605 intel_get_linetime_us(crtc_state));
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304606
4607 return 0;
4608}
4609
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004610static int
4611skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state,
4612 const struct intel_plane_state *plane_state,
4613 struct skl_wm_params *wp, int color_plane)
4614{
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01004615 const struct drm_framebuffer *fb = plane_state->hw.fb;
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004616 int width;
4617
Maarten Lankhorst3a612762019-10-04 13:34:54 +02004618 /*
4619 * Src coordinates are already rotated by 270 degrees for
4620 * the 90/270 degree plane rotation cases (to match the
4621 * GTT mapping), hence no need to account for rotation here.
4622 */
4623 width = drm_rect_width(&plane_state->base.src) >> 16;
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004624
4625 return skl_compute_wm_params(crtc_state, width,
4626 fb->format, fb->modifier,
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01004627 plane_state->hw.rotation,
Ville Syrjäläc92558a2019-03-12 22:58:38 +02004628 skl_adjusted_plane_pixel_rate(crtc_state, plane_state),
4629 wp, color_plane);
4630}
4631
Ville Syrjäläb52c2732018-12-21 19:14:28 +02004632static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level)
4633{
4634 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
4635 return true;
4636
4637 /* The number of lines are ignored for the level 0 watermark. */
4638 return level > 0;
4639}
4640
Maarten Lankhorstec193642019-06-28 10:55:17 +02004641static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state,
Matt Roperd8e87492018-12-11 09:31:07 -08004642 int level,
4643 const struct skl_wm_params *wp,
4644 const struct skl_wm_level *result_prev,
4645 struct skl_wm_level *result /* out */)
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004646{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004647 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004648 u32 latency = dev_priv->wm.skl_latency[level];
Mahesh Kumarb95320b2016-12-01 21:19:37 +05304649 uint_fixed_16_16_t method1, method2;
Mahesh Kumarb95320b2016-12-01 21:19:37 +05304650 uint_fixed_16_16_t selected_result;
Ville Syrjälä961d95e2018-12-21 19:14:32 +02004651 u32 res_blocks, res_lines, min_ddb_alloc = 0;
Ville Syrjäläce110ec2018-11-14 23:07:21 +02004652
Ville Syrjälä0aded172019-02-05 17:50:53 +02004653 if (latency == 0) {
4654 /* reject it */
4655 result->min_ddb_alloc = U16_MAX;
Ville Syrjälä692927f2018-12-21 19:14:29 +02004656 return;
Ville Syrjälä0aded172019-02-05 17:50:53 +02004657 }
Ville Syrjälä692927f2018-12-21 19:14:29 +02004658
Ville Syrjälä25312ef2019-05-03 20:38:05 +03004659 /*
4660 * WaIncreaseLatencyIPCEnabled: kbl,cfl
4661 * Display WA #1141: kbl,cfl
4662 */
Ville Syrjälä5a7d2022019-05-03 20:38:06 +03004663 if ((IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) ||
Rodrigo Vivi82525c12017-06-08 08:50:00 -07004664 dev_priv->ipc_enabled)
Mahesh Kumar4b7b2332016-12-01 21:19:35 +05304665 latency += 4;
4666
Ville Syrjälä60e983f2018-12-21 19:14:33 +02004667 if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled)
Paulo Zanoniee3d5322016-10-11 15:25:38 -03004668 latency += 15;
4669
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304670 method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate,
Mahesh Kumardf8ee192018-01-30 11:49:11 -02004671 wp->cpp, latency, wp->dbuf_block_size);
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304672 method2 = skl_wm_method2(wp->plane_pixel_rate,
Maarten Lankhorst1326a922019-10-31 12:26:02 +01004673 crtc_state->hw.adjusted_mode.crtc_htotal,
Paulo Zanoni1186fa82016-09-22 18:00:31 -03004674 latency,
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304675 wp->plane_blocks_per_line);
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004676
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304677 if (wp->y_tiled) {
4678 selected_result = max_fixed16(method2, wp->y_tile_minimum);
Tvrtko Ursulin0fda6562015-02-27 15:12:35 +00004679 } else {
Maarten Lankhorst1326a922019-10-31 12:26:02 +01004680 if ((wp->cpp * crtc_state->hw.adjusted_mode.crtc_htotal /
Mahesh Kumardf8ee192018-01-30 11:49:11 -02004681 wp->dbuf_block_size < 1) &&
Paulo Zanoni077b5822018-10-04 16:15:57 -07004682 (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) {
Paulo Zanonif1db3ea2016-09-22 18:00:34 -03004683 selected_result = method2;
Paulo Zanoni077b5822018-10-04 16:15:57 -07004684 } else if (latency >= wp->linetime_us) {
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004685 if (IS_GEN(dev_priv, 9) &&
Paulo Zanoni077b5822018-10-04 16:15:57 -07004686 !IS_GEMINILAKE(dev_priv))
4687 selected_result = min_fixed16(method1, method2);
4688 else
4689 selected_result = method2;
4690 } else {
Tvrtko Ursulin0fda6562015-02-27 15:12:35 +00004691 selected_result = method1;
Paulo Zanoni077b5822018-10-04 16:15:57 -07004692 }
Tvrtko Ursulin0fda6562015-02-27 15:12:35 +00004693 }
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004694
Kumar, Mahesheac2cb82017-07-05 20:01:46 +05304695 res_blocks = fixed16_to_u32_round_up(selected_result) + 1;
Kumar, Maheshd273ecc2017-05-17 17:28:22 +05304696 res_lines = div_round_up_fixed16(selected_result,
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304697 wp->plane_blocks_per_line);
Damien Lespiaue6d66172014-11-04 17:06:55 +00004698
Paulo Zanonia5b79d32018-11-13 17:24:32 -08004699 if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) {
4700 /* Display WA #1125: skl,bxt,kbl */
4701 if (level == 0 && wp->rc_surface)
4702 res_blocks +=
4703 fixed16_to_u32_round_up(wp->y_tile_minimum);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07004704
Paulo Zanonia5b79d32018-11-13 17:24:32 -08004705 /* Display WA #1126: skl,bxt,kbl */
4706 if (level >= 1 && level <= 7) {
4707 if (wp->y_tiled) {
4708 res_blocks +=
4709 fixed16_to_u32_round_up(wp->y_tile_minimum);
4710 res_lines += wp->y_min_scanlines;
4711 } else {
4712 res_blocks++;
4713 }
4714
4715 /*
4716 * Make sure result blocks for higher latency levels are
4717 * atleast as high as level below the current level.
4718 * Assumption in DDB algorithm optimization for special
4719 * cases. Also covers Display WA #1125 for RC.
4720 */
4721 if (result_prev->plane_res_b > res_blocks)
4722 res_blocks = result_prev->plane_res_b;
Paulo Zanoni75676ed2016-09-22 18:00:33 -03004723 }
Tvrtko Ursulin0fda6562015-02-27 15:12:35 +00004724 }
Tvrtko Ursulind4c2aa62015-02-27 11:15:22 +00004725
Ville Syrjälä961d95e2018-12-21 19:14:32 +02004726 if (INTEL_GEN(dev_priv) >= 11) {
4727 if (wp->y_tiled) {
4728 int extra_lines;
4729
4730 if (res_lines % wp->y_min_scanlines == 0)
4731 extra_lines = wp->y_min_scanlines;
4732 else
4733 extra_lines = wp->y_min_scanlines * 2 -
4734 res_lines % wp->y_min_scanlines;
4735
4736 min_ddb_alloc = mul_round_up_u32_fixed16(res_lines + extra_lines,
4737 wp->plane_blocks_per_line);
4738 } else {
4739 min_ddb_alloc = res_blocks +
4740 DIV_ROUND_UP(res_blocks, 10);
4741 }
4742 }
4743
Ville Syrjäläb52c2732018-12-21 19:14:28 +02004744 if (!skl_wm_has_lines(dev_priv, level))
4745 res_lines = 0;
4746
Ville Syrjälä0aded172019-02-05 17:50:53 +02004747 if (res_lines > 31) {
4748 /* reject it */
4749 result->min_ddb_alloc = U16_MAX;
Matt Roperd8e87492018-12-11 09:31:07 -08004750 return;
Ville Syrjälä0aded172019-02-05 17:50:53 +02004751 }
Matt Roperd8e87492018-12-11 09:31:07 -08004752
4753 /*
4754 * If res_lines is valid, assume we can use this watermark level
4755 * for now. We'll come back and disable it after we calculate the
4756 * DDB allocation if it turns out we don't actually have enough
4757 * blocks to satisfy it.
4758 */
Mahesh Kumar62027b72018-04-09 09:11:05 +05304759 result->plane_res_b = res_blocks;
4760 result->plane_res_l = res_lines;
Ville Syrjälä961d95e2018-12-21 19:14:32 +02004761 /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */
4762 result->min_ddb_alloc = max(min_ddb_alloc, res_blocks) + 1;
Mahesh Kumar62027b72018-04-09 09:11:05 +05304763 result->plane_en = true;
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004764}
4765
Matt Roperd8e87492018-12-11 09:31:07 -08004766static void
Maarten Lankhorstec193642019-06-28 10:55:17 +02004767skl_compute_wm_levels(const struct intel_crtc_state *crtc_state,
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304768 const struct skl_wm_params *wm_params,
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004769 struct skl_wm_level *levels)
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004770{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004771 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
Kumar, Maheshd2f5e362017-05-17 17:28:28 +05304772 int level, max_level = ilk_wm_max_level(dev_priv);
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004773 struct skl_wm_level *result_prev = &levels[0];
Lyudea62163e2016-10-04 14:28:20 -04004774
Kumar, Maheshd2f5e362017-05-17 17:28:28 +05304775 for (level = 0; level <= max_level; level++) {
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004776 struct skl_wm_level *result = &levels[level];
Kumar, Maheshd2f5e362017-05-17 17:28:28 +05304777
Maarten Lankhorstec193642019-06-28 10:55:17 +02004778 skl_compute_plane_wm(crtc_state, level, wm_params,
Matt Roperd8e87492018-12-11 09:31:07 -08004779 result_prev, result);
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004780
4781 result_prev = result;
Kumar, Maheshd2f5e362017-05-17 17:28:28 +05304782 }
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004783}
4784
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004785static u32
Maarten Lankhorstec193642019-06-28 10:55:17 +02004786skl_compute_linetime_wm(const struct intel_crtc_state *crtc_state)
Damien Lespiau407b50f2014-11-04 17:06:57 +00004787{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004788 struct drm_atomic_state *state = crtc_state->uapi.state;
Mahesh Kumara3a89862016-12-01 21:19:34 +05304789 struct drm_i915_private *dev_priv = to_i915(state->dev);
Kumar, Maheshd555cb52017-05-17 17:28:29 +05304790 uint_fixed_16_16_t linetime_us;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004791 u32 linetime_wm;
Paulo Zanoni30d1b5f2016-10-07 17:28:58 -03004792
Maarten Lankhorstec193642019-06-28 10:55:17 +02004793 linetime_us = intel_get_linetime_us(crtc_state);
Kumar, Mahesheac2cb82017-07-05 20:01:46 +05304794 linetime_wm = fixed16_to_u32_round_up(mul_u32_fixed16(8, linetime_us));
Mahesh Kumara3a89862016-12-01 21:19:34 +05304795
Ville Syrjälä717671c2018-12-21 19:14:36 +02004796 /* Display WA #1135: BXT:ALL GLK:ALL */
4797 if (IS_GEN9_LP(dev_priv) && dev_priv->ipc_enabled)
Kumar, Mahesh446e8502017-08-17 19:15:25 +05304798 linetime_wm /= 2;
Mahesh Kumara3a89862016-12-01 21:19:34 +05304799
4800 return linetime_wm;
Damien Lespiau407b50f2014-11-04 17:06:57 +00004801}
4802
Maarten Lankhorstec193642019-06-28 10:55:17 +02004803static void skl_compute_transition_wm(const struct intel_crtc_state *crtc_state,
Ville Syrjälä6a3c910b2018-11-14 23:07:23 +02004804 const struct skl_wm_params *wp,
Matt Roperd8e87492018-12-11 09:31:07 -08004805 struct skl_plane_wm *wm)
Damien Lespiau407b50f2014-11-04 17:06:57 +00004806{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004807 struct drm_device *dev = crtc_state->uapi.crtc->dev;
Kumar, Maheshca476672017-08-17 19:15:24 +05304808 const struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004809 u16 trans_min, trans_y_tile_min;
4810 const u16 trans_amount = 10; /* This is configurable amount */
4811 u16 wm0_sel_res_b, trans_offset_b, res_blocks;
Damien Lespiau9414f562014-11-04 17:06:58 +00004812
Kumar, Maheshca476672017-08-17 19:15:24 +05304813 /* Transition WM are not recommended by HW team for GEN9 */
4814 if (INTEL_GEN(dev_priv) <= 9)
Ville Syrjälä14a43062018-11-14 23:07:22 +02004815 return;
Kumar, Maheshca476672017-08-17 19:15:24 +05304816
4817 /* Transition WM don't make any sense if ipc is disabled */
4818 if (!dev_priv->ipc_enabled)
Ville Syrjälä14a43062018-11-14 23:07:22 +02004819 return;
Kumar, Maheshca476672017-08-17 19:15:24 +05304820
Paulo Zanoni91961a82018-10-04 16:15:56 -07004821 trans_min = 14;
4822 if (INTEL_GEN(dev_priv) >= 11)
Kumar, Maheshca476672017-08-17 19:15:24 +05304823 trans_min = 4;
4824
4825 trans_offset_b = trans_min + trans_amount;
4826
Paulo Zanonicbacc792018-10-04 16:15:58 -07004827 /*
4828 * The spec asks for Selected Result Blocks for wm0 (the real value),
4829 * not Result Blocks (the integer value). Pay attention to the capital
4830 * letters. The value wm_l0->plane_res_b is actually Result Blocks, but
4831 * since Result Blocks is the ceiling of Selected Result Blocks plus 1,
4832 * and since we later will have to get the ceiling of the sum in the
4833 * transition watermarks calculation, we can just pretend Selected
4834 * Result Blocks is Result Blocks minus 1 and it should work for the
4835 * current platforms.
4836 */
Ville Syrjälä6a3c910b2018-11-14 23:07:23 +02004837 wm0_sel_res_b = wm->wm[0].plane_res_b - 1;
Paulo Zanonicbacc792018-10-04 16:15:58 -07004838
Kumar, Maheshca476672017-08-17 19:15:24 +05304839 if (wp->y_tiled) {
Jani Nikula5ce9a6492019-01-18 14:01:20 +02004840 trans_y_tile_min =
4841 (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum);
Paulo Zanonicbacc792018-10-04 16:15:58 -07004842 res_blocks = max(wm0_sel_res_b, trans_y_tile_min) +
Kumar, Maheshca476672017-08-17 19:15:24 +05304843 trans_offset_b;
4844 } else {
Paulo Zanonicbacc792018-10-04 16:15:58 -07004845 res_blocks = wm0_sel_res_b + trans_offset_b;
Kumar, Maheshca476672017-08-17 19:15:24 +05304846
4847 /* WA BUG:1938466 add one block for non y-tile planes */
4848 if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_A0))
4849 res_blocks += 1;
4850
4851 }
4852
Matt Roperd8e87492018-12-11 09:31:07 -08004853 /*
4854 * Just assume we can enable the transition watermark. After
4855 * computing the DDB we'll come back and disable it if that
4856 * assumption turns out to be false.
4857 */
4858 wm->trans_wm.plane_res_b = res_blocks + 1;
4859 wm->trans_wm.plane_en = true;
Damien Lespiau407b50f2014-11-04 17:06:57 +00004860}
4861
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004862static int skl_build_plane_wm_single(struct intel_crtc_state *crtc_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004863 const struct intel_plane_state *plane_state,
4864 enum plane_id plane_id, int color_plane)
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004865{
Ville Syrjälä83158472018-11-27 18:57:26 +02004866 struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id];
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004867 struct skl_wm_params wm_params;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004868 int ret;
4869
Ville Syrjälä51de9c62018-11-14 23:07:25 +02004870 ret = skl_compute_plane_wm_params(crtc_state, plane_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004871 &wm_params, color_plane);
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004872 if (ret)
4873 return ret;
4874
Ville Syrjälä67155a62019-03-12 22:58:37 +02004875 skl_compute_wm_levels(crtc_state, &wm_params, wm->wm);
Matt Roperd8e87492018-12-11 09:31:07 -08004876 skl_compute_transition_wm(crtc_state, &wm_params, wm);
Ville Syrjälä83158472018-11-27 18:57:26 +02004877
4878 return 0;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004879}
4880
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004881static int skl_build_plane_wm_uv(struct intel_crtc_state *crtc_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004882 const struct intel_plane_state *plane_state,
4883 enum plane_id plane_id)
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004884{
Ville Syrjälä83158472018-11-27 18:57:26 +02004885 struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id];
4886 struct skl_wm_params wm_params;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004887 int ret;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004888
Ville Syrjälä83158472018-11-27 18:57:26 +02004889 wm->is_planar = true;
4890
4891 /* uv plane watermarks must also be validated for NV12/Planar */
Ville Syrjälä51de9c62018-11-14 23:07:25 +02004892 ret = skl_compute_plane_wm_params(crtc_state, plane_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004893 &wm_params, 1);
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004894 if (ret)
4895 return ret;
4896
Ville Syrjälä67155a62019-03-12 22:58:37 +02004897 skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm);
Ville Syrjälä83158472018-11-27 18:57:26 +02004898
4899 return 0;
4900}
4901
Ville Syrjälä96cb7cd2019-03-12 22:58:43 +02004902static int skl_build_plane_wm(struct intel_crtc_state *crtc_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004903 const struct intel_plane_state *plane_state)
4904{
4905 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01004906 const struct drm_framebuffer *fb = plane_state->hw.fb;
Ville Syrjälä83158472018-11-27 18:57:26 +02004907 enum plane_id plane_id = plane->id;
4908 int ret;
4909
4910 if (!intel_wm_plane_visible(crtc_state, plane_state))
4911 return 0;
4912
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004913 ret = skl_build_plane_wm_single(crtc_state, plane_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004914 plane_id, 0);
4915 if (ret)
4916 return ret;
4917
4918 if (fb->format->is_yuv && fb->format->num_planes > 1) {
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004919 ret = skl_build_plane_wm_uv(crtc_state, plane_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004920 plane_id);
4921 if (ret)
4922 return ret;
4923 }
4924
4925 return 0;
4926}
4927
Ville Syrjälä96cb7cd2019-03-12 22:58:43 +02004928static int icl_build_plane_wm(struct intel_crtc_state *crtc_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004929 const struct intel_plane_state *plane_state)
4930{
4931 enum plane_id plane_id = to_intel_plane(plane_state->base.plane)->id;
4932 int ret;
4933
4934 /* Watermarks calculated in master */
Maarten Lankhorstc47b7dd2019-09-20 13:42:20 +02004935 if (plane_state->planar_slave)
Ville Syrjälä83158472018-11-27 18:57:26 +02004936 return 0;
4937
Maarten Lankhorstc47b7dd2019-09-20 13:42:20 +02004938 if (plane_state->planar_linked_plane) {
Maarten Lankhorst7b3cb172019-10-31 12:26:07 +01004939 const struct drm_framebuffer *fb = plane_state->hw.fb;
Maarten Lankhorstc47b7dd2019-09-20 13:42:20 +02004940 enum plane_id y_plane_id = plane_state->planar_linked_plane->id;
Ville Syrjälä83158472018-11-27 18:57:26 +02004941
4942 WARN_ON(!intel_wm_plane_visible(crtc_state, plane_state));
4943 WARN_ON(!fb->format->is_yuv ||
4944 fb->format->num_planes == 1);
4945
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004946 ret = skl_build_plane_wm_single(crtc_state, plane_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004947 y_plane_id, 0);
4948 if (ret)
4949 return ret;
4950
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004951 ret = skl_build_plane_wm_single(crtc_state, plane_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004952 plane_id, 1);
4953 if (ret)
4954 return ret;
4955 } else if (intel_wm_plane_visible(crtc_state, plane_state)) {
Ville Syrjäläff43bc32018-11-27 18:59:00 +02004956 ret = skl_build_plane_wm_single(crtc_state, plane_state,
Ville Syrjälä83158472018-11-27 18:57:26 +02004957 plane_id, 0);
4958 if (ret)
4959 return ret;
4960 }
4961
4962 return 0;
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004963}
4964
Maarten Lankhorstec193642019-06-28 10:55:17 +02004965static int skl_build_pipe_wm(struct intel_crtc_state *crtc_state)
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004966{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01004967 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
Maarten Lankhorstec193642019-06-28 10:55:17 +02004968 struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal;
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02004969 struct intel_plane *plane;
4970 const struct intel_plane_state *plane_state;
Matt Roper55994c22016-05-12 07:06:08 -07004971 int ret;
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004972
Lyudea62163e2016-10-04 14:28:20 -04004973 /*
4974 * We'll only calculate watermarks for planes that are actually
4975 * enabled, so make sure all other planes are set as disabled.
4976 */
4977 memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes));
4978
Maarten Lankhorstaf9fbfa2019-10-04 13:34:53 +02004979 intel_atomic_crtc_state_for_each_plane_state(plane, plane_state,
4980 crtc_state) {
Kumar, Mahesheb2fdcd2017-05-17 17:28:27 +05304981
Ville Syrjälä83158472018-11-27 18:57:26 +02004982 if (INTEL_GEN(dev_priv) >= 11)
Maarten Lankhorstec193642019-06-28 10:55:17 +02004983 ret = icl_build_plane_wm(crtc_state, plane_state);
Maarten Lankhorstb048a002018-10-18 13:51:30 +02004984 else
Maarten Lankhorstec193642019-06-28 10:55:17 +02004985 ret = skl_build_plane_wm(crtc_state, plane_state);
Kumar, Mahesh7e452fd2017-08-17 19:15:23 +05304986 if (ret)
4987 return ret;
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004988 }
Mahesh Kumar942aa2d2018-04-09 09:11:04 +05304989
Maarten Lankhorstec193642019-06-28 10:55:17 +02004990 pipe_wm->linetime = skl_compute_linetime_wm(crtc_state);
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004991
Matt Roper55994c22016-05-12 07:06:08 -07004992 return 0;
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00004993}
4994
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004995static void skl_ddb_entry_write(struct drm_i915_private *dev_priv,
4996 i915_reg_t reg,
Damien Lespiau16160e32014-11-04 17:06:53 +00004997 const struct skl_ddb_entry *entry)
4998{
4999 if (entry->end)
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005000 I915_WRITE_FW(reg, (entry->end - 1) << 16 | entry->start);
Damien Lespiau16160e32014-11-04 17:06:53 +00005001 else
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005002 I915_WRITE_FW(reg, 0);
Damien Lespiau16160e32014-11-04 17:06:53 +00005003}
5004
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005005static void skl_write_wm_level(struct drm_i915_private *dev_priv,
5006 i915_reg_t reg,
5007 const struct skl_wm_level *level)
5008{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02005009 u32 val = 0;
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005010
Ville Syrjälä2ed8e1f2019-02-13 18:54:23 +02005011 if (level->plane_en)
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005012 val |= PLANE_WM_EN;
Ville Syrjälä2ed8e1f2019-02-13 18:54:23 +02005013 if (level->ignore_lines)
5014 val |= PLANE_WM_IGNORE_LINES;
5015 val |= level->plane_res_b;
5016 val |= level->plane_res_l << PLANE_WM_LINES_SHIFT;
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005017
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005018 I915_WRITE_FW(reg, val);
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005019}
5020
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005021void skl_write_plane_wm(struct intel_plane *plane,
5022 const struct intel_crtc_state *crtc_state)
Lyude62e0fb82016-08-22 12:50:08 -04005023{
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005024 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01005025 int level, max_level = ilk_wm_max_level(dev_priv);
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005026 enum plane_id plane_id = plane->id;
5027 enum pipe pipe = plane->pipe;
5028 const struct skl_plane_wm *wm =
5029 &crtc_state->wm.skl.optimal.planes[plane_id];
5030 const struct skl_ddb_entry *ddb_y =
5031 &crtc_state->wm.skl.plane_ddb_y[plane_id];
5032 const struct skl_ddb_entry *ddb_uv =
5033 &crtc_state->wm.skl.plane_ddb_uv[plane_id];
Lyude62e0fb82016-08-22 12:50:08 -04005034
5035 for (level = 0; level <= max_level; level++) {
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02005036 skl_write_wm_level(dev_priv, PLANE_WM(pipe, plane_id, level),
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005037 &wm->wm[level]);
Lyude62e0fb82016-08-22 12:50:08 -04005038 }
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02005039 skl_write_wm_level(dev_priv, PLANE_WM_TRANS(pipe, plane_id),
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005040 &wm->trans_wm);
Lyude27082492016-08-24 07:48:10 +02005041
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005042 if (INTEL_GEN(dev_priv) >= 11) {
Mahesh Kumar234059d2018-01-30 11:49:13 -02005043 skl_ddb_entry_write(dev_priv,
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005044 PLANE_BUF_CFG(pipe, plane_id), ddb_y);
5045 return;
Mahesh Kumarb879d582018-04-09 09:11:01 +05305046 }
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005047
5048 if (wm->is_planar)
5049 swap(ddb_y, ddb_uv);
5050
5051 skl_ddb_entry_write(dev_priv,
5052 PLANE_BUF_CFG(pipe, plane_id), ddb_y);
5053 skl_ddb_entry_write(dev_priv,
5054 PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv);
Lyude62e0fb82016-08-22 12:50:08 -04005055}
5056
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005057void skl_write_cursor_wm(struct intel_plane *plane,
5058 const struct intel_crtc_state *crtc_state)
Lyude62e0fb82016-08-22 12:50:08 -04005059{
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005060 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01005061 int level, max_level = ilk_wm_max_level(dev_priv);
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005062 enum plane_id plane_id = plane->id;
5063 enum pipe pipe = plane->pipe;
5064 const struct skl_plane_wm *wm =
5065 &crtc_state->wm.skl.optimal.planes[plane_id];
5066 const struct skl_ddb_entry *ddb =
5067 &crtc_state->wm.skl.plane_ddb_y[plane_id];
Lyude62e0fb82016-08-22 12:50:08 -04005068
5069 for (level = 0; level <= max_level; level++) {
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005070 skl_write_wm_level(dev_priv, CUR_WM(pipe, level),
5071 &wm->wm[level]);
Lyude62e0fb82016-08-22 12:50:08 -04005072 }
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005073 skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm);
Lyude27082492016-08-24 07:48:10 +02005074
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005075 skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb);
Lyude62e0fb82016-08-22 12:50:08 -04005076}
5077
cpaul@redhat.com45ece232016-10-14 17:31:56 -04005078bool skl_wm_level_equals(const struct skl_wm_level *l1,
5079 const struct skl_wm_level *l2)
5080{
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005081 return l1->plane_en == l2->plane_en &&
Ville Syrjälä2ed8e1f2019-02-13 18:54:23 +02005082 l1->ignore_lines == l2->ignore_lines &&
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005083 l1->plane_res_l == l2->plane_res_l &&
5084 l1->plane_res_b == l2->plane_res_b;
5085}
cpaul@redhat.com45ece232016-10-14 17:31:56 -04005086
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005087static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv,
5088 const struct skl_plane_wm *wm1,
5089 const struct skl_plane_wm *wm2)
5090{
5091 int level, max_level = ilk_wm_max_level(dev_priv);
cpaul@redhat.com45ece232016-10-14 17:31:56 -04005092
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005093 for (level = 0; level <= max_level; level++) {
5094 if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level]) ||
5095 !skl_wm_level_equals(&wm1->uv_wm[level], &wm2->uv_wm[level]))
5096 return false;
5097 }
5098
5099 return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm);
cpaul@redhat.com45ece232016-10-14 17:31:56 -04005100}
5101
Ville Syrjälä961d95e2018-12-21 19:14:32 +02005102static bool skl_pipe_wm_equals(struct intel_crtc *crtc,
5103 const struct skl_pipe_wm *wm1,
5104 const struct skl_pipe_wm *wm2)
5105{
5106 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5107 enum plane_id plane_id;
5108
5109 for_each_plane_id_on_crtc(crtc, plane_id) {
5110 if (!skl_plane_wm_equals(dev_priv,
5111 &wm1->planes[plane_id],
5112 &wm2->planes[plane_id]))
5113 return false;
5114 }
5115
5116 return wm1->linetime == wm2->linetime;
5117}
5118
Lyude27082492016-08-24 07:48:10 +02005119static inline bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a,
5120 const struct skl_ddb_entry *b)
Damien Lespiau0e8fb7b2014-11-04 17:07:02 +00005121{
Lyude27082492016-08-24 07:48:10 +02005122 return a->start < b->end && b->start < a->end;
Damien Lespiau0e8fb7b2014-11-04 17:07:02 +00005123}
5124
Ville Syrjälä53cc68802018-11-01 17:05:59 +02005125bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb,
Jani Nikula696173b2019-04-05 14:00:15 +03005126 const struct skl_ddb_entry *entries,
Ville Syrjälä53cc68802018-11-01 17:05:59 +02005127 int num_entries, int ignore_idx)
Damien Lespiau0e8fb7b2014-11-04 17:07:02 +00005128{
Ville Syrjälä53cc68802018-11-01 17:05:59 +02005129 int i;
Damien Lespiau0e8fb7b2014-11-04 17:07:02 +00005130
Ville Syrjälä53cc68802018-11-01 17:05:59 +02005131 for (i = 0; i < num_entries; i++) {
5132 if (i != ignore_idx &&
5133 skl_ddb_entries_overlap(ddb, &entries[i]))
Lyude27082492016-08-24 07:48:10 +02005134 return true;
Mika Kahola2b685042017-10-10 13:17:03 +03005135 }
Damien Lespiau0e8fb7b2014-11-04 17:07:02 +00005136
Lyude27082492016-08-24 07:48:10 +02005137 return false;
Damien Lespiau0e8fb7b2014-11-04 17:07:02 +00005138}
5139
Jani Nikulabb7791b2016-10-04 12:29:17 +03005140static int
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005141skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state,
5142 struct intel_crtc_state *new_crtc_state)
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07005143{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01005144 struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->uapi.state);
5145 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005146 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5147 struct intel_plane *plane;
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07005148
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005149 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5150 struct intel_plane_state *plane_state;
5151 enum plane_id plane_id = plane->id;
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07005152
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005153 if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id],
5154 &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) &&
5155 skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id],
5156 &new_crtc_state->wm.skl.plane_ddb_uv[plane_id]))
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07005157 continue;
5158
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005159 plane_state = intel_atomic_get_plane_state(state, plane);
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07005160 if (IS_ERR(plane_state))
5161 return PTR_ERR(plane_state);
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +02005162
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005163 new_crtc_state->update_planes |= BIT(plane_id);
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07005164 }
5165
5166 return 0;
5167}
5168
5169static int
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005170skl_compute_ddb(struct intel_atomic_state *state)
Matt Roper98d39492016-05-12 07:06:03 -07005171{
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005172 const struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5173 struct skl_ddb_allocation *ddb = &state->wm_results.ddb;
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005174 struct intel_crtc_state *old_crtc_state;
5175 struct intel_crtc_state *new_crtc_state;
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305176 struct intel_crtc *crtc;
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305177 int ret, i;
Matt Roper98d39492016-05-12 07:06:03 -07005178
Paulo Zanoni5a920b82016-10-04 14:37:32 -03005179 memcpy(ddb, &dev_priv->wm.skl_hw.ddb, sizeof(*ddb));
5180
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005181 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005182 new_crtc_state, i) {
5183 ret = skl_allocate_pipe_ddb(new_crtc_state, ddb);
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07005184 if (ret)
5185 return ret;
5186
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005187 ret = skl_ddb_add_affected_planes(old_crtc_state,
5188 new_crtc_state);
Rodrigo Vivi9a30a262017-06-13 10:52:30 -07005189 if (ret)
5190 return ret;
Matt Roper98d39492016-05-12 07:06:03 -07005191 }
5192
5193 return 0;
5194}
5195
Ville Syrjäläab98e942019-02-08 22:05:27 +02005196static char enast(bool enable)
5197{
5198 return enable ? '*' : ' ';
5199}
5200
Matt Roper2722efb2016-08-17 15:55:55 -04005201static void
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005202skl_print_wm_changes(struct intel_atomic_state *state)
cpaul@redhat.com413fc532016-10-14 17:31:54 -04005203{
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005204 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5205 const struct intel_crtc_state *old_crtc_state;
5206 const struct intel_crtc_state *new_crtc_state;
5207 struct intel_plane *plane;
5208 struct intel_crtc *crtc;
Maarten Lankhorst75704982016-11-01 12:04:10 +01005209 int i;
cpaul@redhat.com413fc532016-10-14 17:31:54 -04005210
Ville Syrjäläab98e942019-02-08 22:05:27 +02005211 if ((drm_debug & DRM_UT_KMS) == 0)
5212 return;
5213
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005214 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
5215 new_crtc_state, i) {
Ville Syrjäläab98e942019-02-08 22:05:27 +02005216 const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm;
5217
5218 old_pipe_wm = &old_crtc_state->wm.skl.optimal;
5219 new_pipe_wm = &new_crtc_state->wm.skl.optimal;
5220
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005221 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5222 enum plane_id plane_id = plane->id;
cpaul@redhat.com413fc532016-10-14 17:31:54 -04005223 const struct skl_ddb_entry *old, *new;
5224
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005225 old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id];
5226 new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id];
cpaul@redhat.com413fc532016-10-14 17:31:54 -04005227
cpaul@redhat.com413fc532016-10-14 17:31:54 -04005228 if (skl_ddb_entry_equal(old, new))
5229 continue;
5230
Ville Syrjäläab98e942019-02-08 22:05:27 +02005231 DRM_DEBUG_KMS("[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n",
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005232 plane->base.base.id, plane->base.name,
Ville Syrjäläab98e942019-02-08 22:05:27 +02005233 old->start, old->end, new->start, new->end,
5234 skl_ddb_entry_size(old), skl_ddb_entry_size(new));
5235 }
5236
5237 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5238 enum plane_id plane_id = plane->id;
5239 const struct skl_plane_wm *old_wm, *new_wm;
5240
5241 old_wm = &old_pipe_wm->planes[plane_id];
5242 new_wm = &new_pipe_wm->planes[plane_id];
5243
5244 if (skl_plane_wm_equals(dev_priv, old_wm, new_wm))
5245 continue;
5246
5247 DRM_DEBUG_KMS("[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm"
5248 " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm\n",
5249 plane->base.base.id, plane->base.name,
5250 enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en),
5251 enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en),
5252 enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en),
5253 enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en),
5254 enast(old_wm->trans_wm.plane_en),
5255 enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en),
5256 enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en),
5257 enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en),
5258 enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en),
5259 enast(new_wm->trans_wm.plane_en));
5260
Ville Syrjälä2ed8e1f2019-02-13 18:54:23 +02005261 DRM_DEBUG_KMS("[PLANE:%d:%s] lines %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d"
5262 " -> %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d\n",
Ville Syrjäläab98e942019-02-08 22:05:27 +02005263 plane->base.base.id, plane->base.name,
Ville Syrjälä2ed8e1f2019-02-13 18:54:23 +02005264 enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l,
5265 enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l,
5266 enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l,
5267 enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l,
5268 enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l,
5269 enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l,
5270 enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l,
5271 enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l,
5272 enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l,
5273
5274 enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l,
5275 enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l,
5276 enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l,
5277 enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l,
5278 enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l,
5279 enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l,
5280 enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l,
5281 enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l,
5282 enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.plane_res_l);
Ville Syrjäläab98e942019-02-08 22:05:27 +02005283
5284 DRM_DEBUG_KMS("[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d"
5285 " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n",
5286 plane->base.base.id, plane->base.name,
5287 old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b,
5288 old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b,
5289 old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b,
5290 old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b,
5291 old_wm->trans_wm.plane_res_b,
5292 new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b,
5293 new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b,
5294 new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b,
5295 new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b,
5296 new_wm->trans_wm.plane_res_b);
5297
5298 DRM_DEBUG_KMS("[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d"
5299 " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n",
5300 plane->base.base.id, plane->base.name,
5301 old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc,
5302 old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc,
5303 old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc,
5304 old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc,
5305 old_wm->trans_wm.min_ddb_alloc,
5306 new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc,
5307 new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc,
5308 new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc,
5309 new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc,
5310 new_wm->trans_wm.min_ddb_alloc);
cpaul@redhat.com413fc532016-10-14 17:31:54 -04005311 }
5312 }
5313}
5314
Ville Syrjälä49e0ed32019-10-11 23:09:43 +03005315static int intel_add_all_pipes(struct intel_atomic_state *state)
5316{
5317 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5318 struct intel_crtc *crtc;
5319
5320 for_each_intel_crtc(&dev_priv->drm, crtc) {
5321 struct intel_crtc_state *crtc_state;
5322
5323 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5324 if (IS_ERR(crtc_state))
5325 return PTR_ERR(crtc_state);
5326 }
5327
5328 return 0;
5329}
5330
Matt Roper98d39492016-05-12 07:06:03 -07005331static int
Ville Syrjäläd7a14582019-10-11 23:09:42 +03005332skl_ddb_add_affected_pipes(struct intel_atomic_state *state)
Matt Roper98d39492016-05-12 07:06:03 -07005333{
Ville Syrjälä49e0ed32019-10-11 23:09:43 +03005334 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
Ville Syrjäläd7a14582019-10-11 23:09:42 +03005335 int ret;
Matt Roper98d39492016-05-12 07:06:03 -07005336
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305337 /*
5338 * If this is our first atomic update following hardware readout,
5339 * we can't trust the DDB that the BIOS programmed for us. Let's
5340 * pretend that all pipes switched active status so that we'll
5341 * ensure a full DDB recompute.
5342 */
5343 if (dev_priv->wm.distrust_bios_wm) {
Ville Syrjälä49e0ed32019-10-11 23:09:43 +03005344 ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex,
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005345 state->base.acquire_ctx);
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305346 if (ret)
5347 return ret;
5348
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005349 state->active_pipe_changes = ~0;
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305350
5351 /*
Ville Syrjäläd06a79d2019-08-21 20:30:29 +03005352 * We usually only initialize state->active_pipes if we
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305353 * we're doing a modeset; make sure this field is always
5354 * initialized during the sanitization process that happens
5355 * on the first commit too.
5356 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005357 if (!state->modeset)
Ville Syrjäläd06a79d2019-08-21 20:30:29 +03005358 state->active_pipes = dev_priv->active_pipes;
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305359 }
5360
5361 /*
5362 * If the modeset changes which CRTC's are active, we need to
5363 * recompute the DDB allocation for *all* active pipes, even
5364 * those that weren't otherwise being modified in any way by this
5365 * atomic commit. Due to the shrinking of the per-pipe allocations
5366 * when new active CRTC's are added, it's possible for a pipe that
5367 * we were already using and aren't changing at all here to suddenly
5368 * become invalid if its DDB needs exceeds its new allocation.
5369 *
5370 * Note that if we wind up doing a full DDB recompute, we can't let
5371 * any other display updates race with this transaction, so we need
5372 * to grab the lock on *all* CRTC's.
5373 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005374 if (state->active_pipe_changes || state->modeset) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005375 state->wm_results.dirty_pipes = ~0;
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305376
Ville Syrjälä49e0ed32019-10-11 23:09:43 +03005377 ret = intel_add_all_pipes(state);
5378 if (ret)
5379 return ret;
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305380 }
5381
5382 return 0;
5383}
5384
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005385/*
5386 * To make sure the cursor watermark registers are always consistent
5387 * with our computed state the following scenario needs special
5388 * treatment:
5389 *
5390 * 1. enable cursor
5391 * 2. move cursor entirely offscreen
5392 * 3. disable cursor
5393 *
5394 * Step 2. does call .disable_plane() but does not zero the watermarks
5395 * (since we consider an offscreen cursor still active for the purposes
5396 * of watermarks). Step 3. would not normally call .disable_plane()
5397 * because the actual plane visibility isn't changing, and we don't
5398 * deallocate the cursor ddb until the pipe gets disabled. So we must
5399 * force step 3. to call .disable_plane() to update the watermark
5400 * registers properly.
5401 *
5402 * Other planes do not suffer from this issues as their watermarks are
5403 * calculated based on the actual plane visibility. The only time this
5404 * can trigger for the other planes is during the initial readout as the
5405 * default value of the watermarks registers is not zero.
5406 */
5407static int skl_wm_add_affected_planes(struct intel_atomic_state *state,
5408 struct intel_crtc *crtc)
5409{
5410 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5411 const struct intel_crtc_state *old_crtc_state =
5412 intel_atomic_get_old_crtc_state(state, crtc);
5413 struct intel_crtc_state *new_crtc_state =
5414 intel_atomic_get_new_crtc_state(state, crtc);
5415 struct intel_plane *plane;
5416
5417 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5418 struct intel_plane_state *plane_state;
5419 enum plane_id plane_id = plane->id;
5420
5421 /*
5422 * Force a full wm update for every plane on modeset.
5423 * Required because the reset value of the wm registers
5424 * is non-zero, whereas we want all disabled planes to
5425 * have zero watermarks. So if we turn off the relevant
5426 * power well the hardware state will go out of sync
5427 * with the software state.
5428 */
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01005429 if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) &&
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005430 skl_plane_wm_equals(dev_priv,
5431 &old_crtc_state->wm.skl.optimal.planes[plane_id],
5432 &new_crtc_state->wm.skl.optimal.planes[plane_id]))
5433 continue;
5434
5435 plane_state = intel_atomic_get_plane_state(state, plane);
5436 if (IS_ERR(plane_state))
5437 return PTR_ERR(plane_state);
5438
5439 new_crtc_state->update_planes |= BIT(plane_id);
5440 }
5441
5442 return 0;
5443}
5444
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305445static int
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005446skl_compute_wm(struct intel_atomic_state *state)
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305447{
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005448 struct intel_crtc *crtc;
Ville Syrjälä8cac9fd2019-03-12 22:58:44 +02005449 struct intel_crtc_state *new_crtc_state;
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005450 struct intel_crtc_state *old_crtc_state;
5451 struct skl_ddb_values *results = &state->wm_results;
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305452 int ret, i;
5453
Matt Roper734fa012016-05-12 15:11:40 -07005454 /* Clear all dirty flags */
5455 results->dirty_pipes = 0;
5456
Ville Syrjäläd7a14582019-10-11 23:09:42 +03005457 ret = skl_ddb_add_affected_pipes(state);
5458 if (ret)
Mahesh Kumare1f96a62018-04-09 09:11:08 +05305459 return ret;
5460
Matt Roper734fa012016-05-12 15:11:40 -07005461 /*
5462 * Calculate WM's for all pipes that are part of this transaction.
Matt Roperd8e87492018-12-11 09:31:07 -08005463 * Note that skl_ddb_add_affected_pipes may have added more CRTC's that
Matt Roper734fa012016-05-12 15:11:40 -07005464 * weren't otherwise being modified (and set bits in dirty_pipes) if
5465 * pipe allocations had to change.
Matt Roper734fa012016-05-12 15:11:40 -07005466 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005467 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
Ville Syrjälä8cac9fd2019-03-12 22:58:44 +02005468 new_crtc_state, i) {
5469 ret = skl_build_pipe_wm(new_crtc_state);
Ville Syrjäläff43bc32018-11-27 18:59:00 +02005470 if (ret)
5471 return ret;
5472
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005473 ret = skl_wm_add_affected_planes(state, crtc);
Matt Roper734fa012016-05-12 15:11:40 -07005474 if (ret)
5475 return ret;
5476
Ville Syrjälä8cac9fd2019-03-12 22:58:44 +02005477 if (!skl_pipe_wm_equals(crtc,
5478 &old_crtc_state->wm.skl.optimal,
5479 &new_crtc_state->wm.skl.optimal))
Ville Syrjälä36b53a22019-10-11 23:09:44 +03005480 results->dirty_pipes |= BIT(crtc->pipe);
Matt Roper734fa012016-05-12 15:11:40 -07005481 }
5482
Matt Roperd8e87492018-12-11 09:31:07 -08005483 ret = skl_compute_ddb(state);
5484 if (ret)
5485 return ret;
5486
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005487 skl_print_wm_changes(state);
cpaul@redhat.com413fc532016-10-14 17:31:54 -04005488
Matt Roper98d39492016-05-12 07:06:03 -07005489 return 0;
5490}
5491
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005492static void skl_atomic_update_crtc_wm(struct intel_atomic_state *state,
Maarten Lankhorstec193642019-06-28 10:55:17 +02005493 struct intel_crtc_state *crtc_state)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005494{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01005495 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005496 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
Maarten Lankhorstec193642019-06-28 10:55:17 +02005497 struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005498 enum pipe pipe = crtc->pipe;
Maarten Lankhorste62929b2016-11-08 13:55:33 +01005499
Ville Syrjälä36b53a22019-10-11 23:09:44 +03005500 if ((state->wm_results.dirty_pipes & BIT(crtc->pipe)) == 0)
Maarten Lankhorste62929b2016-11-08 13:55:33 +01005501 return;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005502
5503 I915_WRITE(PIPE_WM_LINETIME(pipe), pipe_wm->linetime);
5504}
5505
Maarten Lankhorste62929b2016-11-08 13:55:33 +01005506static void skl_initial_wm(struct intel_atomic_state *state,
Maarten Lankhorstec193642019-06-28 10:55:17 +02005507 struct intel_crtc_state *crtc_state)
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00005508{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01005509 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjälä36b53a22019-10-11 23:09:44 +03005510 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Mahesh Kumar60f8e872018-04-09 09:11:00 +05305511 struct skl_ddb_values *results = &state->wm_results;
Bob Paauweadda50b2015-07-21 10:42:53 -07005512
Ville Syrjälä36b53a22019-10-11 23:09:44 +03005513 if ((results->dirty_pipes & BIT(crtc->pipe)) == 0)
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00005514 return;
5515
Matt Roper734fa012016-05-12 15:11:40 -07005516 mutex_lock(&dev_priv->wm.wm_mutex);
5517
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01005518 if (crtc_state->uapi.active_changed)
Maarten Lankhorstec193642019-06-28 10:55:17 +02005519 skl_atomic_update_crtc_wm(state, crtc_state);
Lyude27082492016-08-24 07:48:10 +02005520
Matt Roper734fa012016-05-12 15:11:40 -07005521 mutex_unlock(&dev_priv->wm.wm_mutex);
Pradeep Bhat2d41c0b2014-11-04 17:06:42 +00005522}
5523
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005524static void ilk_compute_wm_config(struct drm_i915_private *dev_priv,
Ville Syrjäläd8905652016-01-14 14:53:35 +02005525 struct intel_wm_config *config)
5526{
5527 struct intel_crtc *crtc;
5528
5529 /* Compute the currently _active_ config */
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005530 for_each_intel_crtc(&dev_priv->drm, crtc) {
Ville Syrjäläd8905652016-01-14 14:53:35 +02005531 const struct intel_pipe_wm *wm = &crtc->wm.active.ilk;
5532
5533 if (!wm->pipe_enabled)
5534 continue;
5535
5536 config->sprites_enabled |= wm->sprites_enabled;
5537 config->sprites_scaled |= wm->sprites_scaled;
5538 config->num_pipes_active++;
5539 }
5540}
5541
Matt Ropered4a6a72016-02-23 17:20:13 -08005542static void ilk_program_watermarks(struct drm_i915_private *dev_priv)
Paulo Zanoni801bcff2013-05-31 10:08:35 -03005543{
Ville Syrjäläb9d5c832015-09-24 15:53:14 -07005544 struct intel_pipe_wm lp_wm_1_2 = {}, lp_wm_5_6 = {}, *best_lp_wm;
Imre Deak820c1982013-12-17 14:46:36 +02005545 struct ilk_wm_maximums max;
Ville Syrjäläd8905652016-01-14 14:53:35 +02005546 struct intel_wm_config config = {};
Imre Deak820c1982013-12-17 14:46:36 +02005547 struct ilk_wm_values results = {};
Ville Syrjälä77c122b2013-08-06 22:24:04 +03005548 enum intel_ddb_partitioning partitioning;
Matt Roper261a27d2015-10-08 15:28:25 -07005549
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005550 ilk_compute_wm_config(dev_priv, &config);
Ville Syrjäläd8905652016-01-14 14:53:35 +02005551
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005552 ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max);
5553 ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2);
Ville Syrjälä0362c782013-10-09 19:17:57 +03005554
Ville Syrjäläa485bfb2013-10-09 19:17:59 +03005555 /* 5/6 split only in single pipe config on IVB+ */
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00005556 if (INTEL_GEN(dev_priv) >= 7 &&
Ville Syrjäläd8905652016-01-14 14:53:35 +02005557 config.num_pipes_active == 1 && config.sprites_enabled) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005558 ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max);
5559 ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6);
Ville Syrjäläa485bfb2013-10-09 19:17:59 +03005560
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005561 best_lp_wm = ilk_find_best_result(dev_priv, &lp_wm_1_2, &lp_wm_5_6);
Paulo Zanoni861f3382013-05-31 10:19:21 -03005562 } else {
Ville Syrjälä198a1e92013-10-09 19:17:58 +03005563 best_lp_wm = &lp_wm_1_2;
Paulo Zanoni861f3382013-05-31 10:19:21 -03005564 }
5565
Ville Syrjälä198a1e92013-10-09 19:17:58 +03005566 partitioning = (best_lp_wm == &lp_wm_1_2) ?
Ville Syrjälä77c122b2013-08-06 22:24:04 +03005567 INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6;
Paulo Zanoni861f3382013-05-31 10:19:21 -03005568
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005569 ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results);
Ville Syrjälä609cede2013-10-09 19:18:03 +03005570
Imre Deak820c1982013-12-17 14:46:36 +02005571 ilk_write_wm_values(dev_priv, &results);
Paulo Zanoni1011d8c2013-05-09 16:55:50 -03005572}
5573
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005574static void ilk_initial_watermarks(struct intel_atomic_state *state,
Maarten Lankhorstec193642019-06-28 10:55:17 +02005575 struct intel_crtc_state *crtc_state)
Ville Syrjäläb9d5c832015-09-24 15:53:14 -07005576{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01005577 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5578 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjäläb9d5c832015-09-24 15:53:14 -07005579
Matt Ropered4a6a72016-02-23 17:20:13 -08005580 mutex_lock(&dev_priv->wm.wm_mutex);
Ville Syrjälä88016a92019-07-01 19:05:45 +03005581 crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate;
Matt Ropered4a6a72016-02-23 17:20:13 -08005582 ilk_program_watermarks(dev_priv);
5583 mutex_unlock(&dev_priv->wm.wm_mutex);
5584}
Ville Syrjäläb9d5c832015-09-24 15:53:14 -07005585
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005586static void ilk_optimize_watermarks(struct intel_atomic_state *state,
Maarten Lankhorstec193642019-06-28 10:55:17 +02005587 struct intel_crtc_state *crtc_state)
Matt Ropered4a6a72016-02-23 17:20:13 -08005588{
Maarten Lankhorst2225f3c2019-10-31 12:26:03 +01005589 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5590 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
Ville Syrjälä88016a92019-07-01 19:05:45 +03005591
5592 if (!crtc_state->wm.need_postvbl_update)
5593 return;
Matt Ropered4a6a72016-02-23 17:20:13 -08005594
5595 mutex_lock(&dev_priv->wm.wm_mutex);
Ville Syrjälä88016a92019-07-01 19:05:45 +03005596 crtc->wm.active.ilk = crtc_state->wm.ilk.optimal;
5597 ilk_program_watermarks(dev_priv);
Matt Ropered4a6a72016-02-23 17:20:13 -08005598 mutex_unlock(&dev_priv->wm.wm_mutex);
Ville Syrjäläb9d5c832015-09-24 15:53:14 -07005599}
5600
Jani Nikula5ce9a6492019-01-18 14:01:20 +02005601static inline void skl_wm_level_from_reg_val(u32 val,
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005602 struct skl_wm_level *level)
Pradeep Bhat30789992014-11-04 17:06:45 +00005603{
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005604 level->plane_en = val & PLANE_WM_EN;
Ville Syrjälä2ed8e1f2019-02-13 18:54:23 +02005605 level->ignore_lines = val & PLANE_WM_IGNORE_LINES;
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005606 level->plane_res_b = val & PLANE_WM_BLOCKS_MASK;
5607 level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) &
5608 PLANE_WM_LINES_MASK;
Pradeep Bhat30789992014-11-04 17:06:45 +00005609}
5610
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005611void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc,
cpaul@redhat.combf9d99a2016-10-14 17:31:55 -04005612 struct skl_pipe_wm *out)
Pradeep Bhat30789992014-11-04 17:06:45 +00005613{
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005614 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5615 enum pipe pipe = crtc->pipe;
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02005616 int level, max_level;
5617 enum plane_id plane_id;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02005618 u32 val;
Pradeep Bhat30789992014-11-04 17:06:45 +00005619
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01005620 max_level = ilk_wm_max_level(dev_priv);
Pradeep Bhat30789992014-11-04 17:06:45 +00005621
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005622 for_each_plane_id_on_crtc(crtc, plane_id) {
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02005623 struct skl_plane_wm *wm = &out->planes[plane_id];
Pradeep Bhat30789992014-11-04 17:06:45 +00005624
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005625 for (level = 0; level <= max_level; level++) {
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02005626 if (plane_id != PLANE_CURSOR)
5627 val = I915_READ(PLANE_WM(pipe, plane_id, level));
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005628 else
5629 val = I915_READ(CUR_WM(pipe, level));
5630
5631 skl_wm_level_from_reg_val(val, &wm->wm[level]);
5632 }
5633
Ville Syrjäläd5cdfdf52016-11-22 18:01:58 +02005634 if (plane_id != PLANE_CURSOR)
5635 val = I915_READ(PLANE_WM_TRANS(pipe, plane_id));
cpaul@redhat.comd8c0faf2016-10-18 16:09:49 -02005636 else
5637 val = I915_READ(CUR_WM_TRANS(pipe));
5638
5639 skl_wm_level_from_reg_val(val, &wm->trans_wm);
5640 }
Pradeep Bhat30789992014-11-04 17:06:45 +00005641
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005642 if (!crtc->active)
Pradeep Bhat30789992014-11-04 17:06:45 +00005643 return;
5644
cpaul@redhat.combf9d99a2016-10-14 17:31:55 -04005645 out->linetime = I915_READ(PIPE_WM_LINETIME(pipe));
Pradeep Bhat30789992014-11-04 17:06:45 +00005646}
5647
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005648void skl_wm_get_hw_state(struct drm_i915_private *dev_priv)
Pradeep Bhat30789992014-11-04 17:06:45 +00005649{
Mahesh Kumar60f8e872018-04-09 09:11:00 +05305650 struct skl_ddb_values *hw = &dev_priv->wm.skl_hw;
Damien Lespiaua269c582014-11-04 17:06:49 +00005651 struct skl_ddb_allocation *ddb = &dev_priv->wm.skl_hw.ddb;
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005652 struct intel_crtc *crtc;
Maarten Lankhorstec193642019-06-28 10:55:17 +02005653 struct intel_crtc_state *crtc_state;
Pradeep Bhat30789992014-11-04 17:06:45 +00005654
Damien Lespiaua269c582014-11-04 17:06:49 +00005655 skl_ddb_get_hw_state(dev_priv, ddb);
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005656 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorstec193642019-06-28 10:55:17 +02005657 crtc_state = to_intel_crtc_state(crtc->base.state);
cpaul@redhat.combf9d99a2016-10-14 17:31:55 -04005658
Maarten Lankhorstec193642019-06-28 10:55:17 +02005659 skl_pipe_wm_get_hw_state(crtc, &crtc_state->wm.skl.optimal);
cpaul@redhat.combf9d99a2016-10-14 17:31:55 -04005660
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005661 if (crtc->active)
Ville Syrjälä36b53a22019-10-11 23:09:44 +03005662 hw->dirty_pipes |= BIT(crtc->pipe);
cpaul@redhat.combf9d99a2016-10-14 17:31:55 -04005663 }
Matt Ropera1de91e2016-05-12 07:05:57 -07005664
Ville Syrjäläd06a79d2019-08-21 20:30:29 +03005665 if (dev_priv->active_pipes) {
Matt Roper279e99d2016-05-12 07:06:02 -07005666 /* Fully recompute DDB on first atomic commit */
5667 dev_priv->wm.distrust_bios_wm = true;
Matt Roper279e99d2016-05-12 07:06:02 -07005668 }
Pradeep Bhat30789992014-11-04 17:06:45 +00005669}
5670
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005671static void ilk_pipe_wm_get_hw_state(struct intel_crtc *crtc)
Ville Syrjälä243e6a42013-10-14 14:55:24 +03005672{
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005673 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005674 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak820c1982013-12-17 14:46:36 +02005675 struct ilk_wm_values *hw = &dev_priv->wm.hw;
Maarten Lankhorstec193642019-06-28 10:55:17 +02005676 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
5677 struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal;
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005678 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005679 static const i915_reg_t wm0_pipe_reg[] = {
Ville Syrjälä243e6a42013-10-14 14:55:24 +03005680 [PIPE_A] = WM0_PIPEA_ILK,
5681 [PIPE_B] = WM0_PIPEB_ILK,
5682 [PIPE_C] = WM0_PIPEC_IVB,
5683 };
5684
5685 hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]);
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005686 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ville Syrjäläce0e0712013-12-05 15:51:36 +02005687 hw->wm_linetime[pipe] = I915_READ(PIPE_WM_LINETIME(pipe));
Ville Syrjälä243e6a42013-10-14 14:55:24 +03005688
Ville Syrjälä15606532016-05-13 17:55:17 +03005689 memset(active, 0, sizeof(*active));
5690
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005691 active->pipe_enabled = crtc->active;
Ville Syrjälä2a44b762014-03-07 18:32:09 +02005692
5693 if (active->pipe_enabled) {
Ville Syrjälä243e6a42013-10-14 14:55:24 +03005694 u32 tmp = hw->wm_pipe[pipe];
5695
5696 /*
5697 * For active pipes LP0 watermark is marked as
5698 * enabled, and LP1+ watermaks as disabled since
5699 * we can't really reverse compute them in case
5700 * multiple pipes are active.
5701 */
5702 active->wm[0].enable = true;
5703 active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT;
5704 active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT;
5705 active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK;
5706 active->linetime = hw->wm_linetime[pipe];
5707 } else {
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01005708 int level, max_level = ilk_wm_max_level(dev_priv);
Ville Syrjälä243e6a42013-10-14 14:55:24 +03005709
5710 /*
5711 * For inactive pipes, all watermark levels
5712 * should be marked as enabled but zeroed,
5713 * which is what we'd compute them to.
5714 */
5715 for (level = 0; level <= max_level; level++)
5716 active->wm[level].enable = true;
5717 }
Matt Roper4e0963c2015-09-24 15:53:15 -07005718
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005719 crtc->wm.active.ilk = *active;
Ville Syrjälä243e6a42013-10-14 14:55:24 +03005720}
5721
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005722#define _FW_WM(value, plane) \
5723 (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT)
5724#define _FW_WM_VLV(value, plane) \
5725 (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT)
5726
Ville Syrjälä04548cb2017-04-21 21:14:29 +03005727static void g4x_read_wm_values(struct drm_i915_private *dev_priv,
5728 struct g4x_wm_values *wm)
5729{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02005730 u32 tmp;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03005731
5732 tmp = I915_READ(DSPFW1);
5733 wm->sr.plane = _FW_WM(tmp, SR);
5734 wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB);
5735 wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB);
5736 wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA);
5737
5738 tmp = I915_READ(DSPFW2);
5739 wm->fbc_en = tmp & DSPFW_FBC_SR_EN;
5740 wm->sr.fbc = _FW_WM(tmp, FBC_SR);
5741 wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR);
5742 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB);
5743 wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA);
5744 wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA);
5745
5746 tmp = I915_READ(DSPFW3);
5747 wm->hpll_en = tmp & DSPFW_HPLL_SR_EN;
5748 wm->sr.cursor = _FW_WM(tmp, CURSOR_SR);
5749 wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR);
5750 wm->hpll.plane = _FW_WM(tmp, HPLL_SR);
5751}
5752
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005753static void vlv_read_wm_values(struct drm_i915_private *dev_priv,
5754 struct vlv_wm_values *wm)
5755{
5756 enum pipe pipe;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02005757 u32 tmp;
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005758
5759 for_each_pipe(dev_priv, pipe) {
5760 tmp = I915_READ(VLV_DDL(pipe));
5761
Ville Syrjälä1b313892016-11-28 19:37:08 +02005762 wm->ddl[pipe].plane[PLANE_PRIMARY] =
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005763 (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005764 wm->ddl[pipe].plane[PLANE_CURSOR] =
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005765 (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005766 wm->ddl[pipe].plane[PLANE_SPRITE0] =
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005767 (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005768 wm->ddl[pipe].plane[PLANE_SPRITE1] =
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005769 (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
5770 }
5771
5772 tmp = I915_READ(DSPFW1);
5773 wm->sr.plane = _FW_WM(tmp, SR);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005774 wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB);
5775 wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB);
5776 wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEA);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005777
5778 tmp = I915_READ(DSPFW2);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005779 wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB);
5780 wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA);
5781 wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEA);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005782
5783 tmp = I915_READ(DSPFW3);
5784 wm->sr.cursor = _FW_WM(tmp, CURSOR_SR);
5785
5786 if (IS_CHERRYVIEW(dev_priv)) {
5787 tmp = I915_READ(DSPFW7_CHV);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005788 wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED);
5789 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEC);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005790
5791 tmp = I915_READ(DSPFW8_CHV);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005792 wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF);
5793 wm->pipe[PIPE_C].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEE);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005794
5795 tmp = I915_READ(DSPFW9_CHV);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005796 wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC);
5797 wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005798
5799 tmp = I915_READ(DSPHOWM);
5800 wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9;
Ville Syrjälä1b313892016-11-28 19:37:08 +02005801 wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8;
5802 wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8;
5803 wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8;
5804 wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8;
5805 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8;
5806 wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8;
5807 wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8;
5808 wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8;
5809 wm->pipe[PIPE_A].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEA_HI) << 8;
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005810 } else {
5811 tmp = I915_READ(DSPFW7);
Ville Syrjälä1b313892016-11-28 19:37:08 +02005812 wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED);
5813 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEC);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005814
5815 tmp = I915_READ(DSPHOWM);
5816 wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9;
Ville Syrjälä1b313892016-11-28 19:37:08 +02005817 wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8;
5818 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8;
5819 wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8;
5820 wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8;
5821 wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8;
5822 wm->pipe[PIPE_A].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEA_HI) << 8;
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005823 }
5824}
5825
5826#undef _FW_WM
5827#undef _FW_WM_VLV
5828
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005829void g4x_wm_get_hw_state(struct drm_i915_private *dev_priv)
Ville Syrjälä04548cb2017-04-21 21:14:29 +03005830{
Ville Syrjälä04548cb2017-04-21 21:14:29 +03005831 struct g4x_wm_values *wm = &dev_priv->wm.g4x;
5832 struct intel_crtc *crtc;
5833
5834 g4x_read_wm_values(dev_priv, wm);
5835
5836 wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
5837
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005838 for_each_intel_crtc(&dev_priv->drm, crtc) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +03005839 struct intel_crtc_state *crtc_state =
5840 to_intel_crtc_state(crtc->base.state);
5841 struct g4x_wm_state *active = &crtc->wm.active.g4x;
5842 struct g4x_pipe_wm *raw;
5843 enum pipe pipe = crtc->pipe;
5844 enum plane_id plane_id;
5845 int level, max_level;
5846
5847 active->cxsr = wm->cxsr;
5848 active->hpll_en = wm->hpll_en;
5849 active->fbc_en = wm->fbc_en;
5850
5851 active->sr = wm->sr;
5852 active->hpll = wm->hpll;
5853
5854 for_each_plane_id_on_crtc(crtc, plane_id) {
5855 active->wm.plane[plane_id] =
5856 wm->pipe[pipe].plane[plane_id];
5857 }
5858
5859 if (wm->cxsr && wm->hpll_en)
5860 max_level = G4X_WM_LEVEL_HPLL;
5861 else if (wm->cxsr)
5862 max_level = G4X_WM_LEVEL_SR;
5863 else
5864 max_level = G4X_WM_LEVEL_NORMAL;
5865
5866 level = G4X_WM_LEVEL_NORMAL;
5867 raw = &crtc_state->wm.g4x.raw[level];
5868 for_each_plane_id_on_crtc(crtc, plane_id)
5869 raw->plane[plane_id] = active->wm.plane[plane_id];
5870
5871 if (++level > max_level)
5872 goto out;
5873
5874 raw = &crtc_state->wm.g4x.raw[level];
5875 raw->plane[PLANE_PRIMARY] = active->sr.plane;
5876 raw->plane[PLANE_CURSOR] = active->sr.cursor;
5877 raw->plane[PLANE_SPRITE0] = 0;
5878 raw->fbc = active->sr.fbc;
5879
5880 if (++level > max_level)
5881 goto out;
5882
5883 raw = &crtc_state->wm.g4x.raw[level];
5884 raw->plane[PLANE_PRIMARY] = active->hpll.plane;
5885 raw->plane[PLANE_CURSOR] = active->hpll.cursor;
5886 raw->plane[PLANE_SPRITE0] = 0;
5887 raw->fbc = active->hpll.fbc;
5888
5889 out:
5890 for_each_plane_id_on_crtc(crtc, plane_id)
5891 g4x_raw_plane_wm_set(crtc_state, level,
5892 plane_id, USHRT_MAX);
5893 g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX);
5894
5895 crtc_state->wm.g4x.optimal = *active;
5896 crtc_state->wm.g4x.intermediate = *active;
5897
5898 DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n",
5899 pipe_name(pipe),
5900 wm->pipe[pipe].plane[PLANE_PRIMARY],
5901 wm->pipe[pipe].plane[PLANE_CURSOR],
5902 wm->pipe[pipe].plane[PLANE_SPRITE0]);
5903 }
5904
5905 DRM_DEBUG_KMS("Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n",
5906 wm->sr.plane, wm->sr.cursor, wm->sr.fbc);
5907 DRM_DEBUG_KMS("Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n",
5908 wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc);
5909 DRM_DEBUG_KMS("Initial SR=%s HPLL=%s FBC=%s\n",
5910 yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en));
5911}
5912
5913void g4x_wm_sanitize(struct drm_i915_private *dev_priv)
5914{
5915 struct intel_plane *plane;
5916 struct intel_crtc *crtc;
5917
5918 mutex_lock(&dev_priv->wm.wm_mutex);
5919
5920 for_each_intel_plane(&dev_priv->drm, plane) {
5921 struct intel_crtc *crtc =
5922 intel_get_crtc_for_pipe(dev_priv, plane->pipe);
5923 struct intel_crtc_state *crtc_state =
5924 to_intel_crtc_state(crtc->base.state);
5925 struct intel_plane_state *plane_state =
5926 to_intel_plane_state(plane->base.state);
5927 struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal;
5928 enum plane_id plane_id = plane->id;
5929 int level;
5930
5931 if (plane_state->base.visible)
5932 continue;
5933
5934 for (level = 0; level < 3; level++) {
5935 struct g4x_pipe_wm *raw =
5936 &crtc_state->wm.g4x.raw[level];
5937
5938 raw->plane[plane_id] = 0;
5939 wm_state->wm.plane[plane_id] = 0;
5940 }
5941
5942 if (plane_id == PLANE_PRIMARY) {
5943 for (level = 0; level < 3; level++) {
5944 struct g4x_pipe_wm *raw =
5945 &crtc_state->wm.g4x.raw[level];
5946 raw->fbc = 0;
5947 }
5948
5949 wm_state->sr.fbc = 0;
5950 wm_state->hpll.fbc = 0;
5951 wm_state->fbc_en = false;
5952 }
5953 }
5954
5955 for_each_intel_crtc(&dev_priv->drm, crtc) {
5956 struct intel_crtc_state *crtc_state =
5957 to_intel_crtc_state(crtc->base.state);
5958
5959 crtc_state->wm.g4x.intermediate =
5960 crtc_state->wm.g4x.optimal;
5961 crtc->wm.active.g4x = crtc_state->wm.g4x.optimal;
5962 }
5963
5964 g4x_program_watermarks(dev_priv);
5965
5966 mutex_unlock(&dev_priv->wm.wm_mutex);
5967}
5968
Matt Ropercd1d3ee2018-12-10 13:54:14 -08005969void vlv_wm_get_hw_state(struct drm_i915_private *dev_priv)
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005970{
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005971 struct vlv_wm_values *wm = &dev_priv->wm.vlv;
Ville Syrjäläf07d43d2017-03-02 19:14:52 +02005972 struct intel_crtc *crtc;
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005973 u32 val;
5974
5975 vlv_read_wm_values(dev_priv, wm);
5976
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005977 wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
5978 wm->level = VLV_WM_LEVEL_PM2;
5979
5980 if (IS_CHERRYVIEW(dev_priv)) {
Chris Wilson337fa6e2019-04-26 09:17:20 +01005981 vlv_punit_get(dev_priv);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005982
Ville Syrjäläc11b8132018-11-29 19:55:03 +02005983 val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005984 if (val & DSP_MAXFIFO_PM5_ENABLE)
5985 wm->level = VLV_WM_LEVEL_PM5;
5986
Ville Syrjälä58590c12015-09-08 21:05:12 +03005987 /*
5988 * If DDR DVFS is disabled in the BIOS, Punit
5989 * will never ack the request. So if that happens
5990 * assume we don't have to enable/disable DDR DVFS
5991 * dynamically. To test that just set the REQ_ACK
5992 * bit to poke the Punit, but don't change the
5993 * HIGH/LOW bits so that we don't actually change
5994 * the current state.
5995 */
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03005996 val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
Ville Syrjälä58590c12015-09-08 21:05:12 +03005997 val |= FORCE_DDR_FREQ_REQ_ACK;
5998 vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val);
5999
6000 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) &
6001 FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) {
6002 DRM_DEBUG_KMS("Punit not acking DDR DVFS request, "
6003 "assuming DDR DVFS is disabled\n");
6004 dev_priv->wm.max_level = VLV_WM_LEVEL_PM5;
6005 } else {
6006 val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
6007 if ((val & FORCE_DDR_HIGH_FREQ) == 0)
6008 wm->level = VLV_WM_LEVEL_DDR_DVFS;
6009 }
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03006010
Chris Wilson337fa6e2019-04-26 09:17:20 +01006011 vlv_punit_put(dev_priv);
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03006012 }
6013
Matt Ropercd1d3ee2018-12-10 13:54:14 -08006014 for_each_intel_crtc(&dev_priv->drm, crtc) {
Ville Syrjäläff32c542017-03-02 19:14:57 +02006015 struct intel_crtc_state *crtc_state =
6016 to_intel_crtc_state(crtc->base.state);
6017 struct vlv_wm_state *active = &crtc->wm.active.vlv;
6018 const struct vlv_fifo_state *fifo_state =
6019 &crtc_state->wm.vlv.fifo_state;
6020 enum pipe pipe = crtc->pipe;
6021 enum plane_id plane_id;
6022 int level;
6023
6024 vlv_get_fifo_size(crtc_state);
6025
6026 active->num_levels = wm->level + 1;
6027 active->cxsr = wm->cxsr;
6028
Ville Syrjäläff32c542017-03-02 19:14:57 +02006029 for (level = 0; level < active->num_levels; level++) {
Ville Syrjälä114d7dc2017-04-21 21:14:21 +03006030 struct g4x_pipe_wm *raw =
Ville Syrjäläff32c542017-03-02 19:14:57 +02006031 &crtc_state->wm.vlv.raw[level];
6032
6033 active->sr[level].plane = wm->sr.plane;
6034 active->sr[level].cursor = wm->sr.cursor;
6035
6036 for_each_plane_id_on_crtc(crtc, plane_id) {
6037 active->wm[level].plane[plane_id] =
6038 wm->pipe[pipe].plane[plane_id];
6039
6040 raw->plane[plane_id] =
6041 vlv_invert_wm_value(active->wm[level].plane[plane_id],
6042 fifo_state->plane[plane_id]);
6043 }
6044 }
6045
6046 for_each_plane_id_on_crtc(crtc, plane_id)
6047 vlv_raw_plane_wm_set(crtc_state, level,
6048 plane_id, USHRT_MAX);
6049 vlv_invalidate_wms(crtc, active, level);
6050
6051 crtc_state->wm.vlv.optimal = *active;
Ville Syrjälä4841da52017-03-02 19:14:59 +02006052 crtc_state->wm.vlv.intermediate = *active;
Ville Syrjäläff32c542017-03-02 19:14:57 +02006053
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03006054 DRM_DEBUG_KMS("Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n",
Ville Syrjälä1b313892016-11-28 19:37:08 +02006055 pipe_name(pipe),
6056 wm->pipe[pipe].plane[PLANE_PRIMARY],
6057 wm->pipe[pipe].plane[PLANE_CURSOR],
6058 wm->pipe[pipe].plane[PLANE_SPRITE0],
6059 wm->pipe[pipe].plane[PLANE_SPRITE1]);
Ville Syrjäläff32c542017-03-02 19:14:57 +02006060 }
Ville Syrjälä6eb1a682015-06-24 22:00:03 +03006061
6062 DRM_DEBUG_KMS("Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n",
6063 wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr);
6064}
6065
Ville Syrjälä602ae832017-03-02 19:15:02 +02006066void vlv_wm_sanitize(struct drm_i915_private *dev_priv)
6067{
6068 struct intel_plane *plane;
6069 struct intel_crtc *crtc;
6070
6071 mutex_lock(&dev_priv->wm.wm_mutex);
6072
6073 for_each_intel_plane(&dev_priv->drm, plane) {
6074 struct intel_crtc *crtc =
6075 intel_get_crtc_for_pipe(dev_priv, plane->pipe);
6076 struct intel_crtc_state *crtc_state =
6077 to_intel_crtc_state(crtc->base.state);
6078 struct intel_plane_state *plane_state =
6079 to_intel_plane_state(plane->base.state);
6080 struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal;
6081 const struct vlv_fifo_state *fifo_state =
6082 &crtc_state->wm.vlv.fifo_state;
6083 enum plane_id plane_id = plane->id;
6084 int level;
6085
6086 if (plane_state->base.visible)
6087 continue;
6088
6089 for (level = 0; level < wm_state->num_levels; level++) {
Ville Syrjälä114d7dc2017-04-21 21:14:21 +03006090 struct g4x_pipe_wm *raw =
Ville Syrjälä602ae832017-03-02 19:15:02 +02006091 &crtc_state->wm.vlv.raw[level];
6092
6093 raw->plane[plane_id] = 0;
6094
6095 wm_state->wm[level].plane[plane_id] =
6096 vlv_invert_wm_value(raw->plane[plane_id],
6097 fifo_state->plane[plane_id]);
6098 }
6099 }
6100
6101 for_each_intel_crtc(&dev_priv->drm, crtc) {
6102 struct intel_crtc_state *crtc_state =
6103 to_intel_crtc_state(crtc->base.state);
6104
6105 crtc_state->wm.vlv.intermediate =
6106 crtc_state->wm.vlv.optimal;
6107 crtc->wm.active.vlv = crtc_state->wm.vlv.optimal;
6108 }
6109
6110 vlv_program_watermarks(dev_priv);
6111
6112 mutex_unlock(&dev_priv->wm.wm_mutex);
6113}
6114
Ville Syrjäläf72b84c2017-11-08 15:35:55 +02006115/*
6116 * FIXME should probably kill this and improve
6117 * the real watermark readout/sanitation instead
6118 */
6119static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv)
6120{
6121 I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN);
6122 I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN);
6123 I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN);
6124
6125 /*
6126 * Don't touch WM1S_LP_EN here.
6127 * Doing so could cause underruns.
6128 */
6129}
6130
Matt Ropercd1d3ee2018-12-10 13:54:14 -08006131void ilk_wm_get_hw_state(struct drm_i915_private *dev_priv)
Ville Syrjälä243e6a42013-10-14 14:55:24 +03006132{
Imre Deak820c1982013-12-17 14:46:36 +02006133 struct ilk_wm_values *hw = &dev_priv->wm.hw;
Matt Ropercd1d3ee2018-12-10 13:54:14 -08006134 struct intel_crtc *crtc;
Ville Syrjälä243e6a42013-10-14 14:55:24 +03006135
Ville Syrjäläf72b84c2017-11-08 15:35:55 +02006136 ilk_init_lp_watermarks(dev_priv);
6137
Matt Ropercd1d3ee2018-12-10 13:54:14 -08006138 for_each_intel_crtc(&dev_priv->drm, crtc)
Ville Syrjälä243e6a42013-10-14 14:55:24 +03006139 ilk_pipe_wm_get_hw_state(crtc);
6140
6141 hw->wm_lp[0] = I915_READ(WM1_LP_ILK);
6142 hw->wm_lp[1] = I915_READ(WM2_LP_ILK);
6143 hw->wm_lp[2] = I915_READ(WM3_LP_ILK);
6144
6145 hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK);
Tvrtko Ursulin175fded2016-11-16 08:55:42 +00006146 if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjäläcfa76982014-03-07 18:32:08 +02006147 hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB);
6148 hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB);
6149 }
Ville Syrjälä243e6a42013-10-14 14:55:24 +03006150
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006151 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Ville Syrjäläac9545f2013-12-05 15:51:28 +02006152 hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ?
6153 INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01006154 else if (IS_IVYBRIDGE(dev_priv))
Ville Syrjäläac9545f2013-12-05 15:51:28 +02006155 hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ?
6156 INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
Ville Syrjälä243e6a42013-10-14 14:55:24 +03006157
6158 hw->enable_fbc_wm =
6159 !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS);
6160}
6161
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03006162/**
6163 * intel_update_watermarks - update FIFO watermark values based on current modes
Chris Wilson31383412018-02-14 14:03:03 +00006164 * @crtc: the #intel_crtc on which to compute the WM
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03006165 *
6166 * Calculate watermark values for the various WM regs based on current mode
6167 * and plane configuration.
6168 *
6169 * There are several cases to deal with here:
6170 * - normal (i.e. non-self-refresh)
6171 * - self-refresh (SR) mode
6172 * - lines are large relative to FIFO size (buffer can hold up to 2)
6173 * - lines are small relative to FIFO size (buffer can hold more than 2
6174 * lines), so need to account for TLB latency
6175 *
6176 * The normal calculation is:
6177 * watermark = dotclock * bytes per pixel * latency
6178 * where latency is platform & configuration dependent (we assume pessimal
6179 * values here).
6180 *
6181 * The SR calculation is:
6182 * watermark = (trunc(latency/line time)+1) * surface width *
6183 * bytes per pixel
6184 * where
6185 * line time = htotal / dotclock
6186 * surface width = hdisplay for normal plane and 64 for cursor
6187 * and latency is assumed to be high, as above.
6188 *
6189 * The final value programmed to the register should always be rounded up,
6190 * and include an extra 2 entries to account for clock crossings.
6191 *
6192 * We don't use the sprite, so we can ignore that. And on Crestline we have
6193 * to set the non-SR watermarks to 8.
6194 */
Ville Syrjälä432081b2016-10-31 22:37:03 +02006195void intel_update_watermarks(struct intel_crtc *crtc)
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03006196{
Ville Syrjälä432081b2016-10-31 22:37:03 +02006197 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03006198
6199 if (dev_priv->display.update_wm)
Ville Syrjälä46ba6142013-09-10 11:40:40 +03006200 dev_priv->display.update_wm(crtc);
Eugeni Dodonovb445e3b2012-04-16 22:20:35 -03006201}
6202
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +05306203void intel_enable_ipc(struct drm_i915_private *dev_priv)
6204{
6205 u32 val;
6206
José Roberto de Souzafd847b82018-09-18 13:47:11 -07006207 if (!HAS_IPC(dev_priv))
6208 return;
6209
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +05306210 val = I915_READ(DISP_ARB_CTL2);
6211
6212 if (dev_priv->ipc_enabled)
6213 val |= DISP_IPC_ENABLE;
6214 else
6215 val &= ~DISP_IPC_ENABLE;
6216
6217 I915_WRITE(DISP_ARB_CTL2, val);
6218}
6219
Ville Syrjäläc91a45f2019-05-03 20:38:07 +03006220static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv)
6221{
6222 /* Display WA #0477 WaDisableIPC: skl */
6223 if (IS_SKYLAKE(dev_priv))
6224 return false;
6225
6226 /* Display WA #1141: SKL:all KBL:all CFL */
6227 if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
6228 return dev_priv->dram_info.symmetric_memory;
6229
6230 return true;
6231}
6232
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +05306233void intel_init_ipc(struct drm_i915_private *dev_priv)
6234{
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +05306235 if (!HAS_IPC(dev_priv))
6236 return;
6237
Ville Syrjäläc91a45f2019-05-03 20:38:07 +03006238 dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv);
José Roberto de Souzac9b818d2018-09-18 13:47:13 -07006239
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +05306240 intel_enable_ipc(dev_priv);
6241}
6242
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006243static void ibx_init_clock_gating(struct drm_i915_private *dev_priv)
Daniel Vetter3107bd42012-10-31 22:52:31 +01006244{
Daniel Vetter3107bd42012-10-31 22:52:31 +01006245 /*
6246 * On Ibex Peak and Cougar Point, we need to disable clock
6247 * gating for the panel power sequencer or it will fail to
6248 * start up when no ports are active.
6249 */
6250 I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
6251}
6252
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006253static void g4x_disable_trickle_feed(struct drm_i915_private *dev_priv)
Ville Syrjälä0e088b82013-06-07 10:47:04 +03006254{
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +03006255 enum pipe pipe;
Ville Syrjälä0e088b82013-06-07 10:47:04 +03006256
Damien Lespiau055e3932014-08-18 13:49:10 +01006257 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä0e088b82013-06-07 10:47:04 +03006258 I915_WRITE(DSPCNTR(pipe),
6259 I915_READ(DSPCNTR(pipe)) |
6260 DISPPLANE_TRICKLE_FEED_DISABLE);
Ville Syrjäläb12ce1d2015-05-26 20:27:23 +03006261
6262 I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe)));
6263 POSTING_READ(DSPSURF(pipe));
Ville Syrjälä0e088b82013-06-07 10:47:04 +03006264 }
6265}
6266
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006267static void ilk_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006268{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02006269 u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006270
Damien Lespiauf1e8fa52013-06-07 17:41:09 +01006271 /*
6272 * Required for FBC
6273 * WaFbcDisableDpfcClockGating:ilk
6274 */
Damien Lespiau4d47e4f2012-10-19 17:55:42 +01006275 dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE |
6276 ILK_DPFCUNIT_CLOCK_GATE_DISABLE |
6277 ILK_DPFDUNIT_CLOCK_GATE_ENABLE;
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006278
6279 I915_WRITE(PCH_3DCGDIS0,
6280 MARIUNIT_CLOCK_GATE_DISABLE |
6281 SVSMUNIT_CLOCK_GATE_DISABLE);
6282 I915_WRITE(PCH_3DCGDIS1,
6283 VFMUNIT_CLOCK_GATE_DISABLE);
6284
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006285 /*
6286 * According to the spec the following bits should be set in
6287 * order to enable memory self-refresh
6288 * The bit 22/21 of 0x42004
6289 * The bit 5 of 0x42020
6290 * The bit 15 of 0x45000
6291 */
6292 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6293 (I915_READ(ILK_DISPLAY_CHICKEN2) |
6294 ILK_DPARB_GATE | ILK_VSDPFD_FULL));
Damien Lespiau4d47e4f2012-10-19 17:55:42 +01006295 dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE;
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006296 I915_WRITE(DISP_ARB_CTL,
6297 (I915_READ(DISP_ARB_CTL) |
6298 DISP_FBC_WM_DIS));
Ville Syrjälä017636c2013-12-05 15:51:37 +02006299
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006300 /*
6301 * Based on the document from hardware guys the following bits
6302 * should be set unconditionally in order to enable FBC.
6303 * The bit 22 of 0x42000
6304 * The bit 22 of 0x42004
6305 * The bit 7,8,9 of 0x42020.
6306 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006307 if (IS_IRONLAKE_M(dev_priv)) {
Damien Lespiau4bb35332013-06-14 15:23:24 +01006308 /* WaFbcAsynchFlipDisableFbcQueue:ilk */
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006309 I915_WRITE(ILK_DISPLAY_CHICKEN1,
6310 I915_READ(ILK_DISPLAY_CHICKEN1) |
6311 ILK_FBCQ_DIS);
6312 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6313 I915_READ(ILK_DISPLAY_CHICKEN2) |
6314 ILK_DPARB_GATE);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006315 }
6316
Damien Lespiau4d47e4f2012-10-19 17:55:42 +01006317 I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate);
6318
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006319 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6320 I915_READ(ILK_DISPLAY_CHICKEN2) |
6321 ILK_ELPIN_409_SELECT);
6322 I915_WRITE(_3D_CHICKEN2,
6323 _3D_CHICKEN2_WM_READ_PIPELINED << 16 |
6324 _3D_CHICKEN2_WM_READ_PIPELINED);
Daniel Vetter4358a372012-10-18 11:49:51 +02006325
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006326 /* WaDisableRenderCachePipelinedFlush:ilk */
Daniel Vetter4358a372012-10-18 11:49:51 +02006327 I915_WRITE(CACHE_MODE_0,
6328 _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE));
Daniel Vetter3107bd42012-10-31 22:52:31 +01006329
Akash Goel4e046322014-04-04 17:14:38 +05306330 /* WaDisable_RenderCache_OperationalFlush:ilk */
6331 I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
6332
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006333 g4x_disable_trickle_feed(dev_priv);
Ville Syrjäläbdad2b22013-06-07 10:47:03 +03006334
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006335 ibx_init_clock_gating(dev_priv);
Daniel Vetter3107bd42012-10-31 22:52:31 +01006336}
6337
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006338static void cpt_init_clock_gating(struct drm_i915_private *dev_priv)
Daniel Vetter3107bd42012-10-31 22:52:31 +01006339{
Ville Syrjäläd048a262019-08-21 20:30:31 +03006340 enum pipe pipe;
Jani Nikula5ce9a6492019-01-18 14:01:20 +02006341 u32 val;
Daniel Vetter3107bd42012-10-31 22:52:31 +01006342
6343 /*
6344 * On Ibex Peak and Cougar Point, we need to disable clock
6345 * gating for the panel power sequencer or it will fail to
6346 * start up when no ports are active.
6347 */
Jesse Barnescd664072013-10-02 10:34:19 -07006348 I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE |
6349 PCH_DPLUNIT_CLOCK_GATE_DISABLE |
6350 PCH_CPUNIT_CLOCK_GATE_DISABLE);
Daniel Vetter3107bd42012-10-31 22:52:31 +01006351 I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) |
6352 DPLS_EDP_PPS_FIX_DIS);
Takashi Iwai335c07b2012-12-11 11:46:29 +01006353 /* The below fixes the weird display corruption, a few pixels shifted
6354 * downward, on (only) LVDS of some HP laptops with IVY.
6355 */
Damien Lespiau055e3932014-08-18 13:49:10 +01006356 for_each_pipe(dev_priv, pipe) {
Paulo Zanonidc4bd2d2013-04-08 15:48:08 -03006357 val = I915_READ(TRANS_CHICKEN2(pipe));
6358 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
6359 val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03006360 if (dev_priv->vbt.fdi_rx_polarity_inverted)
Paulo Zanoni3f704fa2013-04-08 15:48:07 -03006361 val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
Paulo Zanonidc4bd2d2013-04-08 15:48:08 -03006362 val &= ~TRANS_CHICKEN2_FRAME_START_DELAY_MASK;
6363 val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER;
6364 val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH;
Paulo Zanoni3f704fa2013-04-08 15:48:07 -03006365 I915_WRITE(TRANS_CHICKEN2(pipe), val);
6366 }
Daniel Vetter3107bd42012-10-31 22:52:31 +01006367 /* WADP0ClockGatingDisable */
Damien Lespiau055e3932014-08-18 13:49:10 +01006368 for_each_pipe(dev_priv, pipe) {
Daniel Vetter3107bd42012-10-31 22:52:31 +01006369 I915_WRITE(TRANS_CHICKEN1(pipe),
6370 TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
6371 }
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006372}
6373
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006374static void gen6_check_mch_setup(struct drm_i915_private *dev_priv)
Daniel Vetter1d7aaa02013-02-09 21:03:42 +01006375{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02006376 u32 tmp;
Daniel Vetter1d7aaa02013-02-09 21:03:42 +01006377
6378 tmp = I915_READ(MCH_SSKPD);
Daniel Vetterdf662a22014-08-04 11:17:25 +02006379 if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL)
6380 DRM_DEBUG_KMS("Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n",
6381 tmp);
Daniel Vetter1d7aaa02013-02-09 21:03:42 +01006382}
6383
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006384static void gen6_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006385{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02006386 u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006387
Damien Lespiau231e54f2012-10-19 17:55:41 +01006388 I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006389
6390 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6391 I915_READ(ILK_DISPLAY_CHICKEN2) |
6392 ILK_ELPIN_409_SELECT);
6393
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006394 /* WaDisableHiZPlanesWhenMSAAEnabled:snb */
Daniel Vetter42839082012-12-14 23:38:28 +01006395 I915_WRITE(_3D_CHICKEN,
6396 _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB));
6397
Akash Goel4e046322014-04-04 17:14:38 +05306398 /* WaDisable_RenderCache_OperationalFlush:snb */
6399 I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
6400
Ville Syrjälä8d85d272014-02-04 21:59:15 +02006401 /*
6402 * BSpec recoomends 8x4 when MSAA is used,
6403 * however in practice 16x4 seems fastest.
Ville Syrjäläc5c98a52014-02-05 12:43:47 +02006404 *
6405 * Note that PS/WM thread counts depend on the WIZ hashing
6406 * disable bit, which we don't touch here, but it's good
6407 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
Ville Syrjälä8d85d272014-02-04 21:59:15 +02006408 */
6409 I915_WRITE(GEN6_GT_MODE,
Damien Lespiau98533252014-12-08 17:33:51 +00006410 _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
Ville Syrjälä8d85d272014-02-04 21:59:15 +02006411
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006412 I915_WRITE(CACHE_MODE_0,
Daniel Vetter50743292012-04-26 22:02:54 +02006413 _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB));
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006414
6415 I915_WRITE(GEN6_UCGCTL1,
6416 I915_READ(GEN6_UCGCTL1) |
6417 GEN6_BLBUNIT_CLOCK_GATE_DISABLE |
6418 GEN6_CSUNIT_CLOCK_GATE_DISABLE);
6419
6420 /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
6421 * gating disable must be set. Failure to set it results in
6422 * flickering pixels due to Z write ordering failures after
6423 * some amount of runtime in the Mesa "fire" demo, and Unigine
6424 * Sanctuary and Tropics, and apparently anything else with
6425 * alpha test or pixel discard.
6426 *
6427 * According to the spec, bit 11 (RCCUNIT) must also be set,
6428 * but we didn't debug actual testcases to find it out.
Jesse Barnes0f846f82012-06-14 11:04:47 -07006429 *
Ville Syrjäläef593182014-01-22 21:32:47 +02006430 * WaDisableRCCUnitClockGating:snb
6431 * WaDisableRCPBUnitClockGating:snb
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006432 */
6433 I915_WRITE(GEN6_UCGCTL2,
6434 GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
6435 GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
6436
Ville Syrjälä5eb146d2014-02-04 21:59:16 +02006437 /* WaStripsFansDisableFastClipPerformanceFix:snb */
Ville Syrjälä743b57d2014-02-04 21:59:17 +02006438 I915_WRITE(_3D_CHICKEN3,
6439 _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL));
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006440
6441 /*
Ville Syrjäläe927ecd2014-02-04 21:59:18 +02006442 * Bspec says:
6443 * "This bit must be set if 3DSTATE_CLIP clip mode is set to normal and
6444 * 3DSTATE_SF number of SF output attributes is more than 16."
6445 */
6446 I915_WRITE(_3D_CHICKEN3,
6447 _MASKED_BIT_ENABLE(_3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH));
6448
6449 /*
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006450 * According to the spec the following bits should be
6451 * set in order to enable memory self-refresh and fbc:
6452 * The bit21 and bit22 of 0x42000
6453 * The bit21 and bit22 of 0x42004
6454 * The bit5 and bit7 of 0x42020
6455 * The bit14 of 0x70180
6456 * The bit14 of 0x71180
Damien Lespiau4bb35332013-06-14 15:23:24 +01006457 *
6458 * WaFbcAsynchFlipDisableFbcQueue:snb
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006459 */
6460 I915_WRITE(ILK_DISPLAY_CHICKEN1,
6461 I915_READ(ILK_DISPLAY_CHICKEN1) |
6462 ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
6463 I915_WRITE(ILK_DISPLAY_CHICKEN2,
6464 I915_READ(ILK_DISPLAY_CHICKEN2) |
6465 ILK_DPARB_GATE | ILK_VSDPFD_FULL);
Damien Lespiau231e54f2012-10-19 17:55:41 +01006466 I915_WRITE(ILK_DSPCLK_GATE_D,
6467 I915_READ(ILK_DSPCLK_GATE_D) |
6468 ILK_DPARBUNIT_CLOCK_GATE_ENABLE |
6469 ILK_DPFDUNIT_CLOCK_GATE_ENABLE);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006470
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006471 g4x_disable_trickle_feed(dev_priv);
Ben Widawskyf8f2ac92012-10-03 19:34:24 -07006472
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006473 cpt_init_clock_gating(dev_priv);
Daniel Vetter1d7aaa02013-02-09 21:03:42 +01006474
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006475 gen6_check_mch_setup(dev_priv);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006476}
6477
6478static void gen7_setup_fixed_func_scheduler(struct drm_i915_private *dev_priv)
6479{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02006480 u32 reg = I915_READ(GEN7_FF_THREAD_MODE);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006481
Ville Syrjälä3aad9052014-01-22 21:32:59 +02006482 /*
Ville Syrjälä46680e02014-01-22 21:33:01 +02006483 * WaVSThreadDispatchOverride:ivb,vlv
Ville Syrjälä3aad9052014-01-22 21:32:59 +02006484 *
6485 * This actually overrides the dispatch
6486 * mode for all thread types.
6487 */
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006488 reg &= ~GEN7_FF_SCHED_MASK;
6489 reg |= GEN7_FF_TS_SCHED_HW;
6490 reg |= GEN7_FF_VS_SCHED_HW;
6491 reg |= GEN7_FF_DS_SCHED_HW;
6492
6493 I915_WRITE(GEN7_FF_THREAD_MODE, reg);
6494}
6495
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006496static void lpt_init_clock_gating(struct drm_i915_private *dev_priv)
Paulo Zanoni17a303e2012-11-20 15:12:07 -02006497{
Paulo Zanoni17a303e2012-11-20 15:12:07 -02006498 /*
6499 * TODO: this bit should only be enabled when really needed, then
6500 * disabled when not needed anymore in order to save power.
6501 */
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006502 if (HAS_PCH_LPT_LP(dev_priv))
Paulo Zanoni17a303e2012-11-20 15:12:07 -02006503 I915_WRITE(SOUTH_DSPCLK_GATE_D,
6504 I915_READ(SOUTH_DSPCLK_GATE_D) |
6505 PCH_LP_PARTITION_LEVEL_DISABLE);
Paulo Zanoni0a790cd2013-04-17 18:15:49 -03006506
6507 /* WADPOClockGatingDisable:hsw */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03006508 I915_WRITE(TRANS_CHICKEN1(PIPE_A),
6509 I915_READ(TRANS_CHICKEN1(PIPE_A)) |
Paulo Zanoni0a790cd2013-04-17 18:15:49 -03006510 TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
Paulo Zanoni17a303e2012-11-20 15:12:07 -02006511}
6512
Ville Syrjälä712bf362016-10-31 22:37:23 +02006513static void lpt_suspend_hw(struct drm_i915_private *dev_priv)
Imre Deak7d708ee2013-04-17 14:04:50 +03006514{
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01006515 if (HAS_PCH_LPT_LP(dev_priv)) {
Jani Nikula5ce9a6492019-01-18 14:01:20 +02006516 u32 val = I915_READ(SOUTH_DSPCLK_GATE_D);
Imre Deak7d708ee2013-04-17 14:04:50 +03006517
6518 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
6519 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
6520 }
6521}
6522
Imre Deak450174f2016-05-03 15:54:21 +03006523static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv,
6524 int general_prio_credits,
6525 int high_prio_credits)
6526{
6527 u32 misccpctl;
Oscar Mateo930a7842017-10-17 13:25:45 -07006528 u32 val;
Imre Deak450174f2016-05-03 15:54:21 +03006529
6530 /* WaTempDisableDOPClkGating:bdw */
6531 misccpctl = I915_READ(GEN7_MISCCPCTL);
6532 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
6533
Oscar Mateo930a7842017-10-17 13:25:45 -07006534 val = I915_READ(GEN8_L3SQCREG1);
6535 val &= ~L3_PRIO_CREDITS_MASK;
6536 val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits);
6537 val |= L3_HIGH_PRIO_CREDITS(high_prio_credits);
6538 I915_WRITE(GEN8_L3SQCREG1, val);
Imre Deak450174f2016-05-03 15:54:21 +03006539
6540 /*
6541 * Wait at least 100 clocks before re-enabling clock gating.
6542 * See the definition of L3SQCREG1 in BSpec.
6543 */
6544 POSTING_READ(GEN8_L3SQCREG1);
6545 udelay(1);
6546 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
6547}
6548
Oscar Mateod65dc3e2018-05-08 14:29:24 -07006549static void icl_init_clock_gating(struct drm_i915_private *dev_priv)
6550{
6551 /* This is not an Wa. Enable to reduce Sampler power */
6552 I915_WRITE(GEN10_DFR_RATIO_EN_AND_CHICKEN,
6553 I915_READ(GEN10_DFR_RATIO_EN_AND_CHICKEN) & ~DFR_DISABLE);
Radhakrishna Sripada622b3f62018-10-30 01:45:01 -07006554
6555 /* WaEnable32PlaneMode:icl */
6556 I915_WRITE(GEN9_CSFE_CHICKEN1_RCS,
6557 _MASKED_BIT_ENABLE(GEN11_ENABLE_32_PLANE_MODE));
Oscar Mateod65dc3e2018-05-08 14:29:24 -07006558}
6559
Michel Thierry5d869232019-08-23 01:20:34 -07006560static void tgl_init_clock_gating(struct drm_i915_private *dev_priv)
6561{
6562 u32 vd_pg_enable = 0;
6563 unsigned int i;
6564
6565 /* This is not a WA. Enable VD HCP & MFX_ENC powergate */
6566 for (i = 0; i < I915_MAX_VCS; i++) {
6567 if (HAS_ENGINE(dev_priv, _VCS(i)))
6568 vd_pg_enable |= VDN_HCP_POWERGATE_ENABLE(i) |
6569 VDN_MFX_POWERGATE_ENABLE(i);
6570 }
6571
6572 I915_WRITE(POWERGATE_ENABLE,
6573 I915_READ(POWERGATE_ENABLE) | vd_pg_enable);
6574}
6575
Rodrigo Vivi0a46ddd2017-08-30 21:52:23 -07006576static void cnp_init_clock_gating(struct drm_i915_private *dev_priv)
6577{
6578 if (!HAS_PCH_CNP(dev_priv))
6579 return;
6580
Rodrigo Vivi470e7c62018-03-05 17:28:12 -08006581 /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */
Rodrigo Vivi4cc6feb2017-09-08 16:45:33 -07006582 I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) |
6583 CNP_PWM_CGE_GATING_DISABLE);
Rodrigo Vivi0a46ddd2017-08-30 21:52:23 -07006584}
6585
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006586static void cnl_init_clock_gating(struct drm_i915_private *dev_priv)
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07006587{
Rodrigo Vivi8f067832017-09-05 12:30:13 -07006588 u32 val;
Rodrigo Vivi0a46ddd2017-08-30 21:52:23 -07006589 cnp_init_clock_gating(dev_priv);
6590
Rodrigo Vivi1a25db62017-08-15 16:16:51 -07006591 /* This is not an Wa. Enable for better image quality */
6592 I915_WRITE(_3D_CHICKEN3,
6593 _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE));
6594
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07006595 /* WaEnableChickenDCPR:cnl */
6596 I915_WRITE(GEN8_CHICKEN_DCPR_1,
6597 I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM);
6598
6599 /* WaFbcWakeMemOn:cnl */
6600 I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
6601 DISP_FBC_MEMORY_WAKE);
6602
Chris Wilson34991bd2017-11-11 10:03:36 +00006603 val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE);
6604 /* ReadHitWriteOnlyDisable:cnl */
6605 val |= RCCUNIT_CLKGATE_DIS;
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07006606 /* WaSarbUnitClockGatingDisable:cnl (pre-prod) */
6607 if (IS_CNL_REVID(dev_priv, CNL_REVID_A0, CNL_REVID_B0))
Chris Wilson34991bd2017-11-11 10:03:36 +00006608 val |= SARBUNIT_CLKGATE_DIS;
6609 I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val);
Rafael Antognolli01ab0f92017-12-15 16:11:16 -08006610
Rodrigo Vivia4713c52018-03-07 14:09:12 -08006611 /* Wa_2201832410:cnl */
6612 val = I915_READ(SUBSLICE_UNIT_LEVEL_CLKGATE);
6613 val |= GWUNIT_CLKGATE_DIS;
6614 I915_WRITE(SUBSLICE_UNIT_LEVEL_CLKGATE, val);
6615
Rafael Antognolli01ab0f92017-12-15 16:11:16 -08006616 /* WaDisableVFclkgate:cnl */
Rodrigo Vivi14941b62018-03-05 17:20:00 -08006617 /* WaVFUnitClockGatingDisable:cnl */
Rafael Antognolli01ab0f92017-12-15 16:11:16 -08006618 val = I915_READ(UNSLICE_UNIT_LEVEL_CLKGATE);
6619 val |= VFUNIT_CLKGATE_DIS;
6620 I915_WRITE(UNSLICE_UNIT_LEVEL_CLKGATE, val);
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07006621}
6622
Rodrigo Vivi0a46ddd2017-08-30 21:52:23 -07006623static void cfl_init_clock_gating(struct drm_i915_private *dev_priv)
6624{
6625 cnp_init_clock_gating(dev_priv);
6626 gen9_init_clock_gating(dev_priv);
6627
6628 /* WaFbcNukeOnHostModify:cfl */
6629 I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
6630 ILK_DPFC_NUKE_ON_ANY_MODIFICATION);
6631}
6632
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006633static void kbl_init_clock_gating(struct drm_i915_private *dev_priv)
Mika Kuoppala9498dba2016-06-07 17:19:01 +03006634{
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006635 gen9_init_clock_gating(dev_priv);
Mika Kuoppala9498dba2016-06-07 17:19:01 +03006636
6637 /* WaDisableSDEUnitClockGating:kbl */
6638 if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0))
6639 I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
6640 GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
Mika Kuoppala8aeb7f62016-06-07 17:19:05 +03006641
6642 /* WaDisableGamClockGating:kbl */
6643 if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0))
6644 I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) |
6645 GEN6_GAMUNIT_CLOCK_GATE_DISABLE);
Mika Kuoppala031cd8c2016-06-07 17:19:18 +03006646
Rodrigo Vivi0a46ddd2017-08-30 21:52:23 -07006647 /* WaFbcNukeOnHostModify:kbl */
Mika Kuoppala031cd8c2016-06-07 17:19:18 +03006648 I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
6649 ILK_DPFC_NUKE_ON_ANY_MODIFICATION);
Mika Kuoppala9498dba2016-06-07 17:19:01 +03006650}
6651
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006652static void skl_init_clock_gating(struct drm_i915_private *dev_priv)
Daniel Vetterdc00b6a2016-05-19 09:14:20 +02006653{
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006654 gen9_init_clock_gating(dev_priv);
Mika Kuoppala44fff992016-06-07 17:19:09 +03006655
6656 /* WAC6entrylatency:skl */
6657 I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) |
6658 FBC_LLC_FULLY_OPEN);
Mika Kuoppala031cd8c2016-06-07 17:19:18 +03006659
6660 /* WaFbcNukeOnHostModify:skl */
6661 I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
6662 ILK_DPFC_NUKE_ON_ANY_MODIFICATION);
Daniel Vetterdc00b6a2016-05-19 09:14:20 +02006663}
6664
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006665static void bdw_init_clock_gating(struct drm_i915_private *dev_priv)
Ben Widawsky1020a5c2013-11-02 21:07:06 -07006666{
Damien Lespiau07d27e22014-03-03 17:31:46 +00006667 enum pipe pipe;
Ben Widawsky1020a5c2013-11-02 21:07:06 -07006668
Ben Widawskyab57fff2013-12-12 15:28:04 -08006669 /* WaSwitchSolVfFArbitrationPriority:bdw */
Ben Widawsky50ed5fb2013-11-02 21:07:40 -07006670 I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
Ben Widawskyfe4ab3c2013-11-02 21:07:54 -07006671
Ben Widawskyab57fff2013-12-12 15:28:04 -08006672 /* WaPsrDPAMaskVBlankInSRD:bdw */
Ben Widawskyfe4ab3c2013-11-02 21:07:54 -07006673 I915_WRITE(CHICKEN_PAR1_1,
6674 I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD);
6675
Ben Widawskyab57fff2013-12-12 15:28:04 -08006676 /* WaPsrDPRSUnmaskVBlankInSRD:bdw */
Damien Lespiau055e3932014-08-18 13:49:10 +01006677 for_each_pipe(dev_priv, pipe) {
Damien Lespiau07d27e22014-03-03 17:31:46 +00006678 I915_WRITE(CHICKEN_PIPESL_1(pipe),
Ville Syrjäläc7c65622014-03-05 13:05:45 +02006679 I915_READ(CHICKEN_PIPESL_1(pipe)) |
Ville Syrjälä8f670bb2014-03-05 13:05:47 +02006680 BDW_DPRS_MASK_VBLANK_SRD);
Ben Widawskyfe4ab3c2013-11-02 21:07:54 -07006681 }
Ben Widawsky63801f22013-12-12 17:26:03 -08006682
Ben Widawskyab57fff2013-12-12 15:28:04 -08006683 /* WaVSRefCountFullforceMissDisable:bdw */
6684 /* WaDSRefCountFullforceMissDisable:bdw */
6685 I915_WRITE(GEN7_FF_THREAD_MODE,
6686 I915_READ(GEN7_FF_THREAD_MODE) &
6687 ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
Ville Syrjälä36075a42014-02-04 21:59:21 +02006688
Ville Syrjälä295e8bb2014-02-27 21:59:01 +02006689 I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL,
6690 _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
Ville Syrjälä4f1ca9e2014-02-27 21:59:02 +02006691
6692 /* WaDisableSDEUnitClockGating:bdw */
6693 I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
6694 GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
Damien Lespiau5d708682014-03-26 18:41:51 +00006695
Imre Deak450174f2016-05-03 15:54:21 +03006696 /* WaProgramL3SqcReg1Default:bdw */
6697 gen8_set_l3sqc_credits(dev_priv, 30, 2);
Ville Syrjälä4d487cf2015-05-19 20:32:56 +03006698
Mika Kuoppala17e0adf2016-06-07 17:19:02 +03006699 /* WaKVMNotificationOnConfigChange:bdw */
6700 I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1)
6701 | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT);
6702
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006703 lpt_init_clock_gating(dev_priv);
Robert Bragg9cc19732017-02-12 13:32:52 +00006704
6705 /* WaDisableDopClockGating:bdw
6706 *
6707 * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP
6708 * clock gating.
6709 */
6710 I915_WRITE(GEN6_UCGCTL1,
6711 I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE);
Ben Widawsky1020a5c2013-11-02 21:07:06 -07006712}
6713
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006714static void hsw_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonovcad2a2d2012-07-02 11:51:09 -03006715{
Francisco Jerezf3fc4882013-10-02 15:53:16 -07006716 /* L3 caching of data atomics doesn't work -- disable it. */
6717 I915_WRITE(HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE);
6718 I915_WRITE(HSW_ROW_CHICKEN3,
6719 _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE));
6720
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006721 /* This is required by WaCatErrorRejectionIssue:hsw */
Eugeni Dodonovcad2a2d2012-07-02 11:51:09 -03006722 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
6723 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
6724 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
6725
Ville Syrjäläe36ea7f2014-01-22 21:33:00 +02006726 /* WaVSRefCountFullforceMissDisable:hsw */
6727 I915_WRITE(GEN7_FF_THREAD_MODE,
6728 I915_READ(GEN7_FF_THREAD_MODE) & ~GEN7_FF_VS_REF_CNT_FFME);
Eugeni Dodonovcad2a2d2012-07-02 11:51:09 -03006729
Akash Goel4e046322014-04-04 17:14:38 +05306730 /* WaDisable_RenderCache_OperationalFlush:hsw */
6731 I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
6732
Chia-I Wufe27c602014-01-28 13:29:33 +08006733 /* enable HiZ Raw Stall Optimization */
6734 I915_WRITE(CACHE_MODE_0_GEN7,
6735 _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE));
6736
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006737 /* WaDisable4x2SubspanOptimization:hsw */
Eugeni Dodonovcad2a2d2012-07-02 11:51:09 -03006738 I915_WRITE(CACHE_MODE_1,
6739 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
Eugeni Dodonov1544d9d2012-07-02 11:51:10 -03006740
Ville Syrjäläa12c4962014-02-04 21:59:20 +02006741 /*
6742 * BSpec recommends 8x4 when MSAA is used,
6743 * however in practice 16x4 seems fastest.
Ville Syrjäläc5c98a52014-02-05 12:43:47 +02006744 *
6745 * Note that PS/WM thread counts depend on the WIZ hashing
6746 * disable bit, which we don't touch here, but it's good
6747 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
Ville Syrjäläa12c4962014-02-04 21:59:20 +02006748 */
6749 I915_WRITE(GEN7_GT_MODE,
Damien Lespiau98533252014-12-08 17:33:51 +00006750 _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
Ville Syrjäläa12c4962014-02-04 21:59:20 +02006751
Kenneth Graunke94411592014-12-31 16:23:00 -08006752 /* WaSampleCChickenBitEnable:hsw */
6753 I915_WRITE(HALF_SLICE_CHICKEN3,
6754 _MASKED_BIT_ENABLE(HSW_SAMPLE_C_PERFORMANCE));
6755
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006756 /* WaSwitchSolVfFArbitrationPriority:hsw */
Ben Widawskye3dff582013-03-20 14:49:14 -07006757 I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
6758
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006759 lpt_init_clock_gating(dev_priv);
Eugeni Dodonovcad2a2d2012-07-02 11:51:09 -03006760}
6761
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006762static void ivb_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006763{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02006764 u32 snpcr;
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006765
Damien Lespiau231e54f2012-10-19 17:55:41 +01006766 I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006767
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006768 /* WaDisableEarlyCull:ivb */
Jesse Barnes87f80202012-10-02 17:43:41 -05006769 I915_WRITE(_3D_CHICKEN3,
6770 _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL));
6771
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006772 /* WaDisableBackToBackFlipFix:ivb */
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006773 I915_WRITE(IVB_CHICKEN3,
6774 CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
6775 CHICKEN3_DGMG_DONE_FIX_DISABLE);
6776
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006777 /* WaDisablePSDDualDispatchEnable:ivb */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006778 if (IS_IVB_GT1(dev_priv))
Jesse Barnes12f33822012-10-25 12:15:45 -07006779 I915_WRITE(GEN7_HALF_SLICE_CHICKEN1,
6780 _MASKED_BIT_ENABLE(GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE));
Jesse Barnes12f33822012-10-25 12:15:45 -07006781
Akash Goel4e046322014-04-04 17:14:38 +05306782 /* WaDisable_RenderCache_OperationalFlush:ivb */
6783 I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
6784
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006785 /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006786 I915_WRITE(GEN7_COMMON_SLICE_CHICKEN1,
6787 GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC);
6788
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006789 /* WaApplyL3ControlAndL3ChickenMode:ivb */
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006790 I915_WRITE(GEN7_L3CNTLREG1,
6791 GEN7_WA_FOR_GEN7_L3_CONTROL);
6792 I915_WRITE(GEN7_L3_CHICKEN_MODE_REGISTER,
Jesse Barnes8ab43972012-10-25 12:15:42 -07006793 GEN7_WA_L3_CHICKEN_MODE);
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006794 if (IS_IVB_GT1(dev_priv))
Jesse Barnes8ab43972012-10-25 12:15:42 -07006795 I915_WRITE(GEN7_ROW_CHICKEN2,
6796 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
Ville Syrjälä412236c2014-01-22 21:32:44 +02006797 else {
6798 /* must write both registers */
6799 I915_WRITE(GEN7_ROW_CHICKEN2,
6800 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
Jesse Barnes8ab43972012-10-25 12:15:42 -07006801 I915_WRITE(GEN7_ROW_CHICKEN2_GT2,
6802 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
Ville Syrjälä412236c2014-01-22 21:32:44 +02006803 }
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006804
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006805 /* WaForceL3Serialization:ivb */
Jesse Barnes61939d92012-10-02 17:43:38 -05006806 I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) &
6807 ~L3SQ_URB_READ_CAM_MATCH_DISABLE);
6808
Ville Syrjälä1b80a19a2014-01-22 21:32:53 +02006809 /*
Jesse Barnes0f846f82012-06-14 11:04:47 -07006810 * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006811 * This implements the WaDisableRCZUnitClockGating:ivb workaround.
Jesse Barnes0f846f82012-06-14 11:04:47 -07006812 */
6813 I915_WRITE(GEN6_UCGCTL2,
Ville Syrjälä28acf3b2014-01-22 21:32:48 +02006814 GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
Jesse Barnes0f846f82012-06-14 11:04:47 -07006815
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006816 /* This is required by WaCatErrorRejectionIssue:ivb */
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006817 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
6818 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
6819 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
6820
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006821 g4x_disable_trickle_feed(dev_priv);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006822
6823 gen7_setup_fixed_func_scheduler(dev_priv);
Daniel Vetter97e19302012-04-24 16:00:21 +02006824
Chris Wilson22721342014-03-04 09:41:43 +00006825 if (0) { /* causes HiZ corruption on ivb:gt1 */
6826 /* enable HiZ Raw Stall Optimization */
6827 I915_WRITE(CACHE_MODE_0_GEN7,
6828 _MASKED_BIT_DISABLE(HIZ_RAW_STALL_OPT_DISABLE));
6829 }
Chia-I Wu116f2b62014-01-28 13:29:34 +08006830
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006831 /* WaDisable4x2SubspanOptimization:ivb */
Daniel Vetter97e19302012-04-24 16:00:21 +02006832 I915_WRITE(CACHE_MODE_1,
6833 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
Ben Widawsky20848222012-05-04 18:58:59 -07006834
Ville Syrjäläa607c1a2014-02-04 21:59:19 +02006835 /*
6836 * BSpec recommends 8x4 when MSAA is used,
6837 * however in practice 16x4 seems fastest.
Ville Syrjäläc5c98a52014-02-05 12:43:47 +02006838 *
6839 * Note that PS/WM thread counts depend on the WIZ hashing
6840 * disable bit, which we don't touch here, but it's good
6841 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
Ville Syrjäläa607c1a2014-02-04 21:59:19 +02006842 */
6843 I915_WRITE(GEN7_GT_MODE,
Damien Lespiau98533252014-12-08 17:33:51 +00006844 _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
Ville Syrjäläa607c1a2014-02-04 21:59:19 +02006845
Ben Widawsky20848222012-05-04 18:58:59 -07006846 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
6847 snpcr &= ~GEN6_MBC_SNPCR_MASK;
6848 snpcr |= GEN6_MBC_SNPCR_MED;
6849 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
Daniel Vetter3107bd42012-10-31 22:52:31 +01006850
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006851 if (!HAS_PCH_NOP(dev_priv))
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006852 cpt_init_clock_gating(dev_priv);
Daniel Vetter1d7aaa02013-02-09 21:03:42 +01006853
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006854 gen6_check_mch_setup(dev_priv);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006855}
6856
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006857static void vlv_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006858{
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006859 /* WaDisableEarlyCull:vlv */
Jesse Barnes87f80202012-10-02 17:43:41 -05006860 I915_WRITE(_3D_CHICKEN3,
6861 _MASKED_BIT_ENABLE(_3D_CHICKEN_SF_DISABLE_OBJEND_CULL));
6862
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006863 /* WaDisableBackToBackFlipFix:vlv */
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006864 I915_WRITE(IVB_CHICKEN3,
6865 CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
6866 CHICKEN3_DGMG_DONE_FIX_DISABLE);
6867
Ville Syrjäläfad7d362014-01-22 21:32:39 +02006868 /* WaPsdDispatchEnable:vlv */
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006869 /* WaDisablePSDDualDispatchEnable:vlv */
Jesse Barnes12f33822012-10-25 12:15:45 -07006870 I915_WRITE(GEN7_HALF_SLICE_CHICKEN1,
Jesse Barnesd3bc0302013-03-08 10:45:51 -08006871 _MASKED_BIT_ENABLE(GEN7_MAX_PS_THREAD_DEP |
6872 GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE));
Jesse Barnes12f33822012-10-25 12:15:45 -07006873
Akash Goel4e046322014-04-04 17:14:38 +05306874 /* WaDisable_RenderCache_OperationalFlush:vlv */
6875 I915_WRITE(CACHE_MODE_0_GEN7, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
6876
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006877 /* WaForceL3Serialization:vlv */
Jesse Barnes61939d92012-10-02 17:43:38 -05006878 I915_WRITE(GEN7_L3SQCREG4, I915_READ(GEN7_L3SQCREG4) &
6879 ~L3SQ_URB_READ_CAM_MATCH_DISABLE);
6880
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006881 /* WaDisableDopClockGating:vlv */
Jesse Barnes8ab43972012-10-25 12:15:42 -07006882 I915_WRITE(GEN7_ROW_CHICKEN2,
6883 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
6884
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006885 /* This is required by WaCatErrorRejectionIssue:vlv */
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006886 I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
6887 I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
6888 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
6889
Ville Syrjälä46680e02014-01-22 21:33:01 +02006890 gen7_setup_fixed_func_scheduler(dev_priv);
6891
Ville Syrjälä3c0edae2014-01-22 21:32:56 +02006892 /*
Jesse Barnes0f846f82012-06-14 11:04:47 -07006893 * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006894 * This implements the WaDisableRCZUnitClockGating:vlv workaround.
Jesse Barnes0f846f82012-06-14 11:04:47 -07006895 */
6896 I915_WRITE(GEN6_UCGCTL2,
Ville Syrjälä3c0edae2014-01-22 21:32:56 +02006897 GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
Jesse Barnes0f846f82012-06-14 11:04:47 -07006898
Akash Goelc98f5062014-03-24 23:00:07 +05306899 /* WaDisableL3Bank2xClockGate:vlv
6900 * Disabling L3 clock gating- MMIO 940c[25] = 1
6901 * Set bit 25, to disable L3_BANK_2x_CLK_GATING */
6902 I915_WRITE(GEN7_UCGCTL4,
6903 I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE);
Jesse Barnese3f33d42012-06-14 11:04:50 -07006904
Ville Syrjäläafd58e72014-01-22 21:33:03 +02006905 /*
6906 * BSpec says this must be set, even though
6907 * WaDisable4x2SubspanOptimization isn't listed for VLV.
6908 */
Daniel Vetter6b26c862012-04-24 14:04:12 +02006909 I915_WRITE(CACHE_MODE_1,
6910 _MASKED_BIT_ENABLE(PIXEL_SUBSPAN_COLLECT_OPT_DISABLE));
Jesse Barnes79831172012-06-20 10:53:12 -07006911
6912 /*
Ville Syrjäläda2518f2015-01-21 19:38:01 +02006913 * BSpec recommends 8x4 when MSAA is used,
6914 * however in practice 16x4 seems fastest.
6915 *
6916 * Note that PS/WM thread counts depend on the WIZ hashing
6917 * disable bit, which we don't touch here, but it's good
6918 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
6919 */
6920 I915_WRITE(GEN7_GT_MODE,
6921 _MASKED_FIELD(GEN6_WIZ_HASHING_MASK, GEN6_WIZ_HASHING_16x4));
6922
6923 /*
Ville Syrjälä031994e2014-01-22 21:32:46 +02006924 * WaIncreaseL3CreditsForVLVB0:vlv
6925 * This is the hardware default actually.
6926 */
6927 I915_WRITE(GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE);
6928
6929 /*
Damien Lespiauecdb4eb72013-05-03 18:48:10 +01006930 * WaDisableVLVClockGating_VBIIssue:vlv
Jesse Barnes2d809572012-10-25 12:15:44 -07006931 * Disable clock gating on th GCFG unit to prevent a delay
6932 * in the reporting of vblank events.
6933 */
Ville Syrjälä7a0d1ee2014-01-22 21:33:04 +02006934 I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006935}
6936
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006937static void chv_init_clock_gating(struct drm_i915_private *dev_priv)
Ville Syrjäläa4565da2014-04-09 13:28:10 +03006938{
Ville Syrjälä232ce332014-04-09 13:28:35 +03006939 /* WaVSRefCountFullforceMissDisable:chv */
6940 /* WaDSRefCountFullforceMissDisable:chv */
6941 I915_WRITE(GEN7_FF_THREAD_MODE,
6942 I915_READ(GEN7_FF_THREAD_MODE) &
6943 ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
Ville Syrjäläacea6f92014-04-09 13:28:36 +03006944
6945 /* WaDisableSemaphoreAndSyncFlipWait:chv */
6946 I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL,
6947 _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
Ville Syrjälä08466972014-04-09 13:28:37 +03006948
6949 /* WaDisableCSUnitClockGating:chv */
6950 I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) |
6951 GEN6_CSUNIT_CLOCK_GATE_DISABLE);
Ville Syrjäläc6317802014-04-09 13:28:38 +03006952
6953 /* WaDisableSDEUnitClockGating:chv */
6954 I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
6955 GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
Ville Syrjälä6d50b062015-05-19 20:32:57 +03006956
6957 /*
Imre Deak450174f2016-05-03 15:54:21 +03006958 * WaProgramL3SqcReg1Default:chv
6959 * See gfxspecs/Related Documents/Performance Guide/
6960 * LSQC Setting Recommendations.
6961 */
6962 gen8_set_l3sqc_credits(dev_priv, 38, 2);
Ville Syrjäläa4565da2014-04-09 13:28:10 +03006963}
6964
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006965static void g4x_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006966{
Jani Nikula5ce9a6492019-01-18 14:01:20 +02006967 u32 dspclk_gate;
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006968
6969 I915_WRITE(RENCLK_GATE_D1, 0);
6970 I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
6971 GS_UNIT_CLOCK_GATE_DISABLE |
6972 CL_UNIT_CLOCK_GATE_DISABLE);
6973 I915_WRITE(RAMCLK_GATE_D, 0);
6974 dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
6975 OVRUNIT_CLOCK_GATE_DISABLE |
6976 OVCUNIT_CLOCK_GATE_DISABLE;
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01006977 if (IS_GM45(dev_priv))
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006978 dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
6979 I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
Daniel Vetter4358a372012-10-18 11:49:51 +02006980
6981 /* WaDisableRenderCachePipelinedFlush */
6982 I915_WRITE(CACHE_MODE_0,
6983 _MASKED_BIT_ENABLE(CM0_PIPELINED_RENDER_FLUSH_DISABLE));
Ville Syrjäläde1aa622013-06-07 10:47:01 +03006984
Akash Goel4e046322014-04-04 17:14:38 +05306985 /* WaDisable_RenderCache_OperationalFlush:g4x */
6986 I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
6987
Ville Syrjälä46f16e62016-10-31 22:37:22 +02006988 g4x_disable_trickle_feed(dev_priv);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006989}
6990
Rodrigo Vivi91200c02017-08-28 22:20:26 -07006991static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03006992{
Tvrtko Ursulin4f5fd912019-06-11 11:45:48 +01006993 struct intel_uncore *uncore = &dev_priv->uncore;
6994
6995 intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
6996 intel_uncore_write(uncore, RENCLK_GATE_D2, 0);
6997 intel_uncore_write(uncore, DSPCLK_GATE_D, 0);
6998 intel_uncore_write(uncore, RAMCLK_GATE_D, 0);
6999 intel_uncore_write16(uncore, DEUC, 0);
7000 intel_uncore_write(uncore,
7001 MI_ARB_STATE,
7002 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
Akash Goel4e046322014-04-04 17:14:38 +05307003
7004 /* WaDisable_RenderCache_OperationalFlush:gen4 */
Tvrtko Ursulin4f5fd912019-06-11 11:45:48 +01007005 intel_uncore_write(uncore,
7006 CACHE_MODE_0,
7007 _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007008}
7009
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007010static void i965g_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007011{
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007012 I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
7013 I965_RCC_CLOCK_GATE_DISABLE |
7014 I965_RCPB_CLOCK_GATE_DISABLE |
7015 I965_ISC_CLOCK_GATE_DISABLE |
7016 I965_FBC_CLOCK_GATE_DISABLE);
7017 I915_WRITE(RENCLK_GATE_D2, 0);
Ville Syrjälä20f94962013-06-07 10:47:02 +03007018 I915_WRITE(MI_ARB_STATE,
7019 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
Akash Goel4e046322014-04-04 17:14:38 +05307020
7021 /* WaDisable_RenderCache_OperationalFlush:gen4 */
7022 I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007023}
7024
Ville Syrjälä46f16e62016-10-31 22:37:22 +02007025static void gen3_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007026{
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007027 u32 dstate = I915_READ(D_STATE);
7028
7029 dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
7030 DSTATE_DOT_CLOCK_GATING;
7031 I915_WRITE(D_STATE, dstate);
Chris Wilson13a86b82012-04-24 14:51:43 +01007032
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007033 if (IS_PINEVIEW(dev_priv))
Chris Wilson13a86b82012-04-24 14:51:43 +01007034 I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY));
Daniel Vetter974a3b02012-09-09 11:54:16 +02007035
7036 /* IIR "flip pending" means done if this bit is set */
7037 I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
Ville Syrjälä12fabbcb92014-02-25 15:13:38 +02007038
7039 /* interrupts should cause a wake up from C3 */
Ville Syrjälä32992542014-02-25 15:13:39 +02007040 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN));
Ville Syrjälädbb42742014-02-25 15:13:41 +02007041
7042 /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
7043 I915_WRITE(MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE));
Ville Syrjälä10383922014-08-15 01:21:54 +03007044
7045 I915_WRITE(MI_ARB_STATE,
7046 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007047}
7048
Ville Syrjälä46f16e62016-10-31 22:37:22 +02007049static void i85x_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007050{
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007051 I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
Ville Syrjälä54e472a2014-02-25 15:13:40 +02007052
7053 /* interrupts should cause a wake up from C3 */
7054 I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) |
7055 _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE));
Ville Syrjälä10383922014-08-15 01:21:54 +03007056
7057 I915_WRITE(MEM_MODE,
7058 _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE));
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007059}
7060
Ville Syrjälä46f16e62016-10-31 22:37:22 +02007061static void i830_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007062{
Ville Syrjälä10383922014-08-15 01:21:54 +03007063 I915_WRITE(MEM_MODE,
7064 _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) |
7065 _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE));
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007066}
7067
Ville Syrjälä46f16e62016-10-31 22:37:22 +02007068void intel_init_clock_gating(struct drm_i915_private *dev_priv)
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007069{
Ville Syrjälä46f16e62016-10-31 22:37:22 +02007070 dev_priv->display.init_clock_gating(dev_priv);
Eugeni Dodonov6f1d69b2012-04-18 15:29:25 -03007071}
7072
Ville Syrjälä712bf362016-10-31 22:37:23 +02007073void intel_suspend_hw(struct drm_i915_private *dev_priv)
Imre Deak7d708ee2013-04-17 14:04:50 +03007074{
Ville Syrjälä712bf362016-10-31 22:37:23 +02007075 if (HAS_PCH_LPT(dev_priv))
7076 lpt_suspend_hw(dev_priv);
Imre Deak7d708ee2013-04-17 14:04:50 +03007077}
7078
Ville Syrjälä46f16e62016-10-31 22:37:22 +02007079static void nop_init_clock_gating(struct drm_i915_private *dev_priv)
Imre Deakbb400da2016-03-16 13:38:54 +02007080{
7081 DRM_DEBUG_KMS("No clock gating settings or workarounds applied.\n");
7082}
7083
7084/**
7085 * intel_init_clock_gating_hooks - setup the clock gating hooks
7086 * @dev_priv: device private
7087 *
7088 * Setup the hooks that configure which clocks of a given platform can be
7089 * gated and also apply various GT and display specific workarounds for these
7090 * platforms. Note that some GT specific workarounds are applied separately
7091 * when GPU contexts or batchbuffers start their execution.
7092 */
7093void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv)
7094{
Lucas De Marchi13e53c52019-08-17 02:38:42 -07007095 if (IS_GEN(dev_priv, 12))
Michel Thierry5d869232019-08-23 01:20:34 -07007096 dev_priv->display.init_clock_gating = tgl_init_clock_gating;
Lucas De Marchi13e53c52019-08-17 02:38:42 -07007097 else if (IS_GEN(dev_priv, 11))
Oscar Mateod65dc3e2018-05-08 14:29:24 -07007098 dev_priv->display.init_clock_gating = icl_init_clock_gating;
Oscar Mateocc38cae2018-05-08 14:29:23 -07007099 else if (IS_CANNONLAKE(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007100 dev_priv->display.init_clock_gating = cnl_init_clock_gating;
Rodrigo Vivi0a46ddd2017-08-30 21:52:23 -07007101 else if (IS_COFFEELAKE(dev_priv))
7102 dev_priv->display.init_clock_gating = cfl_init_clock_gating;
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07007103 else if (IS_SKYLAKE(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007104 dev_priv->display.init_clock_gating = skl_init_clock_gating;
Rodrigo Vivi0a46ddd2017-08-30 21:52:23 -07007105 else if (IS_KABYLAKE(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007106 dev_priv->display.init_clock_gating = kbl_init_clock_gating;
Ander Conselvan de Oliveira9fb50262017-01-26 11:16:58 +02007107 else if (IS_BROXTON(dev_priv))
Imre Deakbb400da2016-03-16 13:38:54 +02007108 dev_priv->display.init_clock_gating = bxt_init_clock_gating;
Ander Conselvan de Oliveira9fb50262017-01-26 11:16:58 +02007109 else if (IS_GEMINILAKE(dev_priv))
7110 dev_priv->display.init_clock_gating = glk_init_clock_gating;
Imre Deakbb400da2016-03-16 13:38:54 +02007111 else if (IS_BROADWELL(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007112 dev_priv->display.init_clock_gating = bdw_init_clock_gating;
Imre Deakbb400da2016-03-16 13:38:54 +02007113 else if (IS_CHERRYVIEW(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007114 dev_priv->display.init_clock_gating = chv_init_clock_gating;
Imre Deakbb400da2016-03-16 13:38:54 +02007115 else if (IS_HASWELL(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007116 dev_priv->display.init_clock_gating = hsw_init_clock_gating;
Imre Deakbb400da2016-03-16 13:38:54 +02007117 else if (IS_IVYBRIDGE(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007118 dev_priv->display.init_clock_gating = ivb_init_clock_gating;
Imre Deakbb400da2016-03-16 13:38:54 +02007119 else if (IS_VALLEYVIEW(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007120 dev_priv->display.init_clock_gating = vlv_init_clock_gating;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007121 else if (IS_GEN(dev_priv, 6))
Imre Deakbb400da2016-03-16 13:38:54 +02007122 dev_priv->display.init_clock_gating = gen6_init_clock_gating;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007123 else if (IS_GEN(dev_priv, 5))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007124 dev_priv->display.init_clock_gating = ilk_init_clock_gating;
Imre Deakbb400da2016-03-16 13:38:54 +02007125 else if (IS_G4X(dev_priv))
7126 dev_priv->display.init_clock_gating = g4x_init_clock_gating;
Jani Nikulac0f86832016-12-07 12:13:04 +02007127 else if (IS_I965GM(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007128 dev_priv->display.init_clock_gating = i965gm_init_clock_gating;
Jani Nikulac0f86832016-12-07 12:13:04 +02007129 else if (IS_I965G(dev_priv))
Rodrigo Vivi91200c02017-08-28 22:20:26 -07007130 dev_priv->display.init_clock_gating = i965g_init_clock_gating;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007131 else if (IS_GEN(dev_priv, 3))
Imre Deakbb400da2016-03-16 13:38:54 +02007132 dev_priv->display.init_clock_gating = gen3_init_clock_gating;
7133 else if (IS_I85X(dev_priv) || IS_I865G(dev_priv))
7134 dev_priv->display.init_clock_gating = i85x_init_clock_gating;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007135 else if (IS_GEN(dev_priv, 2))
Imre Deakbb400da2016-03-16 13:38:54 +02007136 dev_priv->display.init_clock_gating = i830_init_clock_gating;
7137 else {
7138 MISSING_CASE(INTEL_DEVID(dev_priv));
7139 dev_priv->display.init_clock_gating = nop_init_clock_gating;
7140 }
7141}
7142
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007143/* Set up chip specific power management-related functions */
Ville Syrjälä62d75df2016-10-31 22:37:25 +02007144void intel_init_pm(struct drm_i915_private *dev_priv)
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007145{
Daniel Vetterc921aba2012-04-26 23:28:17 +02007146 /* For cxsr */
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007147 if (IS_PINEVIEW(dev_priv))
Ville Syrjälä148ac1f2016-10-31 22:37:16 +02007148 i915_pineview_get_mem_freq(dev_priv);
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007149 else if (IS_GEN(dev_priv, 5))
Ville Syrjälä148ac1f2016-10-31 22:37:16 +02007150 i915_ironlake_get_mem_freq(dev_priv);
Daniel Vetterc921aba2012-04-26 23:28:17 +02007151
James Ausmusb068a862019-10-09 10:23:14 -07007152 if (intel_has_sagv(dev_priv))
7153 skl_setup_sagv_block_time(dev_priv);
7154
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007155 /* For FIFO watermark updates */
Ville Syrjälä62d75df2016-10-31 22:37:25 +02007156 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjäläbb726512016-10-31 22:37:24 +02007157 skl_setup_wm_latency(dev_priv);
Maarten Lankhorste62929b2016-11-08 13:55:33 +01007158 dev_priv->display.initial_watermarks = skl_initial_wm;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01007159 dev_priv->display.atomic_update_watermarks = skl_atomic_update_crtc_wm;
Matt Roper98d39492016-05-12 07:06:03 -07007160 dev_priv->display.compute_global_watermarks = skl_compute_wm;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01007161 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjäläbb726512016-10-31 22:37:24 +02007162 ilk_setup_wm_latency(dev_priv);
Ville Syrjälä53615a52013-08-01 16:18:50 +03007163
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007164 if ((IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[1] &&
Ville Syrjäläbd602542014-01-07 16:14:10 +02007165 dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007166 (!IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[0] &&
Ville Syrjäläbd602542014-01-07 16:14:10 +02007167 dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) {
Matt Roper86c8bbb2015-09-24 15:53:16 -07007168 dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm;
Matt Ropered4a6a72016-02-23 17:20:13 -08007169 dev_priv->display.compute_intermediate_wm =
7170 ilk_compute_intermediate_wm;
7171 dev_priv->display.initial_watermarks =
7172 ilk_initial_watermarks;
7173 dev_priv->display.optimize_watermarks =
7174 ilk_optimize_watermarks;
Ville Syrjäläbd602542014-01-07 16:14:10 +02007175 } else {
7176 DRM_DEBUG_KMS("Failed to read display plane latency. "
7177 "Disable CxSR\n");
7178 }
Ville Syrjälä6b6b3ee2016-11-28 19:37:07 +02007179 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjäläbb726512016-10-31 22:37:24 +02007180 vlv_setup_wm_latency(dev_priv);
Ville Syrjäläff32c542017-03-02 19:14:57 +02007181 dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm;
Ville Syrjälä4841da52017-03-02 19:14:59 +02007182 dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm;
Ville Syrjäläff32c542017-03-02 19:14:57 +02007183 dev_priv->display.initial_watermarks = vlv_initial_watermarks;
Ville Syrjälä4841da52017-03-02 19:14:59 +02007184 dev_priv->display.optimize_watermarks = vlv_optimize_watermarks;
Ville Syrjäläff32c542017-03-02 19:14:57 +02007185 dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo;
Ville Syrjälä04548cb2017-04-21 21:14:29 +03007186 } else if (IS_G4X(dev_priv)) {
7187 g4x_setup_wm_latency(dev_priv);
7188 dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm;
7189 dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm;
7190 dev_priv->display.initial_watermarks = g4x_initial_watermarks;
7191 dev_priv->display.optimize_watermarks = g4x_optimize_watermarks;
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007192 } else if (IS_PINEVIEW(dev_priv)) {
Tvrtko Ursulin86d35d42019-03-26 07:40:54 +00007193 if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv),
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007194 dev_priv->is_ddr3,
7195 dev_priv->fsb_freq,
7196 dev_priv->mem_freq)) {
7197 DRM_INFO("failed to find known CxSR latency "
7198 "(found ddr%s fsb freq %d, mem freq %d), "
7199 "disabling CxSR\n",
7200 (dev_priv->is_ddr3 == 1) ? "3" : "2",
7201 dev_priv->fsb_freq, dev_priv->mem_freq);
7202 /* Disable CxSR and never update its watermark again */
Imre Deak5209b1f2014-07-01 12:36:17 +03007203 intel_set_memory_cxsr(dev_priv, false);
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007204 dev_priv->display.update_wm = NULL;
7205 } else
7206 dev_priv->display.update_wm = pineview_update_wm;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007207 } else if (IS_GEN(dev_priv, 4)) {
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007208 dev_priv->display.update_wm = i965_update_wm;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007209 } else if (IS_GEN(dev_priv, 3)) {
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007210 dev_priv->display.update_wm = i9xx_update_wm;
7211 dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007212 } else if (IS_GEN(dev_priv, 2)) {
Jani Nikula24977872019-09-11 12:26:08 +03007213 if (INTEL_NUM_PIPES(dev_priv) == 1) {
Daniel Vetterfeb56b92013-12-14 20:38:30 -02007214 dev_priv->display.update_wm = i845_update_wm;
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007215 dev_priv->display.get_fifo_size = i845_get_fifo_size;
Daniel Vetterfeb56b92013-12-14 20:38:30 -02007216 } else {
7217 dev_priv->display.update_wm = i9xx_update_wm;
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007218 dev_priv->display.get_fifo_size = i830_get_fifo_size;
Daniel Vetterfeb56b92013-12-14 20:38:30 -02007219 }
Daniel Vetterfeb56b92013-12-14 20:38:30 -02007220 } else {
7221 DRM_ERROR("unexpected fall-through in intel_init_pm\n");
Eugeni Dodonov1fa61102012-04-18 15:29:26 -03007222 }
7223}
7224
Tvrtko Ursulin192aa182016-12-01 14:16:45 +00007225void intel_pm_setup(struct drm_i915_private *dev_priv)
Chris Wilson907b28c2013-07-19 20:36:52 +01007226{
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01007227 dev_priv->runtime_pm.suspended = false;
7228 atomic_set(&dev_priv->runtime_pm.wakeref_count, 0);
Chris Wilson907b28c2013-07-19 20:36:52 +01007229}