2 * Copyright © 2012 Intel Corporation
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:
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
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
28 #include <linux/module.h>
29 #include <linux/string_helpers.h>
30 #include <linux/pm_runtime.h>
32 #include <drm/drm_atomic_helper.h>
33 #include <drm/drm_blend.h>
34 #include <drm/drm_fourcc.h>
35 #include <drm/drm_plane_helper.h>
37 #include "display/intel_atomic.h"
38 #include "display/intel_atomic_plane.h"
39 #include "display/intel_bw.h"
40 #include "display/intel_de.h"
41 #include "display/intel_display_trace.h"
42 #include "display/intel_display_types.h"
43 #include "display/intel_fb.h"
44 #include "display/intel_fbc.h"
45 #include "display/intel_sprite.h"
46 #include "display/skl_universal_plane.h"
48 #include "gt/intel_engine_regs.h"
49 #include "gt/intel_gt_regs.h"
50 #include "gt/intel_llc.h"
53 #include "i915_fixed.h"
55 #include "intel_mchbar_regs.h"
56 #include "intel_pcode.h"
58 #include "vlv_sideband.h"
59 #include "../../../platform/x86/intel_ips.h"
61 static void skl_sagv_disable(struct drm_i915_private *dev_priv);
63 struct drm_i915_clock_gating_funcs {
64 void (*init_clock_gating)(struct drm_i915_private *i915);
67 /* Stores plane specific WM parameters */
68 struct skl_wm_params {
69 bool x_tiled, y_tiled;
76 u32 plane_bytes_per_line;
77 uint_fixed_16_16_t plane_blocks_per_line;
78 uint_fixed_16_16_t y_tile_minimum;
83 /* used in computing the new watermarks state */
84 struct intel_wm_config {
85 unsigned int num_pipes_active;
90 static void gen9_init_clock_gating(struct drm_i915_private *dev_priv)
92 if (HAS_LLC(dev_priv)) {
94 * WaCompressedResourceDisplayNewHashMode:skl,kbl
95 * Display WA #0390: skl,kbl
97 * Must match Sampler, Pixel Back End, and Media. See
98 * WaCompressedResourceSamplerPbeMediaNewHashMode.
100 intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1,
101 intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR1_1) |
102 SKL_DE_COMPRESSED_HASH_MODE);
105 /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl,cfl */
106 intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1,
107 intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP);
109 /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */
110 intel_uncore_write(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1,
111 intel_uncore_read(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM);
114 * WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl
115 * Display WA #0859: skl,bxt,kbl,glk,cfl
117 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) |
118 DISP_FBC_MEMORY_WAKE);
121 static void bxt_init_clock_gating(struct drm_i915_private *dev_priv)
123 gen9_init_clock_gating(dev_priv);
125 /* WaDisableSDEUnitClockGating:bxt */
126 intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) |
127 GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
131 * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only.
133 intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) |
134 GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ);
137 * Wa: Backlight PWM may stop in the asserted state, causing backlight
140 intel_uncore_write(&dev_priv->uncore, GEN9_CLKGATE_DIS_0, intel_uncore_read(&dev_priv->uncore, GEN9_CLKGATE_DIS_0) |
141 PWM1_GATING_DIS | PWM2_GATING_DIS);
144 * Lower the display internal timeout.
145 * This is needed to avoid any hard hangs when DSI port PLL
146 * is off and a MMIO access is attempted by any privilege
147 * application, using batch buffers or any other means.
149 intel_uncore_write(&dev_priv->uncore, RM_TIMEOUT, MMIO_TIMEOUT_US(950));
152 * WaFbcTurnOffFbcWatermark:bxt
153 * Display WA #0562: bxt
155 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) |
159 * WaFbcHighMemBwCorruptionAvoidance:bxt
160 * Display WA #0883: bxt
162 intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A),
163 intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A)) |
164 DPFC_DISABLE_DUMMY0);
167 static void glk_init_clock_gating(struct drm_i915_private *dev_priv)
169 gen9_init_clock_gating(dev_priv);
172 * WaDisablePWMClockGating:glk
173 * Backlight PWM may stop in the asserted state, causing backlight
176 intel_uncore_write(&dev_priv->uncore, GEN9_CLKGATE_DIS_0, intel_uncore_read(&dev_priv->uncore, GEN9_CLKGATE_DIS_0) |
177 PWM1_GATING_DIS | PWM2_GATING_DIS);
180 static void pnv_get_mem_freq(struct drm_i915_private *dev_priv)
184 tmp = intel_uncore_read(&dev_priv->uncore, CLKCFG);
186 switch (tmp & CLKCFG_FSB_MASK) {
188 dev_priv->fsb_freq = 533; /* 133*4 */
191 dev_priv->fsb_freq = 800; /* 200*4 */
194 dev_priv->fsb_freq = 667; /* 167*4 */
197 dev_priv->fsb_freq = 400; /* 100*4 */
201 switch (tmp & CLKCFG_MEM_MASK) {
203 dev_priv->mem_freq = 533;
206 dev_priv->mem_freq = 667;
209 dev_priv->mem_freq = 800;
213 /* detect pineview DDR3 setting */
214 tmp = intel_uncore_read(&dev_priv->uncore, CSHRDDR3CTL);
215 dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0;
218 static void ilk_get_mem_freq(struct drm_i915_private *dev_priv)
222 ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1);
223 csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0);
225 switch (ddrpll & 0xff) {
227 dev_priv->mem_freq = 800;
230 dev_priv->mem_freq = 1066;
233 dev_priv->mem_freq = 1333;
236 dev_priv->mem_freq = 1600;
239 drm_dbg(&dev_priv->drm, "unknown memory frequency 0x%02x\n",
241 dev_priv->mem_freq = 0;
245 switch (csipll & 0x3ff) {
247 dev_priv->fsb_freq = 3200;
250 dev_priv->fsb_freq = 3733;
253 dev_priv->fsb_freq = 4266;
256 dev_priv->fsb_freq = 4800;
259 dev_priv->fsb_freq = 5333;
262 dev_priv->fsb_freq = 5866;
265 dev_priv->fsb_freq = 6400;
268 drm_dbg(&dev_priv->drm, "unknown fsb frequency 0x%04x\n",
270 dev_priv->fsb_freq = 0;
275 static const struct cxsr_latency cxsr_latency_table[] = {
276 {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
277 {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
278 {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
279 {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
280 {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
282 {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
283 {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
284 {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
285 {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
286 {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
288 {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
289 {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
290 {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
291 {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
292 {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
294 {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
295 {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
296 {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
297 {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
298 {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
300 {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
301 {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
302 {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
303 {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
304 {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
306 {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
307 {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
308 {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
309 {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
310 {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
313 static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop,
318 const struct cxsr_latency *latency;
321 if (fsb == 0 || mem == 0)
324 for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
325 latency = &cxsr_latency_table[i];
326 if (is_desktop == latency->is_desktop &&
327 is_ddr3 == latency->is_ddr3 &&
328 fsb == latency->fsb_freq && mem == latency->mem_freq)
332 DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
337 static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable)
341 vlv_punit_get(dev_priv);
343 val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
345 val &= ~FORCE_DDR_HIGH_FREQ;
347 val |= FORCE_DDR_HIGH_FREQ;
348 val &= ~FORCE_DDR_LOW_FREQ;
349 val |= FORCE_DDR_FREQ_REQ_ACK;
350 vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val);
352 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) &
353 FORCE_DDR_FREQ_REQ_ACK) == 0, 3))
354 drm_err(&dev_priv->drm,
355 "timed out waiting for Punit DDR DVFS request\n");
357 vlv_punit_put(dev_priv);
360 static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable)
364 vlv_punit_get(dev_priv);
366 val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM);
368 val |= DSP_MAXFIFO_PM5_ENABLE;
370 val &= ~DSP_MAXFIFO_PM5_ENABLE;
371 vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val);
373 vlv_punit_put(dev_priv);
376 #define FW_WM(value, plane) \
377 (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK)
379 static bool _intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable)
384 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
385 was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
386 intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0);
387 intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF_VLV);
388 } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) {
389 was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF) & FW_BLC_SELF_EN;
390 intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0);
391 intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF);
392 } else if (IS_PINEVIEW(dev_priv)) {
393 val = intel_uncore_read(&dev_priv->uncore, DSPFW3);
394 was_enabled = val & PINEVIEW_SELF_REFRESH_EN;
396 val |= PINEVIEW_SELF_REFRESH_EN;
398 val &= ~PINEVIEW_SELF_REFRESH_EN;
399 intel_uncore_write(&dev_priv->uncore, DSPFW3, val);
400 intel_uncore_posting_read(&dev_priv->uncore, DSPFW3);
401 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) {
402 was_enabled = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF) & FW_BLC_SELF_EN;
403 val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) :
404 _MASKED_BIT_DISABLE(FW_BLC_SELF_EN);
405 intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, val);
406 intel_uncore_posting_read(&dev_priv->uncore, FW_BLC_SELF);
407 } else if (IS_I915GM(dev_priv)) {
409 * FIXME can't find a bit like this for 915G, and
410 * and yet it does have the related watermark in
411 * FW_BLC_SELF. What's going on?
413 was_enabled = intel_uncore_read(&dev_priv->uncore, INSTPM) & INSTPM_SELF_EN;
414 val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) :
415 _MASKED_BIT_DISABLE(INSTPM_SELF_EN);
416 intel_uncore_write(&dev_priv->uncore, INSTPM, val);
417 intel_uncore_posting_read(&dev_priv->uncore, INSTPM);
422 trace_intel_memory_cxsr(dev_priv, was_enabled, enable);
424 drm_dbg_kms(&dev_priv->drm, "memory self-refresh is %s (was %s)\n",
425 str_enabled_disabled(enable),
426 str_enabled_disabled(was_enabled));
432 * intel_set_memory_cxsr - Configure CxSR state
433 * @dev_priv: i915 device
434 * @enable: Allow vs. disallow CxSR
436 * Allow or disallow the system to enter a special CxSR
437 * (C-state self refresh) state. What typically happens in CxSR mode
438 * is that several display FIFOs may get combined into a single larger
439 * FIFO for a particular plane (so called max FIFO mode) to allow the
440 * system to defer memory fetches longer, and the memory will enter
443 * Note that enabling CxSR does not guarantee that the system enter
444 * this special mode, nor does it guarantee that the system stays
445 * in that mode once entered. So this just allows/disallows the system
446 * to autonomously utilize the CxSR mode. Other factors such as core
447 * C-states will affect when/if the system actually enters/exits the
450 * Note that on VLV/CHV this actually only controls the max FIFO mode,
451 * and the system is free to enter/exit memory self refresh at any time
452 * even when the use of CxSR has been disallowed.
454 * While the system is actually in the CxSR/max FIFO mode, some plane
455 * control registers will not get latched on vblank. Thus in order to
456 * guarantee the system will respond to changes in the plane registers
457 * we must always disallow CxSR prior to making changes to those registers.
458 * Unfortunately the system will re-evaluate the CxSR conditions at
459 * frame start which happens after vblank start (which is when the plane
460 * registers would get latched), so we can't proceed with the plane update
461 * during the same frame where we disallowed CxSR.
463 * Certain platforms also have a deeper HPLL SR mode. Fortunately the
464 * HPLL SR mode depends on CxSR itself, so we don't have to hand hold
465 * the hardware w.r.t. HPLL SR when writing to plane registers.
466 * Disallowing just CxSR is sufficient.
468 bool intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable)
472 mutex_lock(&dev_priv->wm.wm_mutex);
473 ret = _intel_set_memory_cxsr(dev_priv, enable);
474 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
475 dev_priv->wm.vlv.cxsr = enable;
476 else if (IS_G4X(dev_priv))
477 dev_priv->wm.g4x.cxsr = enable;
478 mutex_unlock(&dev_priv->wm.wm_mutex);
484 * Latency for FIFO fetches is dependent on several factors:
485 * - memory configuration (speed, channels)
487 * - current MCH state
488 * It can be fairly high in some situations, so here we assume a fairly
489 * pessimal value. It's a tradeoff between extra memory fetches (if we
490 * set this value too high, the FIFO will fetch frequently to stay full)
491 * and power consumption (set it too low to save power and we might see
492 * FIFO underruns and display "flicker").
494 * A value of 5us seems to be a good balance; safe for very low end
495 * platforms but not overly aggressive on lower latency configs.
497 static const int pessimal_latency_ns = 5000;
499 #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \
500 ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8))
502 static void vlv_get_fifo_size(struct intel_crtc_state *crtc_state)
504 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
505 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
506 struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state;
507 enum pipe pipe = crtc->pipe;
508 int sprite0_start, sprite1_start;
509 u32 dsparb, dsparb2, dsparb3;
513 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB);
514 dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2);
515 sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0);
516 sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4);
519 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB);
520 dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2);
521 sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8);
522 sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12);
525 dsparb2 = intel_uncore_read(&dev_priv->uncore, DSPARB2);
526 dsparb3 = intel_uncore_read(&dev_priv->uncore, DSPARB3);
527 sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16);
528 sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20);
535 fifo_state->plane[PLANE_PRIMARY] = sprite0_start;
536 fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start;
537 fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start;
538 fifo_state->plane[PLANE_CURSOR] = 63;
541 static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv,
542 enum i9xx_plane_id i9xx_plane)
544 u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB);
547 size = dsparb & 0x7f;
548 if (i9xx_plane == PLANE_B)
549 size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
551 drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n",
552 dsparb, plane_name(i9xx_plane), size);
557 static int i830_get_fifo_size(struct drm_i915_private *dev_priv,
558 enum i9xx_plane_id i9xx_plane)
560 u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB);
563 size = dsparb & 0x1ff;
564 if (i9xx_plane == PLANE_B)
565 size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
566 size >>= 1; /* Convert to cachelines */
568 drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n",
569 dsparb, plane_name(i9xx_plane), size);
574 static int i845_get_fifo_size(struct drm_i915_private *dev_priv,
575 enum i9xx_plane_id i9xx_plane)
577 u32 dsparb = intel_uncore_read(&dev_priv->uncore, DSPARB);
580 size = dsparb & 0x7f;
581 size >>= 2; /* Convert to cachelines */
583 drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n",
584 dsparb, plane_name(i9xx_plane), size);
589 /* Pineview has different values for various configs */
590 static const struct intel_watermark_params pnv_display_wm = {
591 .fifo_size = PINEVIEW_DISPLAY_FIFO,
592 .max_wm = PINEVIEW_MAX_WM,
593 .default_wm = PINEVIEW_DFT_WM,
594 .guard_size = PINEVIEW_GUARD_WM,
595 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
598 static const struct intel_watermark_params pnv_display_hplloff_wm = {
599 .fifo_size = PINEVIEW_DISPLAY_FIFO,
600 .max_wm = PINEVIEW_MAX_WM,
601 .default_wm = PINEVIEW_DFT_HPLLOFF_WM,
602 .guard_size = PINEVIEW_GUARD_WM,
603 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
606 static const struct intel_watermark_params pnv_cursor_wm = {
607 .fifo_size = PINEVIEW_CURSOR_FIFO,
608 .max_wm = PINEVIEW_CURSOR_MAX_WM,
609 .default_wm = PINEVIEW_CURSOR_DFT_WM,
610 .guard_size = PINEVIEW_CURSOR_GUARD_WM,
611 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
614 static const struct intel_watermark_params pnv_cursor_hplloff_wm = {
615 .fifo_size = PINEVIEW_CURSOR_FIFO,
616 .max_wm = PINEVIEW_CURSOR_MAX_WM,
617 .default_wm = PINEVIEW_CURSOR_DFT_WM,
618 .guard_size = PINEVIEW_CURSOR_GUARD_WM,
619 .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
622 static const struct intel_watermark_params i965_cursor_wm_info = {
623 .fifo_size = I965_CURSOR_FIFO,
624 .max_wm = I965_CURSOR_MAX_WM,
625 .default_wm = I965_CURSOR_DFT_WM,
627 .cacheline_size = I915_FIFO_LINE_SIZE,
630 static const struct intel_watermark_params i945_wm_info = {
631 .fifo_size = I945_FIFO_SIZE,
632 .max_wm = I915_MAX_WM,
635 .cacheline_size = I915_FIFO_LINE_SIZE,
638 static const struct intel_watermark_params i915_wm_info = {
639 .fifo_size = I915_FIFO_SIZE,
640 .max_wm = I915_MAX_WM,
643 .cacheline_size = I915_FIFO_LINE_SIZE,
646 static const struct intel_watermark_params i830_a_wm_info = {
647 .fifo_size = I855GM_FIFO_SIZE,
648 .max_wm = I915_MAX_WM,
651 .cacheline_size = I830_FIFO_LINE_SIZE,
654 static const struct intel_watermark_params i830_bc_wm_info = {
655 .fifo_size = I855GM_FIFO_SIZE,
656 .max_wm = I915_MAX_WM/2,
659 .cacheline_size = I830_FIFO_LINE_SIZE,
662 static const struct intel_watermark_params i845_wm_info = {
663 .fifo_size = I830_FIFO_SIZE,
664 .max_wm = I915_MAX_WM,
667 .cacheline_size = I830_FIFO_LINE_SIZE,
671 * intel_wm_method1 - Method 1 / "small buffer" watermark formula
672 * @pixel_rate: Pipe pixel rate in kHz
673 * @cpp: Plane bytes per pixel
674 * @latency: Memory wakeup latency in 0.1us units
676 * Compute the watermark using the method 1 or "small buffer"
677 * formula. The caller may additonally add extra cachelines
678 * to account for TLB misses and clock crossings.
680 * This method is concerned with the short term drain rate
681 * of the FIFO, ie. it does not account for blanking periods
682 * which would effectively reduce the average drain rate across
683 * a longer period. The name "small" refers to the fact the
684 * FIFO is relatively small compared to the amount of data
687 * The FIFO level vs. time graph might look something like:
691 * __---__---__ (- plane active, _ blanking)
694 * or perhaps like this:
697 * __----__----__ (- plane active, _ blanking)
701 * The watermark in bytes
703 static unsigned int intel_wm_method1(unsigned int pixel_rate,
705 unsigned int latency)
709 ret = mul_u32_u32(pixel_rate, cpp * latency);
710 ret = DIV_ROUND_UP_ULL(ret, 10000);
716 * intel_wm_method2 - Method 2 / "large buffer" watermark formula
717 * @pixel_rate: Pipe pixel rate in kHz
718 * @htotal: Pipe horizontal total
719 * @width: Plane width in pixels
720 * @cpp: Plane bytes per pixel
721 * @latency: Memory wakeup latency in 0.1us units
723 * Compute the watermark using the method 2 or "large buffer"
724 * formula. The caller may additonally add extra cachelines
725 * to account for TLB misses and clock crossings.
727 * This method is concerned with the long term drain rate
728 * of the FIFO, ie. it does account for blanking periods
729 * which effectively reduce the average drain rate across
730 * a longer period. The name "large" refers to the fact the
731 * FIFO is relatively large compared to the amount of data
734 * The FIFO level vs. time graph might look something like:
739 * __ --__--__--__--__--__--__ (- plane active, _ blanking)
743 * The watermark in bytes
745 static unsigned int intel_wm_method2(unsigned int pixel_rate,
749 unsigned int latency)
754 * FIXME remove once all users are computing
755 * watermarks in the correct place.
757 if (WARN_ON_ONCE(htotal == 0))
760 ret = (latency * pixel_rate) / (htotal * 10000);
761 ret = (ret + 1) * width * cpp;
767 * intel_calculate_wm - calculate watermark level
768 * @pixel_rate: pixel clock
769 * @wm: chip FIFO params
770 * @fifo_size: size of the FIFO buffer
771 * @cpp: bytes per pixel
772 * @latency_ns: memory latency for the platform
774 * Calculate the watermark level (the level at which the display plane will
775 * start fetching from memory again). Each chip has a different display
776 * FIFO size and allocation, so the caller needs to figure that out and pass
777 * in the correct intel_watermark_params structure.
779 * As the pixel clock runs, the FIFO will be drained at a rate that depends
780 * on the pixel size. When it reaches the watermark level, it'll start
781 * fetching FIFO line sized based chunks from memory until the FIFO fills
782 * past the watermark point. If the FIFO drains completely, a FIFO underrun
783 * will occur, and a display engine hang could result.
785 static unsigned int intel_calculate_wm(int pixel_rate,
786 const struct intel_watermark_params *wm,
787 int fifo_size, int cpp,
788 unsigned int latency_ns)
790 int entries, wm_size;
793 * Note: we need to make sure we don't overflow for various clock &
795 * clocks go from a few thousand to several hundred thousand.
796 * latency is usually a few thousand
798 entries = intel_wm_method1(pixel_rate, cpp,
800 entries = DIV_ROUND_UP(entries, wm->cacheline_size) +
802 DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries);
804 wm_size = fifo_size - entries;
805 DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size);
807 /* Don't promote wm_size to unsigned... */
808 if (wm_size > wm->max_wm)
809 wm_size = wm->max_wm;
811 wm_size = wm->default_wm;
814 * Bspec seems to indicate that the value shouldn't be lower than
815 * 'burst size + 1'. Certainly 830 is quite unhappy with low values.
816 * Lets go for 8 which is the burst size since certain platforms
817 * already use a hardcoded 8 (which is what the spec says should be
826 static bool is_disabling(int old, int new, int threshold)
828 return old >= threshold && new < threshold;
831 static bool is_enabling(int old, int new, int threshold)
833 return old < threshold && new >= threshold;
836 static int intel_wm_num_levels(struct drm_i915_private *dev_priv)
838 return dev_priv->wm.max_level + 1;
841 static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state,
842 const struct intel_plane_state *plane_state)
844 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
846 /* FIXME check the 'enable' instead */
847 if (!crtc_state->hw.active)
851 * Treat cursor with fb as always visible since cursor updates
852 * can happen faster than the vrefresh rate, and the current
853 * watermark code doesn't handle that correctly. Cursor updates
854 * which set/clear the fb or change the cursor size are going
855 * to get throttled by intel_legacy_cursor_update() to work
856 * around this problem with the watermark code.
858 if (plane->id == PLANE_CURSOR)
859 return plane_state->hw.fb != NULL;
861 return plane_state->uapi.visible;
864 static bool intel_crtc_active(struct intel_crtc *crtc)
866 /* Be paranoid as we can arrive here with only partial
867 * state retrieved from the hardware during setup.
869 * We can ditch the adjusted_mode.crtc_clock check as soon
870 * as Haswell has gained clock readout/fastboot support.
872 * We can ditch the crtc->primary->state->fb check as soon as we can
873 * properly reconstruct framebuffers.
875 * FIXME: The intel_crtc->active here should be switched to
876 * crtc->state->active once we have proper CRTC states wired up
879 return crtc && crtc->active && crtc->base.primary->state->fb &&
880 crtc->config->hw.adjusted_mode.crtc_clock;
883 static struct intel_crtc *single_enabled_crtc(struct drm_i915_private *dev_priv)
885 struct intel_crtc *crtc, *enabled = NULL;
887 for_each_intel_crtc(&dev_priv->drm, crtc) {
888 if (intel_crtc_active(crtc)) {
898 static void pnv_update_wm(struct drm_i915_private *dev_priv)
900 struct intel_crtc *crtc;
901 const struct cxsr_latency *latency;
905 latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv),
910 drm_dbg_kms(&dev_priv->drm,
911 "Unknown FSB/MEM found, disable CxSR\n");
912 intel_set_memory_cxsr(dev_priv, false);
916 crtc = single_enabled_crtc(dev_priv);
918 const struct drm_framebuffer *fb =
919 crtc->base.primary->state->fb;
920 int pixel_rate = crtc->config->pixel_rate;
921 int cpp = fb->format->cpp[0];
924 wm = intel_calculate_wm(pixel_rate, &pnv_display_wm,
925 pnv_display_wm.fifo_size,
926 cpp, latency->display_sr);
927 reg = intel_uncore_read(&dev_priv->uncore, DSPFW1);
928 reg &= ~DSPFW_SR_MASK;
929 reg |= FW_WM(wm, SR);
930 intel_uncore_write(&dev_priv->uncore, DSPFW1, reg);
931 drm_dbg_kms(&dev_priv->drm, "DSPFW1 register is %x\n", reg);
934 wm = intel_calculate_wm(pixel_rate, &pnv_cursor_wm,
935 pnv_display_wm.fifo_size,
936 4, latency->cursor_sr);
937 reg = intel_uncore_read(&dev_priv->uncore, DSPFW3);
938 reg &= ~DSPFW_CURSOR_SR_MASK;
939 reg |= FW_WM(wm, CURSOR_SR);
940 intel_uncore_write(&dev_priv->uncore, DSPFW3, reg);
942 /* Display HPLL off SR */
943 wm = intel_calculate_wm(pixel_rate, &pnv_display_hplloff_wm,
944 pnv_display_hplloff_wm.fifo_size,
945 cpp, latency->display_hpll_disable);
946 reg = intel_uncore_read(&dev_priv->uncore, DSPFW3);
947 reg &= ~DSPFW_HPLL_SR_MASK;
948 reg |= FW_WM(wm, HPLL_SR);
949 intel_uncore_write(&dev_priv->uncore, DSPFW3, reg);
951 /* cursor HPLL off SR */
952 wm = intel_calculate_wm(pixel_rate, &pnv_cursor_hplloff_wm,
953 pnv_display_hplloff_wm.fifo_size,
954 4, latency->cursor_hpll_disable);
955 reg = intel_uncore_read(&dev_priv->uncore, DSPFW3);
956 reg &= ~DSPFW_HPLL_CURSOR_MASK;
957 reg |= FW_WM(wm, HPLL_CURSOR);
958 intel_uncore_write(&dev_priv->uncore, DSPFW3, reg);
959 drm_dbg_kms(&dev_priv->drm, "DSPFW3 register is %x\n", reg);
961 intel_set_memory_cxsr(dev_priv, true);
963 intel_set_memory_cxsr(dev_priv, false);
968 * Documentation says:
969 * "If the line size is small, the TLB fetches can get in the way of the
970 * data fetches, causing some lag in the pixel data return which is not
971 * accounted for in the above formulas. The following adjustment only
972 * needs to be applied if eight whole lines fit in the buffer at once.
973 * The WM is adjusted upwards by the difference between the FIFO size
974 * and the size of 8 whole lines. This adjustment is always performed
975 * in the actual pixel depth regardless of whether FBC is enabled or not."
977 static unsigned int g4x_tlb_miss_wa(int fifo_size, int width, int cpp)
979 int tlb_miss = fifo_size * 64 - width * cpp * 8;
981 return max(0, tlb_miss);
984 static void g4x_write_wm_values(struct drm_i915_private *dev_priv,
985 const struct g4x_wm_values *wm)
989 for_each_pipe(dev_priv, pipe)
990 trace_g4x_wm(intel_crtc_for_pipe(dev_priv, pipe), wm);
992 intel_uncore_write(&dev_priv->uncore, DSPFW1,
993 FW_WM(wm->sr.plane, SR) |
994 FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) |
995 FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) |
996 FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA));
997 intel_uncore_write(&dev_priv->uncore, DSPFW2,
998 (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) |
999 FW_WM(wm->sr.fbc, FBC_SR) |
1000 FW_WM(wm->hpll.fbc, FBC_HPLL_SR) |
1001 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) |
1002 FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) |
1003 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA));
1004 intel_uncore_write(&dev_priv->uncore, DSPFW3,
1005 (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) |
1006 FW_WM(wm->sr.cursor, CURSOR_SR) |
1007 FW_WM(wm->hpll.cursor, HPLL_CURSOR) |
1008 FW_WM(wm->hpll.plane, HPLL_SR));
1010 intel_uncore_posting_read(&dev_priv->uncore, DSPFW1);
1013 #define FW_WM_VLV(value, plane) \
1014 (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV)
1016 static void vlv_write_wm_values(struct drm_i915_private *dev_priv,
1017 const struct vlv_wm_values *wm)
1021 for_each_pipe(dev_priv, pipe) {
1022 trace_vlv_wm(intel_crtc_for_pipe(dev_priv, pipe), wm);
1024 intel_uncore_write(&dev_priv->uncore, VLV_DDL(pipe),
1025 (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) |
1026 (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) |
1027 (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) |
1028 (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT));
1032 * Zero the (unused) WM1 watermarks, and also clear all the
1033 * high order bits so that there are no out of bounds values
1034 * present in the registers during the reprogramming.
1036 intel_uncore_write(&dev_priv->uncore, DSPHOWM, 0);
1037 intel_uncore_write(&dev_priv->uncore, DSPHOWM1, 0);
1038 intel_uncore_write(&dev_priv->uncore, DSPFW4, 0);
1039 intel_uncore_write(&dev_priv->uncore, DSPFW5, 0);
1040 intel_uncore_write(&dev_priv->uncore, DSPFW6, 0);
1042 intel_uncore_write(&dev_priv->uncore, DSPFW1,
1043 FW_WM(wm->sr.plane, SR) |
1044 FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) |
1045 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) |
1046 FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA));
1047 intel_uncore_write(&dev_priv->uncore, DSPFW2,
1048 FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) |
1049 FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) |
1050 FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA));
1051 intel_uncore_write(&dev_priv->uncore, DSPFW3,
1052 FW_WM(wm->sr.cursor, CURSOR_SR));
1054 if (IS_CHERRYVIEW(dev_priv)) {
1055 intel_uncore_write(&dev_priv->uncore, DSPFW7_CHV,
1056 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) |
1057 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC));
1058 intel_uncore_write(&dev_priv->uncore, DSPFW8_CHV,
1059 FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) |
1060 FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE));
1061 intel_uncore_write(&dev_priv->uncore, DSPFW9_CHV,
1062 FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) |
1063 FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC));
1064 intel_uncore_write(&dev_priv->uncore, DSPHOWM,
1065 FW_WM(wm->sr.plane >> 9, SR_HI) |
1066 FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) |
1067 FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) |
1068 FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) |
1069 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) |
1070 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) |
1071 FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) |
1072 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) |
1073 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) |
1074 FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY] >> 8, PLANEA_HI));
1076 intel_uncore_write(&dev_priv->uncore, DSPFW7,
1077 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) |
1078 FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC));
1079 intel_uncore_write(&dev_priv->uncore, DSPHOWM,
1080 FW_WM(wm->sr.plane >> 9, SR_HI) |
1081 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) |
1082 FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) |
1083 FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) |
1084 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) |
1085 FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) |
1086 FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY] >> 8, PLANEA_HI));
1089 intel_uncore_posting_read(&dev_priv->uncore, DSPFW1);
1094 static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv)
1096 /* all latencies in usec */
1097 dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5;
1098 dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12;
1099 dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35;
1101 dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL;
1104 static int g4x_plane_fifo_size(enum plane_id plane_id, int level)
1107 * DSPCNTR[13] supposedly controls whether the
1108 * primary plane can use the FIFO space otherwise
1109 * reserved for the sprite plane. It's not 100% clear
1110 * what the actual FIFO size is, but it looks like we
1111 * can happily set both primary and sprite watermarks
1112 * up to 127 cachelines. So that would seem to mean
1113 * that either DSPCNTR[13] doesn't do anything, or that
1114 * the total FIFO is >= 256 cachelines in size. Either
1115 * way, we don't seem to have to worry about this
1116 * repartitioning as the maximum watermark value the
1117 * register can hold for each plane is lower than the
1118 * minimum FIFO size.
1124 return level == G4X_WM_LEVEL_NORMAL ? 127 : 511;
1126 return level == G4X_WM_LEVEL_NORMAL ? 127 : 0;
1128 MISSING_CASE(plane_id);
1133 static int g4x_fbc_fifo_size(int level)
1136 case G4X_WM_LEVEL_SR:
1138 case G4X_WM_LEVEL_HPLL:
1141 MISSING_CASE(level);
1146 static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state,
1147 const struct intel_plane_state *plane_state,
1150 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1151 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1152 const struct drm_display_mode *pipe_mode =
1153 &crtc_state->hw.pipe_mode;
1154 unsigned int latency = dev_priv->wm.pri_latency[level] * 10;
1155 unsigned int pixel_rate, htotal, cpp, width, wm;
1160 if (!intel_wm_plane_visible(crtc_state, plane_state))
1163 cpp = plane_state->hw.fb->format->cpp[0];
1166 * WaUse32BppForSRWM:ctg,elk
1168 * The spec fails to list this restriction for the
1169 * HPLL watermark, which seems a little strange.
1170 * Let's use 32bpp for the HPLL watermark as well.
1172 if (plane->id == PLANE_PRIMARY &&
1173 level != G4X_WM_LEVEL_NORMAL)
1176 pixel_rate = crtc_state->pixel_rate;
1177 htotal = pipe_mode->crtc_htotal;
1178 width = drm_rect_width(&plane_state->uapi.src) >> 16;
1180 if (plane->id == PLANE_CURSOR) {
1181 wm = intel_wm_method2(pixel_rate, htotal, width, cpp, latency);
1182 } else if (plane->id == PLANE_PRIMARY &&
1183 level == G4X_WM_LEVEL_NORMAL) {
1184 wm = intel_wm_method1(pixel_rate, cpp, latency);
1186 unsigned int small, large;
1188 small = intel_wm_method1(pixel_rate, cpp, latency);
1189 large = intel_wm_method2(pixel_rate, htotal, width, cpp, latency);
1191 wm = min(small, large);
1194 wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level),
1197 wm = DIV_ROUND_UP(wm, 64) + 2;
1199 return min_t(unsigned int, wm, USHRT_MAX);
1202 static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state,
1203 int level, enum plane_id plane_id, u16 value)
1205 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1208 for (; level < intel_wm_num_levels(dev_priv); level++) {
1209 struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1211 dirty |= raw->plane[plane_id] != value;
1212 raw->plane[plane_id] = value;
1218 static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state,
1219 int level, u16 value)
1221 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1224 /* NORMAL level doesn't have an FBC watermark */
1225 level = max(level, G4X_WM_LEVEL_SR);
1227 for (; level < intel_wm_num_levels(dev_priv); level++) {
1228 struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1230 dirty |= raw->fbc != value;
1237 static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state,
1238 const struct intel_plane_state *plane_state,
1241 static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state,
1242 const struct intel_plane_state *plane_state)
1244 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1245 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1246 int num_levels = intel_wm_num_levels(to_i915(plane->base.dev));
1247 enum plane_id plane_id = plane->id;
1251 if (!intel_wm_plane_visible(crtc_state, plane_state)) {
1252 dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0);
1253 if (plane_id == PLANE_PRIMARY)
1254 dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0);
1258 for (level = 0; level < num_levels; level++) {
1259 struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1262 wm = g4x_compute_wm(crtc_state, plane_state, level);
1263 max_wm = g4x_plane_fifo_size(plane_id, level);
1268 dirty |= raw->plane[plane_id] != wm;
1269 raw->plane[plane_id] = wm;
1271 if (plane_id != PLANE_PRIMARY ||
1272 level == G4X_WM_LEVEL_NORMAL)
1275 wm = ilk_compute_fbc_wm(crtc_state, plane_state,
1276 raw->plane[plane_id]);
1277 max_wm = g4x_fbc_fifo_size(level);
1280 * FBC wm is not mandatory as we
1281 * can always just disable its use.
1286 dirty |= raw->fbc != wm;
1290 /* mark watermarks as invalid */
1291 dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX);
1293 if (plane_id == PLANE_PRIMARY)
1294 dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX);
1298 drm_dbg_kms(&dev_priv->drm,
1299 "%s watermarks: normal=%d, SR=%d, HPLL=%d\n",
1301 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id],
1302 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id],
1303 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]);
1305 if (plane_id == PLANE_PRIMARY)
1306 drm_dbg_kms(&dev_priv->drm,
1307 "FBC watermarks: SR=%d, HPLL=%d\n",
1308 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc,
1309 crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc);
1315 static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state,
1316 enum plane_id plane_id, int level)
1318 const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1320 return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level);
1323 static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state,
1326 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1328 if (level > dev_priv->wm.max_level)
1331 return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) &&
1332 g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) &&
1333 g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level);
1336 /* mark all levels starting from 'level' as invalid */
1337 static void g4x_invalidate_wms(struct intel_crtc *crtc,
1338 struct g4x_wm_state *wm_state, int level)
1340 if (level <= G4X_WM_LEVEL_NORMAL) {
1341 enum plane_id plane_id;
1343 for_each_plane_id_on_crtc(crtc, plane_id)
1344 wm_state->wm.plane[plane_id] = USHRT_MAX;
1347 if (level <= G4X_WM_LEVEL_SR) {
1348 wm_state->cxsr = false;
1349 wm_state->sr.cursor = USHRT_MAX;
1350 wm_state->sr.plane = USHRT_MAX;
1351 wm_state->sr.fbc = USHRT_MAX;
1354 if (level <= G4X_WM_LEVEL_HPLL) {
1355 wm_state->hpll_en = false;
1356 wm_state->hpll.cursor = USHRT_MAX;
1357 wm_state->hpll.plane = USHRT_MAX;
1358 wm_state->hpll.fbc = USHRT_MAX;
1362 static bool g4x_compute_fbc_en(const struct g4x_wm_state *wm_state,
1365 if (level < G4X_WM_LEVEL_SR)
1368 if (level >= G4X_WM_LEVEL_SR &&
1369 wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR))
1372 if (level >= G4X_WM_LEVEL_HPLL &&
1373 wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL))
1379 static int g4x_compute_pipe_wm(struct intel_atomic_state *state,
1380 struct intel_crtc *crtc)
1382 struct intel_crtc_state *crtc_state =
1383 intel_atomic_get_new_crtc_state(state, crtc);
1384 struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal;
1385 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1386 const struct g4x_pipe_wm *raw;
1387 const struct intel_plane_state *old_plane_state;
1388 const struct intel_plane_state *new_plane_state;
1389 struct intel_plane *plane;
1390 enum plane_id plane_id;
1392 unsigned int dirty = 0;
1394 for_each_oldnew_intel_plane_in_state(state, plane,
1396 new_plane_state, i) {
1397 if (new_plane_state->hw.crtc != &crtc->base &&
1398 old_plane_state->hw.crtc != &crtc->base)
1401 if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state))
1402 dirty |= BIT(plane->id);
1408 level = G4X_WM_LEVEL_NORMAL;
1409 if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1412 raw = &crtc_state->wm.g4x.raw[level];
1413 for_each_plane_id_on_crtc(crtc, plane_id)
1414 wm_state->wm.plane[plane_id] = raw->plane[plane_id];
1416 level = G4X_WM_LEVEL_SR;
1417 if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1420 raw = &crtc_state->wm.g4x.raw[level];
1421 wm_state->sr.plane = raw->plane[PLANE_PRIMARY];
1422 wm_state->sr.cursor = raw->plane[PLANE_CURSOR];
1423 wm_state->sr.fbc = raw->fbc;
1425 wm_state->cxsr = active_planes == BIT(PLANE_PRIMARY);
1427 level = G4X_WM_LEVEL_HPLL;
1428 if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1431 raw = &crtc_state->wm.g4x.raw[level];
1432 wm_state->hpll.plane = raw->plane[PLANE_PRIMARY];
1433 wm_state->hpll.cursor = raw->plane[PLANE_CURSOR];
1434 wm_state->hpll.fbc = raw->fbc;
1436 wm_state->hpll_en = wm_state->cxsr;
1441 if (level == G4X_WM_LEVEL_NORMAL)
1444 /* invalidate the higher levels */
1445 g4x_invalidate_wms(crtc, wm_state, level);
1448 * Determine if the FBC watermark(s) can be used. IF
1449 * this isn't the case we prefer to disable the FBC
1450 * watermark(s) rather than disable the SR/HPLL
1451 * level(s) entirely. 'level-1' is the highest valid
1454 wm_state->fbc_en = g4x_compute_fbc_en(wm_state, level - 1);
1459 static int g4x_compute_intermediate_wm(struct intel_atomic_state *state,
1460 struct intel_crtc *crtc)
1462 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1463 struct intel_crtc_state *new_crtc_state =
1464 intel_atomic_get_new_crtc_state(state, crtc);
1465 const struct intel_crtc_state *old_crtc_state =
1466 intel_atomic_get_old_crtc_state(state, crtc);
1467 struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate;
1468 const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal;
1469 const struct g4x_wm_state *active = &old_crtc_state->wm.g4x.optimal;
1470 enum plane_id plane_id;
1472 if (!new_crtc_state->hw.active ||
1473 drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) {
1474 *intermediate = *optimal;
1476 intermediate->cxsr = false;
1477 intermediate->hpll_en = false;
1481 intermediate->cxsr = optimal->cxsr && active->cxsr &&
1482 !new_crtc_state->disable_cxsr;
1483 intermediate->hpll_en = optimal->hpll_en && active->hpll_en &&
1484 !new_crtc_state->disable_cxsr;
1485 intermediate->fbc_en = optimal->fbc_en && active->fbc_en;
1487 for_each_plane_id_on_crtc(crtc, plane_id) {
1488 intermediate->wm.plane[plane_id] =
1489 max(optimal->wm.plane[plane_id],
1490 active->wm.plane[plane_id]);
1492 drm_WARN_ON(&dev_priv->drm, intermediate->wm.plane[plane_id] >
1493 g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL));
1496 intermediate->sr.plane = max(optimal->sr.plane,
1498 intermediate->sr.cursor = max(optimal->sr.cursor,
1500 intermediate->sr.fbc = max(optimal->sr.fbc,
1503 intermediate->hpll.plane = max(optimal->hpll.plane,
1504 active->hpll.plane);
1505 intermediate->hpll.cursor = max(optimal->hpll.cursor,
1506 active->hpll.cursor);
1507 intermediate->hpll.fbc = max(optimal->hpll.fbc,
1510 drm_WARN_ON(&dev_priv->drm,
1511 (intermediate->sr.plane >
1512 g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) ||
1513 intermediate->sr.cursor >
1514 g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) &&
1515 intermediate->cxsr);
1516 drm_WARN_ON(&dev_priv->drm,
1517 (intermediate->sr.plane >
1518 g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) ||
1519 intermediate->sr.cursor >
1520 g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) &&
1521 intermediate->hpll_en);
1523 drm_WARN_ON(&dev_priv->drm,
1524 intermediate->sr.fbc > g4x_fbc_fifo_size(1) &&
1525 intermediate->fbc_en && intermediate->cxsr);
1526 drm_WARN_ON(&dev_priv->drm,
1527 intermediate->hpll.fbc > g4x_fbc_fifo_size(2) &&
1528 intermediate->fbc_en && intermediate->hpll_en);
1532 * If our intermediate WM are identical to the final WM, then we can
1533 * omit the post-vblank programming; only update if it's different.
1535 if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0)
1536 new_crtc_state->wm.need_postvbl_update = true;
1541 static void g4x_merge_wm(struct drm_i915_private *dev_priv,
1542 struct g4x_wm_values *wm)
1544 struct intel_crtc *crtc;
1545 int num_active_pipes = 0;
1551 for_each_intel_crtc(&dev_priv->drm, crtc) {
1552 const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x;
1557 if (!wm_state->cxsr)
1559 if (!wm_state->hpll_en)
1560 wm->hpll_en = false;
1561 if (!wm_state->fbc_en)
1567 if (num_active_pipes != 1) {
1569 wm->hpll_en = false;
1573 for_each_intel_crtc(&dev_priv->drm, crtc) {
1574 const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x;
1575 enum pipe pipe = crtc->pipe;
1577 wm->pipe[pipe] = wm_state->wm;
1578 if (crtc->active && wm->cxsr)
1579 wm->sr = wm_state->sr;
1580 if (crtc->active && wm->hpll_en)
1581 wm->hpll = wm_state->hpll;
1585 static void g4x_program_watermarks(struct drm_i915_private *dev_priv)
1587 struct g4x_wm_values *old_wm = &dev_priv->wm.g4x;
1588 struct g4x_wm_values new_wm = {};
1590 g4x_merge_wm(dev_priv, &new_wm);
1592 if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0)
1595 if (is_disabling(old_wm->cxsr, new_wm.cxsr, true))
1596 _intel_set_memory_cxsr(dev_priv, false);
1598 g4x_write_wm_values(dev_priv, &new_wm);
1600 if (is_enabling(old_wm->cxsr, new_wm.cxsr, true))
1601 _intel_set_memory_cxsr(dev_priv, true);
1606 static void g4x_initial_watermarks(struct intel_atomic_state *state,
1607 struct intel_crtc *crtc)
1609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1610 const struct intel_crtc_state *crtc_state =
1611 intel_atomic_get_new_crtc_state(state, crtc);
1613 mutex_lock(&dev_priv->wm.wm_mutex);
1614 crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate;
1615 g4x_program_watermarks(dev_priv);
1616 mutex_unlock(&dev_priv->wm.wm_mutex);
1619 static void g4x_optimize_watermarks(struct intel_atomic_state *state,
1620 struct intel_crtc *crtc)
1622 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1623 const struct intel_crtc_state *crtc_state =
1624 intel_atomic_get_new_crtc_state(state, crtc);
1626 if (!crtc_state->wm.need_postvbl_update)
1629 mutex_lock(&dev_priv->wm.wm_mutex);
1630 crtc->wm.active.g4x = crtc_state->wm.g4x.optimal;
1631 g4x_program_watermarks(dev_priv);
1632 mutex_unlock(&dev_priv->wm.wm_mutex);
1635 /* latency must be in 0.1us units. */
1636 static unsigned int vlv_wm_method2(unsigned int pixel_rate,
1637 unsigned int htotal,
1640 unsigned int latency)
1644 ret = intel_wm_method2(pixel_rate, htotal,
1645 width, cpp, latency);
1646 ret = DIV_ROUND_UP(ret, 64);
1651 static void vlv_setup_wm_latency(struct drm_i915_private *dev_priv)
1653 /* all latencies in usec */
1654 dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3;
1656 dev_priv->wm.max_level = VLV_WM_LEVEL_PM2;
1658 if (IS_CHERRYVIEW(dev_priv)) {
1659 dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12;
1660 dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33;
1662 dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS;
1666 static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state,
1667 const struct intel_plane_state *plane_state,
1670 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1671 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1672 const struct drm_display_mode *pipe_mode =
1673 &crtc_state->hw.pipe_mode;
1674 unsigned int pixel_rate, htotal, cpp, width, wm;
1676 if (dev_priv->wm.pri_latency[level] == 0)
1679 if (!intel_wm_plane_visible(crtc_state, plane_state))
1682 cpp = plane_state->hw.fb->format->cpp[0];
1683 pixel_rate = crtc_state->pixel_rate;
1684 htotal = pipe_mode->crtc_htotal;
1685 width = drm_rect_width(&plane_state->uapi.src) >> 16;
1687 if (plane->id == PLANE_CURSOR) {
1689 * FIXME the formula gives values that are
1690 * too big for the cursor FIFO, and hence we
1691 * would never be able to use cursors. For
1692 * now just hardcode the watermark.
1696 wm = vlv_wm_method2(pixel_rate, htotal, width, cpp,
1697 dev_priv->wm.pri_latency[level] * 10);
1700 return min_t(unsigned int, wm, USHRT_MAX);
1703 static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes)
1705 return (active_planes & (BIT(PLANE_SPRITE0) |
1706 BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1);
1709 static int vlv_compute_fifo(struct intel_crtc_state *crtc_state)
1711 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1712 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1713 const struct g4x_pipe_wm *raw =
1714 &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2];
1715 struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state;
1716 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1717 int num_active_planes = hweight8(active_planes);
1718 const int fifo_size = 511;
1719 int fifo_extra, fifo_left = fifo_size;
1720 int sprite0_fifo_extra = 0;
1721 unsigned int total_rate;
1722 enum plane_id plane_id;
1725 * When enabling sprite0 after sprite1 has already been enabled
1726 * we tend to get an underrun unless sprite0 already has some
1727 * FIFO space allcoated. Hence we always allocate at least one
1728 * cacheline for sprite0 whenever sprite1 is enabled.
1730 * All other plane enable sequences appear immune to this problem.
1732 if (vlv_need_sprite0_fifo_workaround(active_planes))
1733 sprite0_fifo_extra = 1;
1735 total_rate = raw->plane[PLANE_PRIMARY] +
1736 raw->plane[PLANE_SPRITE0] +
1737 raw->plane[PLANE_SPRITE1] +
1740 if (total_rate > fifo_size)
1743 if (total_rate == 0)
1746 for_each_plane_id_on_crtc(crtc, plane_id) {
1749 if ((active_planes & BIT(plane_id)) == 0) {
1750 fifo_state->plane[plane_id] = 0;
1754 rate = raw->plane[plane_id];
1755 fifo_state->plane[plane_id] = fifo_size * rate / total_rate;
1756 fifo_left -= fifo_state->plane[plane_id];
1759 fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra;
1760 fifo_left -= sprite0_fifo_extra;
1762 fifo_state->plane[PLANE_CURSOR] = 63;
1764 fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1);
1766 /* spread the remainder evenly */
1767 for_each_plane_id_on_crtc(crtc, plane_id) {
1773 if ((active_planes & BIT(plane_id)) == 0)
1776 plane_extra = min(fifo_extra, fifo_left);
1777 fifo_state->plane[plane_id] += plane_extra;
1778 fifo_left -= plane_extra;
1781 drm_WARN_ON(&dev_priv->drm, active_planes != 0 && fifo_left != 0);
1783 /* give it all to the first plane if none are active */
1784 if (active_planes == 0) {
1785 drm_WARN_ON(&dev_priv->drm, fifo_left != fifo_size);
1786 fifo_state->plane[PLANE_PRIMARY] = fifo_left;
1792 /* mark all levels starting from 'level' as invalid */
1793 static void vlv_invalidate_wms(struct intel_crtc *crtc,
1794 struct vlv_wm_state *wm_state, int level)
1796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1798 for (; level < intel_wm_num_levels(dev_priv); level++) {
1799 enum plane_id plane_id;
1801 for_each_plane_id_on_crtc(crtc, plane_id)
1802 wm_state->wm[level].plane[plane_id] = USHRT_MAX;
1804 wm_state->sr[level].cursor = USHRT_MAX;
1805 wm_state->sr[level].plane = USHRT_MAX;
1809 static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size)
1814 return fifo_size - wm;
1818 * Starting from 'level' set all higher
1819 * levels to 'value' in the "raw" watermarks.
1821 static bool vlv_raw_plane_wm_set(struct intel_crtc_state *crtc_state,
1822 int level, enum plane_id plane_id, u16 value)
1824 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1825 int num_levels = intel_wm_num_levels(dev_priv);
1828 for (; level < num_levels; level++) {
1829 struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
1831 dirty |= raw->plane[plane_id] != value;
1832 raw->plane[plane_id] = value;
1838 static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state,
1839 const struct intel_plane_state *plane_state)
1841 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1842 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1843 enum plane_id plane_id = plane->id;
1844 int num_levels = intel_wm_num_levels(to_i915(plane->base.dev));
1848 if (!intel_wm_plane_visible(crtc_state, plane_state)) {
1849 dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0);
1853 for (level = 0; level < num_levels; level++) {
1854 struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
1855 int wm = vlv_compute_wm_level(crtc_state, plane_state, level);
1856 int max_wm = plane_id == PLANE_CURSOR ? 63 : 511;
1861 dirty |= raw->plane[plane_id] != wm;
1862 raw->plane[plane_id] = wm;
1865 /* mark all higher levels as invalid */
1866 dirty |= vlv_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX);
1870 drm_dbg_kms(&dev_priv->drm,
1871 "%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n",
1873 crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id],
1874 crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id],
1875 crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]);
1880 static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state,
1881 enum plane_id plane_id, int level)
1883 const struct g4x_pipe_wm *raw =
1884 &crtc_state->wm.vlv.raw[level];
1885 const struct vlv_fifo_state *fifo_state =
1886 &crtc_state->wm.vlv.fifo_state;
1888 return raw->plane[plane_id] <= fifo_state->plane[plane_id];
1891 static bool vlv_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, int level)
1893 return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) &&
1894 vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) &&
1895 vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) &&
1896 vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level);
1899 static int vlv_compute_pipe_wm(struct intel_atomic_state *state,
1900 struct intel_crtc *crtc)
1902 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1903 struct intel_crtc_state *crtc_state =
1904 intel_atomic_get_new_crtc_state(state, crtc);
1905 struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal;
1906 const struct vlv_fifo_state *fifo_state =
1907 &crtc_state->wm.vlv.fifo_state;
1908 u8 active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1909 int num_active_planes = hweight8(active_planes);
1910 bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->uapi);
1911 const struct intel_plane_state *old_plane_state;
1912 const struct intel_plane_state *new_plane_state;
1913 struct intel_plane *plane;
1914 enum plane_id plane_id;
1916 unsigned int dirty = 0;
1918 for_each_oldnew_intel_plane_in_state(state, plane,
1920 new_plane_state, i) {
1921 if (new_plane_state->hw.crtc != &crtc->base &&
1922 old_plane_state->hw.crtc != &crtc->base)
1925 if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state))
1926 dirty |= BIT(plane->id);
1930 * DSPARB registers may have been reset due to the
1931 * power well being turned off. Make sure we restore
1932 * them to a consistent state even if no primary/sprite
1933 * planes are initially active.
1936 crtc_state->fifo_changed = true;
1941 /* cursor changes don't warrant a FIFO recompute */
1942 if (dirty & ~BIT(PLANE_CURSOR)) {
1943 const struct intel_crtc_state *old_crtc_state =
1944 intel_atomic_get_old_crtc_state(state, crtc);
1945 const struct vlv_fifo_state *old_fifo_state =
1946 &old_crtc_state->wm.vlv.fifo_state;
1948 ret = vlv_compute_fifo(crtc_state);
1952 if (needs_modeset ||
1953 memcmp(old_fifo_state, fifo_state,
1954 sizeof(*fifo_state)) != 0)
1955 crtc_state->fifo_changed = true;
1958 /* initially allow all levels */
1959 wm_state->num_levels = intel_wm_num_levels(dev_priv);
1961 * Note that enabling cxsr with no primary/sprite planes
1962 * enabled can wedge the pipe. Hence we only allow cxsr
1963 * with exactly one enabled primary/sprite plane.
1965 wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1;
1967 for (level = 0; level < wm_state->num_levels; level++) {
1968 const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
1969 const int sr_fifo_size = INTEL_NUM_PIPES(dev_priv) * 512 - 1;
1971 if (!vlv_raw_crtc_wm_is_valid(crtc_state, level))
1974 for_each_plane_id_on_crtc(crtc, plane_id) {
1975 wm_state->wm[level].plane[plane_id] =
1976 vlv_invert_wm_value(raw->plane[plane_id],
1977 fifo_state->plane[plane_id]);
1980 wm_state->sr[level].plane =
1981 vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY],
1982 raw->plane[PLANE_SPRITE0],
1983 raw->plane[PLANE_SPRITE1]),
1986 wm_state->sr[level].cursor =
1987 vlv_invert_wm_value(raw->plane[PLANE_CURSOR],
1994 /* limit to only levels we can actually handle */
1995 wm_state->num_levels = level;
1997 /* invalidate the higher levels */
1998 vlv_invalidate_wms(crtc, wm_state, level);
2003 #define VLV_FIFO(plane, value) \
2004 (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV)
2006 static void vlv_atomic_update_fifo(struct intel_atomic_state *state,
2007 struct intel_crtc *crtc)
2009 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2010 struct intel_uncore *uncore = &dev_priv->uncore;
2011 const struct intel_crtc_state *crtc_state =
2012 intel_atomic_get_new_crtc_state(state, crtc);
2013 const struct vlv_fifo_state *fifo_state =
2014 &crtc_state->wm.vlv.fifo_state;
2015 int sprite0_start, sprite1_start, fifo_size;
2016 u32 dsparb, dsparb2, dsparb3;
2018 if (!crtc_state->fifo_changed)
2021 sprite0_start = fifo_state->plane[PLANE_PRIMARY];
2022 sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start;
2023 fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start;
2025 drm_WARN_ON(&dev_priv->drm, fifo_state->plane[PLANE_CURSOR] != 63);
2026 drm_WARN_ON(&dev_priv->drm, fifo_size != 511);
2028 trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size);
2031 * uncore.lock serves a double purpose here. It allows us to
2032 * use the less expensive I915_{READ,WRITE}_FW() functions, and
2033 * it protects the DSPARB registers from getting clobbered by
2034 * parallel updates from multiple pipes.
2036 * intel_pipe_update_start() has already disabled interrupts
2037 * for us, so a plain spin_lock() is sufficient here.
2039 spin_lock(&uncore->lock);
2041 switch (crtc->pipe) {
2043 dsparb = intel_uncore_read_fw(uncore, DSPARB);
2044 dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
2046 dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) |
2047 VLV_FIFO(SPRITEB, 0xff));
2048 dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) |
2049 VLV_FIFO(SPRITEB, sprite1_start));
2051 dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) |
2052 VLV_FIFO(SPRITEB_HI, 0x1));
2053 dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) |
2054 VLV_FIFO(SPRITEB_HI, sprite1_start >> 8));
2056 intel_uncore_write_fw(uncore, DSPARB, dsparb);
2057 intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
2060 dsparb = intel_uncore_read_fw(uncore, DSPARB);
2061 dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
2063 dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) |
2064 VLV_FIFO(SPRITED, 0xff));
2065 dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) |
2066 VLV_FIFO(SPRITED, sprite1_start));
2068 dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) |
2069 VLV_FIFO(SPRITED_HI, 0xff));
2070 dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) |
2071 VLV_FIFO(SPRITED_HI, sprite1_start >> 8));
2073 intel_uncore_write_fw(uncore, DSPARB, dsparb);
2074 intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
2077 dsparb3 = intel_uncore_read_fw(uncore, DSPARB3);
2078 dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
2080 dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) |
2081 VLV_FIFO(SPRITEF, 0xff));
2082 dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) |
2083 VLV_FIFO(SPRITEF, sprite1_start));
2085 dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) |
2086 VLV_FIFO(SPRITEF_HI, 0xff));
2087 dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) |
2088 VLV_FIFO(SPRITEF_HI, sprite1_start >> 8));
2090 intel_uncore_write_fw(uncore, DSPARB3, dsparb3);
2091 intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
2097 intel_uncore_posting_read_fw(uncore, DSPARB);
2099 spin_unlock(&uncore->lock);
2104 static int vlv_compute_intermediate_wm(struct intel_atomic_state *state,
2105 struct intel_crtc *crtc)
2107 struct intel_crtc_state *new_crtc_state =
2108 intel_atomic_get_new_crtc_state(state, crtc);
2109 const struct intel_crtc_state *old_crtc_state =
2110 intel_atomic_get_old_crtc_state(state, crtc);
2111 struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate;
2112 const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal;
2113 const struct vlv_wm_state *active = &old_crtc_state->wm.vlv.optimal;
2116 if (!new_crtc_state->hw.active ||
2117 drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) {
2118 *intermediate = *optimal;
2120 intermediate->cxsr = false;
2124 intermediate->num_levels = min(optimal->num_levels, active->num_levels);
2125 intermediate->cxsr = optimal->cxsr && active->cxsr &&
2126 !new_crtc_state->disable_cxsr;
2128 for (level = 0; level < intermediate->num_levels; level++) {
2129 enum plane_id plane_id;
2131 for_each_plane_id_on_crtc(crtc, plane_id) {
2132 intermediate->wm[level].plane[plane_id] =
2133 min(optimal->wm[level].plane[plane_id],
2134 active->wm[level].plane[plane_id]);
2137 intermediate->sr[level].plane = min(optimal->sr[level].plane,
2138 active->sr[level].plane);
2139 intermediate->sr[level].cursor = min(optimal->sr[level].cursor,
2140 active->sr[level].cursor);
2143 vlv_invalidate_wms(crtc, intermediate, level);
2147 * If our intermediate WM are identical to the final WM, then we can
2148 * omit the post-vblank programming; only update if it's different.
2150 if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0)
2151 new_crtc_state->wm.need_postvbl_update = true;
2156 static void vlv_merge_wm(struct drm_i915_private *dev_priv,
2157 struct vlv_wm_values *wm)
2159 struct intel_crtc *crtc;
2160 int num_active_pipes = 0;
2162 wm->level = dev_priv->wm.max_level;
2165 for_each_intel_crtc(&dev_priv->drm, crtc) {
2166 const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv;
2171 if (!wm_state->cxsr)
2175 wm->level = min_t(int, wm->level, wm_state->num_levels - 1);
2178 if (num_active_pipes != 1)
2181 if (num_active_pipes > 1)
2182 wm->level = VLV_WM_LEVEL_PM2;
2184 for_each_intel_crtc(&dev_priv->drm, crtc) {
2185 const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv;
2186 enum pipe pipe = crtc->pipe;
2188 wm->pipe[pipe] = wm_state->wm[wm->level];
2189 if (crtc->active && wm->cxsr)
2190 wm->sr = wm_state->sr[wm->level];
2192 wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2;
2193 wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2;
2194 wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2;
2195 wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2;
2199 static void vlv_program_watermarks(struct drm_i915_private *dev_priv)
2201 struct vlv_wm_values *old_wm = &dev_priv->wm.vlv;
2202 struct vlv_wm_values new_wm = {};
2204 vlv_merge_wm(dev_priv, &new_wm);
2206 if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0)
2209 if (is_disabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_DDR_DVFS))
2210 chv_set_memory_dvfs(dev_priv, false);
2212 if (is_disabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_PM5))
2213 chv_set_memory_pm5(dev_priv, false);
2215 if (is_disabling(old_wm->cxsr, new_wm.cxsr, true))
2216 _intel_set_memory_cxsr(dev_priv, false);
2218 vlv_write_wm_values(dev_priv, &new_wm);
2220 if (is_enabling(old_wm->cxsr, new_wm.cxsr, true))
2221 _intel_set_memory_cxsr(dev_priv, true);
2223 if (is_enabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_PM5))
2224 chv_set_memory_pm5(dev_priv, true);
2226 if (is_enabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_DDR_DVFS))
2227 chv_set_memory_dvfs(dev_priv, true);
2232 static void vlv_initial_watermarks(struct intel_atomic_state *state,
2233 struct intel_crtc *crtc)
2235 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2236 const struct intel_crtc_state *crtc_state =
2237 intel_atomic_get_new_crtc_state(state, crtc);
2239 mutex_lock(&dev_priv->wm.wm_mutex);
2240 crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate;
2241 vlv_program_watermarks(dev_priv);
2242 mutex_unlock(&dev_priv->wm.wm_mutex);
2245 static void vlv_optimize_watermarks(struct intel_atomic_state *state,
2246 struct intel_crtc *crtc)
2248 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2249 const struct intel_crtc_state *crtc_state =
2250 intel_atomic_get_new_crtc_state(state, crtc);
2252 if (!crtc_state->wm.need_postvbl_update)
2255 mutex_lock(&dev_priv->wm.wm_mutex);
2256 crtc->wm.active.vlv = crtc_state->wm.vlv.optimal;
2257 vlv_program_watermarks(dev_priv);
2258 mutex_unlock(&dev_priv->wm.wm_mutex);
2261 static void i965_update_wm(struct drm_i915_private *dev_priv)
2263 struct intel_crtc *crtc;
2268 /* Calc sr entries for one plane configs */
2269 crtc = single_enabled_crtc(dev_priv);
2271 /* self-refresh has much higher latency */
2272 static const int sr_latency_ns = 12000;
2273 const struct drm_display_mode *pipe_mode =
2274 &crtc->config->hw.pipe_mode;
2275 const struct drm_framebuffer *fb =
2276 crtc->base.primary->state->fb;
2277 int pixel_rate = crtc->config->pixel_rate;
2278 int htotal = pipe_mode->crtc_htotal;
2279 int width = drm_rect_width(&crtc->base.primary->state->src) >> 16;
2280 int cpp = fb->format->cpp[0];
2283 entries = intel_wm_method2(pixel_rate, htotal,
2284 width, cpp, sr_latency_ns / 100);
2285 entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
2286 srwm = I965_FIFO_SIZE - entries;
2290 drm_dbg_kms(&dev_priv->drm,
2291 "self-refresh entries: %d, wm: %d\n",
2294 entries = intel_wm_method2(pixel_rate, htotal,
2295 crtc->base.cursor->state->crtc_w, 4,
2296 sr_latency_ns / 100);
2297 entries = DIV_ROUND_UP(entries,
2298 i965_cursor_wm_info.cacheline_size) +
2299 i965_cursor_wm_info.guard_size;
2301 cursor_sr = i965_cursor_wm_info.fifo_size - entries;
2302 if (cursor_sr > i965_cursor_wm_info.max_wm)
2303 cursor_sr = i965_cursor_wm_info.max_wm;
2305 drm_dbg_kms(&dev_priv->drm,
2306 "self-refresh watermark: display plane %d "
2307 "cursor %d\n", srwm, cursor_sr);
2309 cxsr_enabled = true;
2311 cxsr_enabled = false;
2312 /* Turn off self refresh if both pipes are enabled */
2313 intel_set_memory_cxsr(dev_priv, false);
2316 drm_dbg_kms(&dev_priv->drm,
2317 "Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
2320 /* 965 has limitations... */
2321 intel_uncore_write(&dev_priv->uncore, DSPFW1, FW_WM(srwm, SR) |
2325 intel_uncore_write(&dev_priv->uncore, DSPFW2, FW_WM(8, CURSORA) |
2326 FW_WM(8, PLANEC_OLD));
2327 /* update cursor SR watermark */
2328 intel_uncore_write(&dev_priv->uncore, DSPFW3, FW_WM(cursor_sr, CURSOR_SR));
2331 intel_set_memory_cxsr(dev_priv, true);
2336 static struct intel_crtc *intel_crtc_for_plane(struct drm_i915_private *i915,
2337 enum i9xx_plane_id i9xx_plane)
2339 struct intel_plane *plane;
2341 for_each_intel_plane(&i915->drm, plane) {
2342 if (plane->id == PLANE_PRIMARY &&
2343 plane->i9xx_plane == i9xx_plane)
2344 return intel_crtc_for_pipe(i915, plane->pipe);
2350 static void i9xx_update_wm(struct drm_i915_private *dev_priv)
2352 const struct intel_watermark_params *wm_info;
2357 int planea_wm, planeb_wm;
2358 struct intel_crtc *crtc;
2360 if (IS_I945GM(dev_priv))
2361 wm_info = &i945_wm_info;
2362 else if (DISPLAY_VER(dev_priv) != 2)
2363 wm_info = &i915_wm_info;
2365 wm_info = &i830_a_wm_info;
2367 if (DISPLAY_VER(dev_priv) == 2)
2368 fifo_size = i830_get_fifo_size(dev_priv, PLANE_A);
2370 fifo_size = i9xx_get_fifo_size(dev_priv, PLANE_A);
2371 crtc = intel_crtc_for_plane(dev_priv, PLANE_A);
2372 if (intel_crtc_active(crtc)) {
2373 const struct drm_framebuffer *fb =
2374 crtc->base.primary->state->fb;
2377 if (DISPLAY_VER(dev_priv) == 2)
2380 cpp = fb->format->cpp[0];
2382 planea_wm = intel_calculate_wm(crtc->config->pixel_rate,
2383 wm_info, fifo_size, cpp,
2384 pessimal_latency_ns);
2386 planea_wm = fifo_size - wm_info->guard_size;
2387 if (planea_wm > (long)wm_info->max_wm)
2388 planea_wm = wm_info->max_wm;
2391 if (DISPLAY_VER(dev_priv) == 2)
2392 wm_info = &i830_bc_wm_info;
2394 if (DISPLAY_VER(dev_priv) == 2)
2395 fifo_size = i830_get_fifo_size(dev_priv, PLANE_B);
2397 fifo_size = i9xx_get_fifo_size(dev_priv, PLANE_B);
2398 crtc = intel_crtc_for_plane(dev_priv, PLANE_B);
2399 if (intel_crtc_active(crtc)) {
2400 const struct drm_framebuffer *fb =
2401 crtc->base.primary->state->fb;
2404 if (DISPLAY_VER(dev_priv) == 2)
2407 cpp = fb->format->cpp[0];
2409 planeb_wm = intel_calculate_wm(crtc->config->pixel_rate,
2410 wm_info, fifo_size, cpp,
2411 pessimal_latency_ns);
2413 planeb_wm = fifo_size - wm_info->guard_size;
2414 if (planeb_wm > (long)wm_info->max_wm)
2415 planeb_wm = wm_info->max_wm;
2418 drm_dbg_kms(&dev_priv->drm,
2419 "FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
2421 crtc = single_enabled_crtc(dev_priv);
2422 if (IS_I915GM(dev_priv) && crtc) {
2423 struct drm_i915_gem_object *obj;
2425 obj = intel_fb_obj(crtc->base.primary->state->fb);
2427 /* self-refresh seems busted with untiled */
2428 if (!i915_gem_object_is_tiled(obj))
2433 * Overlay gets an aggressive default since video jitter is bad.
2437 /* Play safe and disable self-refresh before adjusting watermarks. */
2438 intel_set_memory_cxsr(dev_priv, false);
2440 /* Calc sr entries for one plane configs */
2441 if (HAS_FW_BLC(dev_priv) && crtc) {
2442 /* self-refresh has much higher latency */
2443 static const int sr_latency_ns = 6000;
2444 const struct drm_display_mode *pipe_mode =
2445 &crtc->config->hw.pipe_mode;
2446 const struct drm_framebuffer *fb =
2447 crtc->base.primary->state->fb;
2448 int pixel_rate = crtc->config->pixel_rate;
2449 int htotal = pipe_mode->crtc_htotal;
2450 int width = drm_rect_width(&crtc->base.primary->state->src) >> 16;
2454 if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv))
2457 cpp = fb->format->cpp[0];
2459 entries = intel_wm_method2(pixel_rate, htotal, width, cpp,
2460 sr_latency_ns / 100);
2461 entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
2462 drm_dbg_kms(&dev_priv->drm,
2463 "self-refresh entries: %d\n", entries);
2464 srwm = wm_info->fifo_size - entries;
2468 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv))
2469 intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF,
2470 FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
2472 intel_uncore_write(&dev_priv->uncore, FW_BLC_SELF, srwm & 0x3f);
2475 drm_dbg_kms(&dev_priv->drm,
2476 "Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
2477 planea_wm, planeb_wm, cwm, srwm);
2479 fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
2480 fwater_hi = (cwm & 0x1f);
2482 /* Set request length to 8 cachelines per fetch */
2483 fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
2484 fwater_hi = fwater_hi | (1 << 8);
2486 intel_uncore_write(&dev_priv->uncore, FW_BLC, fwater_lo);
2487 intel_uncore_write(&dev_priv->uncore, FW_BLC2, fwater_hi);
2490 intel_set_memory_cxsr(dev_priv, true);
2493 static void i845_update_wm(struct drm_i915_private *dev_priv)
2495 struct intel_crtc *crtc;
2499 crtc = single_enabled_crtc(dev_priv);
2503 planea_wm = intel_calculate_wm(crtc->config->pixel_rate,
2505 i845_get_fifo_size(dev_priv, PLANE_A),
2506 4, pessimal_latency_ns);
2507 fwater_lo = intel_uncore_read(&dev_priv->uncore, FW_BLC) & ~0xfff;
2508 fwater_lo |= (3<<8) | planea_wm;
2510 drm_dbg_kms(&dev_priv->drm,
2511 "Setting FIFO watermarks - A: %d\n", planea_wm);
2513 intel_uncore_write(&dev_priv->uncore, FW_BLC, fwater_lo);
2516 /* latency must be in 0.1us units. */
2517 static unsigned int ilk_wm_method1(unsigned int pixel_rate,
2519 unsigned int latency)
2523 ret = intel_wm_method1(pixel_rate, cpp, latency);
2524 ret = DIV_ROUND_UP(ret, 64) + 2;
2529 /* latency must be in 0.1us units. */
2530 static unsigned int ilk_wm_method2(unsigned int pixel_rate,
2531 unsigned int htotal,
2534 unsigned int latency)
2538 ret = intel_wm_method2(pixel_rate, htotal,
2539 width, cpp, latency);
2540 ret = DIV_ROUND_UP(ret, 64) + 2;
2545 static u32 ilk_wm_fbc(u32 pri_val, u32 horiz_pixels, u8 cpp)
2548 * Neither of these should be possible since this function shouldn't be
2549 * called if the CRTC is off or the plane is invisible. But let's be
2550 * extra paranoid to avoid a potential divide-by-zero if we screw up
2551 * elsewhere in the driver.
2555 if (WARN_ON(!horiz_pixels))
2558 return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2;
2561 struct ilk_wm_maximums {
2569 * For both WM_PIPE and WM_LP.
2570 * mem_value must be in 0.1us units.
2572 static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state,
2573 const struct intel_plane_state *plane_state,
2574 u32 mem_value, bool is_lp)
2576 u32 method1, method2;
2582 if (!intel_wm_plane_visible(crtc_state, plane_state))
2585 cpp = plane_state->hw.fb->format->cpp[0];
2587 method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value);
2592 method2 = ilk_wm_method2(crtc_state->pixel_rate,
2593 crtc_state->hw.pipe_mode.crtc_htotal,
2594 drm_rect_width(&plane_state->uapi.src) >> 16,
2597 return min(method1, method2);
2601 * For both WM_PIPE and WM_LP.
2602 * mem_value must be in 0.1us units.
2604 static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state,
2605 const struct intel_plane_state *plane_state,
2608 u32 method1, method2;
2614 if (!intel_wm_plane_visible(crtc_state, plane_state))
2617 cpp = plane_state->hw.fb->format->cpp[0];
2619 method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value);
2620 method2 = ilk_wm_method2(crtc_state->pixel_rate,
2621 crtc_state->hw.pipe_mode.crtc_htotal,
2622 drm_rect_width(&plane_state->uapi.src) >> 16,
2624 return min(method1, method2);
2628 * For both WM_PIPE and WM_LP.
2629 * mem_value must be in 0.1us units.
2631 static u32 ilk_compute_cur_wm(const struct intel_crtc_state *crtc_state,
2632 const struct intel_plane_state *plane_state,
2640 if (!intel_wm_plane_visible(crtc_state, plane_state))
2643 cpp = plane_state->hw.fb->format->cpp[0];
2645 return ilk_wm_method2(crtc_state->pixel_rate,
2646 crtc_state->hw.pipe_mode.crtc_htotal,
2647 drm_rect_width(&plane_state->uapi.src) >> 16,
2651 /* Only for WM_LP. */
2652 static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state,
2653 const struct intel_plane_state *plane_state,
2658 if (!intel_wm_plane_visible(crtc_state, plane_state))
2661 cpp = plane_state->hw.fb->format->cpp[0];
2663 return ilk_wm_fbc(pri_val, drm_rect_width(&plane_state->uapi.src) >> 16,
2668 ilk_display_fifo_size(const struct drm_i915_private *dev_priv)
2670 if (DISPLAY_VER(dev_priv) >= 8)
2672 else if (DISPLAY_VER(dev_priv) >= 7)
2679 ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv,
2680 int level, bool is_sprite)
2682 if (DISPLAY_VER(dev_priv) >= 8)
2683 /* BDW primary/sprite plane watermarks */
2684 return level == 0 ? 255 : 2047;
2685 else if (DISPLAY_VER(dev_priv) >= 7)
2686 /* IVB/HSW primary/sprite plane watermarks */
2687 return level == 0 ? 127 : 1023;
2688 else if (!is_sprite)
2689 /* ILK/SNB primary plane watermarks */
2690 return level == 0 ? 127 : 511;
2692 /* ILK/SNB sprite plane watermarks */
2693 return level == 0 ? 63 : 255;
2697 ilk_cursor_wm_reg_max(const struct drm_i915_private *dev_priv, int level)
2699 if (DISPLAY_VER(dev_priv) >= 7)
2700 return level == 0 ? 63 : 255;
2702 return level == 0 ? 31 : 63;
2705 static unsigned int ilk_fbc_wm_reg_max(const struct drm_i915_private *dev_priv)
2707 if (DISPLAY_VER(dev_priv) >= 8)
2713 /* Calculate the maximum primary/sprite plane watermark */
2714 static unsigned int ilk_plane_wm_max(const struct drm_i915_private *dev_priv,
2716 const struct intel_wm_config *config,
2717 enum intel_ddb_partitioning ddb_partitioning,
2720 unsigned int fifo_size = ilk_display_fifo_size(dev_priv);
2722 /* if sprites aren't enabled, sprites get nothing */
2723 if (is_sprite && !config->sprites_enabled)
2726 /* HSW allows LP1+ watermarks even with multiple pipes */
2727 if (level == 0 || config->num_pipes_active > 1) {
2728 fifo_size /= INTEL_NUM_PIPES(dev_priv);
2731 * For some reason the non self refresh
2732 * FIFO size is only half of the self
2733 * refresh FIFO size on ILK/SNB.
2735 if (DISPLAY_VER(dev_priv) <= 6)
2739 if (config->sprites_enabled) {
2740 /* level 0 is always calculated with 1:1 split */
2741 if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) {
2750 /* clamp to max that the registers can hold */
2751 return min(fifo_size, ilk_plane_wm_reg_max(dev_priv, level, is_sprite));
2754 /* Calculate the maximum cursor plane watermark */
2755 static unsigned int ilk_cursor_wm_max(const struct drm_i915_private *dev_priv,
2757 const struct intel_wm_config *config)
2759 /* HSW LP1+ watermarks w/ multiple pipes */
2760 if (level > 0 && config->num_pipes_active > 1)
2763 /* otherwise just report max that registers can hold */
2764 return ilk_cursor_wm_reg_max(dev_priv, level);
2767 static void ilk_compute_wm_maximums(const struct drm_i915_private *dev_priv,
2769 const struct intel_wm_config *config,
2770 enum intel_ddb_partitioning ddb_partitioning,
2771 struct ilk_wm_maximums *max)
2773 max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false);
2774 max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true);
2775 max->cur = ilk_cursor_wm_max(dev_priv, level, config);
2776 max->fbc = ilk_fbc_wm_reg_max(dev_priv);
2779 static void ilk_compute_wm_reg_maximums(const struct drm_i915_private *dev_priv,
2781 struct ilk_wm_maximums *max)
2783 max->pri = ilk_plane_wm_reg_max(dev_priv, level, false);
2784 max->spr = ilk_plane_wm_reg_max(dev_priv, level, true);
2785 max->cur = ilk_cursor_wm_reg_max(dev_priv, level);
2786 max->fbc = ilk_fbc_wm_reg_max(dev_priv);
2789 static bool ilk_validate_wm_level(int level,
2790 const struct ilk_wm_maximums *max,
2791 struct intel_wm_level *result)
2795 /* already determined to be invalid? */
2796 if (!result->enable)
2799 result->enable = result->pri_val <= max->pri &&
2800 result->spr_val <= max->spr &&
2801 result->cur_val <= max->cur;
2803 ret = result->enable;
2806 * HACK until we can pre-compute everything,
2807 * and thus fail gracefully if LP0 watermarks
2810 if (level == 0 && !result->enable) {
2811 if (result->pri_val > max->pri)
2812 DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n",
2813 level, result->pri_val, max->pri);
2814 if (result->spr_val > max->spr)
2815 DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n",
2816 level, result->spr_val, max->spr);
2817 if (result->cur_val > max->cur)
2818 DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n",
2819 level, result->cur_val, max->cur);
2821 result->pri_val = min_t(u32, result->pri_val, max->pri);
2822 result->spr_val = min_t(u32, result->spr_val, max->spr);
2823 result->cur_val = min_t(u32, result->cur_val, max->cur);
2824 result->enable = true;
2830 static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv,
2831 const struct intel_crtc *crtc,
2833 struct intel_crtc_state *crtc_state,
2834 const struct intel_plane_state *pristate,
2835 const struct intel_plane_state *sprstate,
2836 const struct intel_plane_state *curstate,
2837 struct intel_wm_level *result)
2839 u16 pri_latency = dev_priv->wm.pri_latency[level];
2840 u16 spr_latency = dev_priv->wm.spr_latency[level];
2841 u16 cur_latency = dev_priv->wm.cur_latency[level];
2843 /* WM1+ latency values stored in 0.5us units */
2851 result->pri_val = ilk_compute_pri_wm(crtc_state, pristate,
2852 pri_latency, level);
2853 result->fbc_val = ilk_compute_fbc_wm(crtc_state, pristate, result->pri_val);
2857 result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency);
2860 result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency);
2862 result->enable = true;
2865 static void intel_read_wm_latency(struct drm_i915_private *dev_priv,
2868 struct intel_uncore *uncore = &dev_priv->uncore;
2870 if (DISPLAY_VER(dev_priv) >= 9) {
2873 int level, max_level = ilk_wm_max_level(dev_priv);
2874 int mult = IS_DG2(dev_priv) ? 2 : 1;
2876 /* read the first set of memory latencies[0:3] */
2877 val = 0; /* data0 to be programmed to 0 for first set */
2878 ret = snb_pcode_read(&dev_priv->uncore, GEN9_PCODE_READ_MEM_LATENCY,
2882 drm_err(&dev_priv->drm,
2883 "SKL Mailbox read error = %d\n", ret);
2887 wm[0] = (val & GEN9_MEM_LATENCY_LEVEL_MASK) * mult;
2888 wm[1] = ((val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
2889 GEN9_MEM_LATENCY_LEVEL_MASK) * mult;
2890 wm[2] = ((val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
2891 GEN9_MEM_LATENCY_LEVEL_MASK) * mult;
2892 wm[3] = ((val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
2893 GEN9_MEM_LATENCY_LEVEL_MASK) * mult;
2895 /* read the second set of memory latencies[4:7] */
2896 val = 1; /* data0 to be programmed to 1 for second set */
2897 ret = snb_pcode_read(&dev_priv->uncore, GEN9_PCODE_READ_MEM_LATENCY,
2900 drm_err(&dev_priv->drm,
2901 "SKL Mailbox read error = %d\n", ret);
2905 wm[4] = (val & GEN9_MEM_LATENCY_LEVEL_MASK) * mult;
2906 wm[5] = ((val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
2907 GEN9_MEM_LATENCY_LEVEL_MASK) * mult;
2908 wm[6] = ((val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
2909 GEN9_MEM_LATENCY_LEVEL_MASK) * mult;
2910 wm[7] = ((val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
2911 GEN9_MEM_LATENCY_LEVEL_MASK) * mult;
2914 * If a level n (n > 1) has a 0us latency, all levels m (m >= n)
2915 * need to be disabled. We make sure to sanitize the values out
2916 * of the punit to satisfy this requirement.
2918 for (level = 1; level <= max_level; level++) {
2919 if (wm[level] == 0) {
2920 for (i = level + 1; i <= max_level; i++)
2923 max_level = level - 1;
2930 * WaWmMemoryReadLatency
2932 * punit doesn't take into account the read latency so we need
2933 * to add proper adjustement to each valid level we retrieve
2934 * from the punit when level 0 response data is 0us.
2937 u8 adjust = DISPLAY_VER(dev_priv) >= 12 ? 3 : 2;
2939 for (level = 0; level <= max_level; level++)
2940 wm[level] += adjust;
2944 * WA Level-0 adjustment for 16GB DIMMs: SKL+
2945 * If we could not get dimm info enable this WA to prevent from
2946 * any underrun. If not able to get Dimm info assume 16GB dimm
2947 * to avoid any underrun.
2949 if (dev_priv->dram_info.wm_lv_0_adjust_needed)
2951 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
2952 u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD);
2954 wm[0] = REG_FIELD_GET64(SSKPD_NEW_WM0_MASK_HSW, sskpd);
2956 wm[0] = REG_FIELD_GET64(SSKPD_OLD_WM0_MASK_HSW, sskpd);
2957 wm[1] = REG_FIELD_GET64(SSKPD_WM1_MASK_HSW, sskpd);
2958 wm[2] = REG_FIELD_GET64(SSKPD_WM2_MASK_HSW, sskpd);
2959 wm[3] = REG_FIELD_GET64(SSKPD_WM3_MASK_HSW, sskpd);
2960 wm[4] = REG_FIELD_GET64(SSKPD_WM4_MASK_HSW, sskpd);
2961 } else if (DISPLAY_VER(dev_priv) >= 6) {
2962 u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD);
2964 wm[0] = REG_FIELD_GET(SSKPD_WM0_MASK_SNB, sskpd);
2965 wm[1] = REG_FIELD_GET(SSKPD_WM1_MASK_SNB, sskpd);
2966 wm[2] = REG_FIELD_GET(SSKPD_WM2_MASK_SNB, sskpd);
2967 wm[3] = REG_FIELD_GET(SSKPD_WM3_MASK_SNB, sskpd);
2968 } else if (DISPLAY_VER(dev_priv) >= 5) {
2969 u32 mltr = intel_uncore_read(uncore, MLTR_ILK);
2971 /* ILK primary LP0 latency is 700 ns */
2973 wm[1] = REG_FIELD_GET(MLTR_WM1_MASK, mltr);
2974 wm[2] = REG_FIELD_GET(MLTR_WM2_MASK, mltr);
2976 MISSING_CASE(INTEL_DEVID(dev_priv));
2980 static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv,
2983 /* ILK sprite LP0 latency is 1300 ns */
2984 if (DISPLAY_VER(dev_priv) == 5)
2988 static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv,
2991 /* ILK cursor LP0 latency is 1300 ns */
2992 if (DISPLAY_VER(dev_priv) == 5)
2996 int ilk_wm_max_level(const struct drm_i915_private *dev_priv)
2998 /* how many WM levels are we expecting */
2999 if (HAS_HW_SAGV_WM(dev_priv))
3001 else if (DISPLAY_VER(dev_priv) >= 9)
3003 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3005 else if (DISPLAY_VER(dev_priv) >= 6)
3011 static void intel_print_wm_latency(struct drm_i915_private *dev_priv,
3015 int level, max_level = ilk_wm_max_level(dev_priv);
3017 for (level = 0; level <= max_level; level++) {
3018 unsigned int latency = wm[level];
3021 drm_dbg_kms(&dev_priv->drm,
3022 "%s WM%d latency not provided\n",
3028 * - latencies are in us on gen9.
3029 * - before then, WM1+ latency values are in 0.5us units
3031 if (DISPLAY_VER(dev_priv) >= 9)
3036 drm_dbg_kms(&dev_priv->drm,
3037 "%s WM%d latency %u (%u.%u usec)\n", name, level,
3038 wm[level], latency / 10, latency % 10);
3042 static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv,
3045 int level, max_level = ilk_wm_max_level(dev_priv);
3050 wm[0] = max(wm[0], min);
3051 for (level = 1; level <= max_level; level++)
3052 wm[level] = max_t(u16, wm[level], DIV_ROUND_UP(min, 5));
3057 static void snb_wm_latency_quirk(struct drm_i915_private *dev_priv)
3062 * The BIOS provided WM memory latency values are often
3063 * inadequate for high resolution displays. Adjust them.
3065 changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12);
3066 changed |= ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12);
3067 changed |= ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12);
3072 drm_dbg_kms(&dev_priv->drm,
3073 "WM latency values increased to avoid potential underruns\n");
3074 intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
3075 intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
3076 intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
3079 static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv)
3082 * On some SNB machines (Thinkpad X220 Tablet at least)
3083 * LP3 usage can cause vblank interrupts to be lost.
3084 * The DEIIR bit will go high but it looks like the CPU
3085 * never gets interrupted.
3087 * It's not clear whether other interrupt source could
3088 * be affected or if this is somehow limited to vblank
3089 * interrupts only. To play it safe we disable LP3
3090 * watermarks entirely.
3092 if (dev_priv->wm.pri_latency[3] == 0 &&
3093 dev_priv->wm.spr_latency[3] == 0 &&
3094 dev_priv->wm.cur_latency[3] == 0)
3097 dev_priv->wm.pri_latency[3] = 0;
3098 dev_priv->wm.spr_latency[3] = 0;
3099 dev_priv->wm.cur_latency[3] = 0;
3101 drm_dbg_kms(&dev_priv->drm,
3102 "LP3 watermarks disabled due to potential for lost interrupts\n");
3103 intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
3104 intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
3105 intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
3108 static void ilk_setup_wm_latency(struct drm_i915_private *dev_priv)
3110 intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency);
3112 memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency,
3113 sizeof(dev_priv->wm.pri_latency));
3114 memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency,
3115 sizeof(dev_priv->wm.pri_latency));
3117 intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency);
3118 intel_fixup_cur_wm_latency(dev_priv, dev_priv->wm.cur_latency);
3120 intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
3121 intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
3122 intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
3124 if (DISPLAY_VER(dev_priv) == 6) {
3125 snb_wm_latency_quirk(dev_priv);
3126 snb_wm_lp3_irq_quirk(dev_priv);
3130 static void skl_setup_wm_latency(struct drm_i915_private *dev_priv)
3132 intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency);
3133 intel_print_wm_latency(dev_priv, "Gen9 Plane", dev_priv->wm.skl_latency);
3136 static bool ilk_validate_pipe_wm(const struct drm_i915_private *dev_priv,
3137 struct intel_pipe_wm *pipe_wm)
3139 /* LP0 watermark maximums depend on this pipe alone */
3140 const struct intel_wm_config config = {
3141 .num_pipes_active = 1,
3142 .sprites_enabled = pipe_wm->sprites_enabled,
3143 .sprites_scaled = pipe_wm->sprites_scaled,
3145 struct ilk_wm_maximums max;
3147 /* LP0 watermarks always use 1/2 DDB partitioning */
3148 ilk_compute_wm_maximums(dev_priv, 0, &config, INTEL_DDB_PART_1_2, &max);
3150 /* At least LP0 must be valid */
3151 if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) {
3152 drm_dbg_kms(&dev_priv->drm, "LP0 watermark invalid\n");
3159 /* Compute new watermarks for the pipe */
3160 static int ilk_compute_pipe_wm(struct intel_atomic_state *state,
3161 struct intel_crtc *crtc)
3163 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
3164 struct intel_crtc_state *crtc_state =
3165 intel_atomic_get_new_crtc_state(state, crtc);
3166 struct intel_pipe_wm *pipe_wm;
3167 struct intel_plane *plane;
3168 const struct intel_plane_state *plane_state;
3169 const struct intel_plane_state *pristate = NULL;
3170 const struct intel_plane_state *sprstate = NULL;
3171 const struct intel_plane_state *curstate = NULL;
3172 int level, max_level = ilk_wm_max_level(dev_priv), usable_level;
3173 struct ilk_wm_maximums max;
3175 pipe_wm = &crtc_state->wm.ilk.optimal;
3177 intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
3178 if (plane->base.type == DRM_PLANE_TYPE_PRIMARY)
3179 pristate = plane_state;
3180 else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY)
3181 sprstate = plane_state;
3182 else if (plane->base.type == DRM_PLANE_TYPE_CURSOR)
3183 curstate = plane_state;
3186 pipe_wm->pipe_enabled = crtc_state->hw.active;
3187 pipe_wm->sprites_enabled = crtc_state->active_planes & BIT(PLANE_SPRITE0);
3188 pipe_wm->sprites_scaled = crtc_state->scaled_planes & BIT(PLANE_SPRITE0);
3190 usable_level = max_level;
3192 /* ILK/SNB: LP2+ watermarks only w/o sprites */
3193 if (DISPLAY_VER(dev_priv) <= 6 && pipe_wm->sprites_enabled)
3196 /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */
3197 if (pipe_wm->sprites_scaled)
3200 memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm));
3201 ilk_compute_wm_level(dev_priv, crtc, 0, crtc_state,
3202 pristate, sprstate, curstate, &pipe_wm->wm[0]);
3204 if (!ilk_validate_pipe_wm(dev_priv, pipe_wm))
3207 ilk_compute_wm_reg_maximums(dev_priv, 1, &max);
3209 for (level = 1; level <= usable_level; level++) {
3210 struct intel_wm_level *wm = &pipe_wm->wm[level];
3212 ilk_compute_wm_level(dev_priv, crtc, level, crtc_state,
3213 pristate, sprstate, curstate, wm);
3216 * Disable any watermark level that exceeds the
3217 * register maximums since such watermarks are
3220 if (!ilk_validate_wm_level(level, &max, wm)) {
3221 memset(wm, 0, sizeof(*wm));
3230 * Build a set of 'intermediate' watermark values that satisfy both the old
3231 * state and the new state. These can be programmed to the hardware
3234 static int ilk_compute_intermediate_wm(struct intel_atomic_state *state,
3235 struct intel_crtc *crtc)
3237 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3238 struct intel_crtc_state *new_crtc_state =
3239 intel_atomic_get_new_crtc_state(state, crtc);
3240 const struct intel_crtc_state *old_crtc_state =
3241 intel_atomic_get_old_crtc_state(state, crtc);
3242 struct intel_pipe_wm *a = &new_crtc_state->wm.ilk.intermediate;
3243 const struct intel_pipe_wm *b = &old_crtc_state->wm.ilk.optimal;
3244 int level, max_level = ilk_wm_max_level(dev_priv);
3247 * Start with the final, target watermarks, then combine with the
3248 * currently active watermarks to get values that are safe both before
3249 * and after the vblank.
3251 *a = new_crtc_state->wm.ilk.optimal;
3252 if (!new_crtc_state->hw.active ||
3253 drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) ||
3254 state->skip_intermediate_wm)
3257 a->pipe_enabled |= b->pipe_enabled;
3258 a->sprites_enabled |= b->sprites_enabled;
3259 a->sprites_scaled |= b->sprites_scaled;
3261 for (level = 0; level <= max_level; level++) {
3262 struct intel_wm_level *a_wm = &a->wm[level];
3263 const struct intel_wm_level *b_wm = &b->wm[level];
3265 a_wm->enable &= b_wm->enable;
3266 a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val);
3267 a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val);
3268 a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val);
3269 a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val);
3273 * We need to make sure that these merged watermark values are
3274 * actually a valid configuration themselves. If they're not,
3275 * there's no safe way to transition from the old state to
3276 * the new state, so we need to fail the atomic transaction.
3278 if (!ilk_validate_pipe_wm(dev_priv, a))
3282 * If our intermediate WM are identical to the final WM, then we can
3283 * omit the post-vblank programming; only update if it's different.
3285 if (memcmp(a, &new_crtc_state->wm.ilk.optimal, sizeof(*a)) != 0)
3286 new_crtc_state->wm.need_postvbl_update = true;
3292 * Merge the watermarks from all active pipes for a specific level.
3294 static void ilk_merge_wm_level(struct drm_i915_private *dev_priv,
3296 struct intel_wm_level *ret_wm)
3298 const struct intel_crtc *crtc;
3300 ret_wm->enable = true;
3302 for_each_intel_crtc(&dev_priv->drm, crtc) {
3303 const struct intel_pipe_wm *active = &crtc->wm.active.ilk;
3304 const struct intel_wm_level *wm = &active->wm[level];
3306 if (!active->pipe_enabled)
3310 * The watermark values may have been used in the past,
3311 * so we must maintain them in the registers for some
3312 * time even if the level is now disabled.
3315 ret_wm->enable = false;
3317 ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val);
3318 ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val);
3319 ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val);
3320 ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val);
3325 * Merge all low power watermarks for all active pipes.
3327 static void ilk_wm_merge(struct drm_i915_private *dev_priv,
3328 const struct intel_wm_config *config,
3329 const struct ilk_wm_maximums *max,
3330 struct intel_pipe_wm *merged)
3332 int level, max_level = ilk_wm_max_level(dev_priv);
3333 int last_enabled_level = max_level;
3335 /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */
3336 if ((DISPLAY_VER(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) &&
3337 config->num_pipes_active > 1)
3338 last_enabled_level = 0;
3340 /* ILK: FBC WM must be disabled always */
3341 merged->fbc_wm_enabled = DISPLAY_VER(dev_priv) >= 6;
3343 /* merge each WM1+ level */
3344 for (level = 1; level <= max_level; level++) {
3345 struct intel_wm_level *wm = &merged->wm[level];
3347 ilk_merge_wm_level(dev_priv, level, wm);
3349 if (level > last_enabled_level)
3351 else if (!ilk_validate_wm_level(level, max, wm))
3352 /* make sure all following levels get disabled */
3353 last_enabled_level = level - 1;
3356 * The spec says it is preferred to disable
3357 * FBC WMs instead of disabling a WM level.
3359 if (wm->fbc_val > max->fbc) {
3361 merged->fbc_wm_enabled = false;
3366 /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */
3367 if (DISPLAY_VER(dev_priv) == 5 && HAS_FBC(dev_priv) &&
3368 dev_priv->params.enable_fbc && !merged->fbc_wm_enabled) {
3369 for (level = 2; level <= max_level; level++) {
3370 struct intel_wm_level *wm = &merged->wm[level];
3377 static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm)
3379 /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */
3380 return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable);
3383 /* The value we need to program into the WM_LPx latency field */
3384 static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv,
3387 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3390 return dev_priv->wm.pri_latency[level];
3393 static void ilk_compute_wm_results(struct drm_i915_private *dev_priv,
3394 const struct intel_pipe_wm *merged,
3395 enum intel_ddb_partitioning partitioning,
3396 struct ilk_wm_values *results)
3398 struct intel_crtc *crtc;
3401 results->enable_fbc_wm = merged->fbc_wm_enabled;
3402 results->partitioning = partitioning;
3404 /* LP1+ register values */
3405 for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
3406 const struct intel_wm_level *r;
3408 level = ilk_wm_lp_to_level(wm_lp, merged);
3410 r = &merged->wm[level];
3413 * Maintain the watermark values even if the level is
3414 * disabled. Doing otherwise could cause underruns.
3416 results->wm_lp[wm_lp - 1] =
3417 WM_LP_LATENCY(ilk_wm_lp_latency(dev_priv, level)) |
3418 WM_LP_PRIMARY(r->pri_val) |
3419 WM_LP_CURSOR(r->cur_val);
3422 results->wm_lp[wm_lp - 1] |= WM_LP_ENABLE;
3424 if (DISPLAY_VER(dev_priv) >= 8)
3425 results->wm_lp[wm_lp - 1] |= WM_LP_FBC_BDW(r->fbc_val);
3427 results->wm_lp[wm_lp - 1] |= WM_LP_FBC_ILK(r->fbc_val);
3429 results->wm_lp_spr[wm_lp - 1] = WM_LP_SPRITE(r->spr_val);
3432 * Always set WM_LP_SPRITE_EN when spr_val != 0, even if the
3433 * level is disabled. Doing otherwise could cause underruns.
3435 if (DISPLAY_VER(dev_priv) <= 6 && r->spr_val) {
3436 drm_WARN_ON(&dev_priv->drm, wm_lp != 1);
3437 results->wm_lp_spr[wm_lp - 1] |= WM_LP_SPRITE_ENABLE;
3441 /* LP0 register values */
3442 for_each_intel_crtc(&dev_priv->drm, crtc) {
3443 enum pipe pipe = crtc->pipe;
3444 const struct intel_pipe_wm *pipe_wm = &crtc->wm.active.ilk;
3445 const struct intel_wm_level *r = &pipe_wm->wm[0];
3447 if (drm_WARN_ON(&dev_priv->drm, !r->enable))
3450 results->wm_pipe[pipe] =
3451 WM0_PIPE_PRIMARY(r->pri_val) |
3452 WM0_PIPE_SPRITE(r->spr_val) |
3453 WM0_PIPE_CURSOR(r->cur_val);
3457 /* Find the result with the highest level enabled. Check for enable_fbc_wm in
3458 * case both are at the same level. Prefer r1 in case they're the same. */
3459 static struct intel_pipe_wm *
3460 ilk_find_best_result(struct drm_i915_private *dev_priv,
3461 struct intel_pipe_wm *r1,
3462 struct intel_pipe_wm *r2)
3464 int level, max_level = ilk_wm_max_level(dev_priv);
3465 int level1 = 0, level2 = 0;
3467 for (level = 1; level <= max_level; level++) {
3468 if (r1->wm[level].enable)
3470 if (r2->wm[level].enable)
3474 if (level1 == level2) {
3475 if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled)
3479 } else if (level1 > level2) {
3486 /* dirty bits used to track which watermarks need changes */
3487 #define WM_DIRTY_PIPE(pipe) (1 << (pipe))
3488 #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp)))
3489 #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3))
3490 #define WM_DIRTY_FBC (1 << 24)
3491 #define WM_DIRTY_DDB (1 << 25)
3493 static unsigned int ilk_compute_wm_dirty(struct drm_i915_private *dev_priv,
3494 const struct ilk_wm_values *old,
3495 const struct ilk_wm_values *new)
3497 unsigned int dirty = 0;
3501 for_each_pipe(dev_priv, pipe) {
3502 if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) {
3503 dirty |= WM_DIRTY_PIPE(pipe);
3504 /* Must disable LP1+ watermarks too */
3505 dirty |= WM_DIRTY_LP_ALL;
3509 if (old->enable_fbc_wm != new->enable_fbc_wm) {
3510 dirty |= WM_DIRTY_FBC;
3511 /* Must disable LP1+ watermarks too */
3512 dirty |= WM_DIRTY_LP_ALL;
3515 if (old->partitioning != new->partitioning) {
3516 dirty |= WM_DIRTY_DDB;
3517 /* Must disable LP1+ watermarks too */
3518 dirty |= WM_DIRTY_LP_ALL;
3521 /* LP1+ watermarks already deemed dirty, no need to continue */
3522 if (dirty & WM_DIRTY_LP_ALL)
3525 /* Find the lowest numbered LP1+ watermark in need of an update... */
3526 for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
3527 if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] ||
3528 old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1])
3532 /* ...and mark it and all higher numbered LP1+ watermarks as dirty */
3533 for (; wm_lp <= 3; wm_lp++)
3534 dirty |= WM_DIRTY_LP(wm_lp);
3539 static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv,
3542 struct ilk_wm_values *previous = &dev_priv->wm.hw;
3543 bool changed = false;
3545 if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM_LP_ENABLE) {
3546 previous->wm_lp[2] &= ~WM_LP_ENABLE;
3547 intel_uncore_write(&dev_priv->uncore, WM3_LP_ILK, previous->wm_lp[2]);
3550 if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM_LP_ENABLE) {
3551 previous->wm_lp[1] &= ~WM_LP_ENABLE;
3552 intel_uncore_write(&dev_priv->uncore, WM2_LP_ILK, previous->wm_lp[1]);
3555 if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM_LP_ENABLE) {
3556 previous->wm_lp[0] &= ~WM_LP_ENABLE;
3557 intel_uncore_write(&dev_priv->uncore, WM1_LP_ILK, previous->wm_lp[0]);
3562 * Don't touch WM_LP_SPRITE_ENABLE here.
3563 * Doing so could cause underruns.
3570 * The spec says we shouldn't write when we don't need, because every write
3571 * causes WMs to be re-evaluated, expending some power.
3573 static void ilk_write_wm_values(struct drm_i915_private *dev_priv,
3574 struct ilk_wm_values *results)
3576 struct ilk_wm_values *previous = &dev_priv->wm.hw;
3580 dirty = ilk_compute_wm_dirty(dev_priv, previous, results);
3584 _ilk_disable_lp_wm(dev_priv, dirty);
3586 if (dirty & WM_DIRTY_PIPE(PIPE_A))
3587 intel_uncore_write(&dev_priv->uncore, WM0_PIPE_ILK(PIPE_A), results->wm_pipe[0]);
3588 if (dirty & WM_DIRTY_PIPE(PIPE_B))
3589 intel_uncore_write(&dev_priv->uncore, WM0_PIPE_ILK(PIPE_B), results->wm_pipe[1]);
3590 if (dirty & WM_DIRTY_PIPE(PIPE_C))
3591 intel_uncore_write(&dev_priv->uncore, WM0_PIPE_ILK(PIPE_C), results->wm_pipe[2]);
3593 if (dirty & WM_DIRTY_DDB) {
3594 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3595 val = intel_uncore_read(&dev_priv->uncore, WM_MISC);
3596 if (results->partitioning == INTEL_DDB_PART_1_2)
3597 val &= ~WM_MISC_DATA_PARTITION_5_6;
3599 val |= WM_MISC_DATA_PARTITION_5_6;
3600 intel_uncore_write(&dev_priv->uncore, WM_MISC, val);
3602 val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2);
3603 if (results->partitioning == INTEL_DDB_PART_1_2)
3604 val &= ~DISP_DATA_PARTITION_5_6;
3606 val |= DISP_DATA_PARTITION_5_6;
3607 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL2, val);
3611 if (dirty & WM_DIRTY_FBC) {
3612 val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL);
3613 if (results->enable_fbc_wm)
3614 val &= ~DISP_FBC_WM_DIS;
3616 val |= DISP_FBC_WM_DIS;
3617 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, val);
3620 if (dirty & WM_DIRTY_LP(1) &&
3621 previous->wm_lp_spr[0] != results->wm_lp_spr[0])
3622 intel_uncore_write(&dev_priv->uncore, WM1S_LP_ILK, results->wm_lp_spr[0]);
3624 if (DISPLAY_VER(dev_priv) >= 7) {
3625 if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1])
3626 intel_uncore_write(&dev_priv->uncore, WM2S_LP_IVB, results->wm_lp_spr[1]);
3627 if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2])
3628 intel_uncore_write(&dev_priv->uncore, WM3S_LP_IVB, results->wm_lp_spr[2]);
3631 if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] != results->wm_lp[0])
3632 intel_uncore_write(&dev_priv->uncore, WM1_LP_ILK, results->wm_lp[0]);
3633 if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] != results->wm_lp[1])
3634 intel_uncore_write(&dev_priv->uncore, WM2_LP_ILK, results->wm_lp[1]);
3635 if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] != results->wm_lp[2])
3636 intel_uncore_write(&dev_priv->uncore, WM3_LP_ILK, results->wm_lp[2]);
3638 dev_priv->wm.hw = *results;
3641 bool ilk_disable_lp_wm(struct drm_i915_private *dev_priv)
3643 return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL);
3646 u8 intel_enabled_dbuf_slices_mask(struct drm_i915_private *dev_priv)
3648 u8 enabled_slices = 0;
3649 enum dbuf_slice slice;
3651 for_each_dbuf_slice(dev_priv, slice) {
3652 if (intel_uncore_read(&dev_priv->uncore,
3653 DBUF_CTL_S(slice)) & DBUF_POWER_STATE)
3654 enabled_slices |= BIT(slice);
3657 return enabled_slices;
3661 * FIXME: We still don't have the proper code detect if we need to apply the WA,
3662 * so assume we'll always need it in order to avoid underruns.
3664 static bool skl_needs_memory_bw_wa(struct drm_i915_private *dev_priv)
3666 return DISPLAY_VER(dev_priv) == 9;
3670 intel_has_sagv(struct drm_i915_private *dev_priv)
3672 return DISPLAY_VER(dev_priv) >= 9 && !IS_LP(dev_priv) &&
3673 dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED;
3677 intel_sagv_block_time(struct drm_i915_private *dev_priv)
3679 if (DISPLAY_VER(dev_priv) >= 12) {
3683 ret = snb_pcode_read(&dev_priv->uncore,
3684 GEN12_PCODE_READ_SAGV_BLOCK_TIME_US,
3687 drm_dbg_kms(&dev_priv->drm, "Couldn't read SAGV block time!\n");
3692 } else if (DISPLAY_VER(dev_priv) == 11) {
3694 } else if (DISPLAY_VER(dev_priv) == 9 && !IS_LP(dev_priv)) {
3701 static void intel_sagv_init(struct drm_i915_private *i915)
3703 if (!intel_has_sagv(i915))
3704 i915->sagv_status = I915_SAGV_NOT_CONTROLLED;
3707 * Probe to see if we have working SAGV control.
3708 * For icl+ this was already determined by intel_bw_init_hw().
3710 if (DISPLAY_VER(i915) < 11)
3711 skl_sagv_disable(i915);
3713 drm_WARN_ON(&i915->drm, i915->sagv_status == I915_SAGV_UNKNOWN);
3715 i915->sagv_block_time_us = intel_sagv_block_time(i915);
3717 drm_dbg_kms(&i915->drm, "SAGV supported: %s, original SAGV block time: %u us\n",
3718 str_yes_no(intel_has_sagv(i915)), i915->sagv_block_time_us);
3720 /* avoid overflow when adding with wm0 latency/etc. */
3721 if (drm_WARN(&i915->drm, i915->sagv_block_time_us > U16_MAX,
3722 "Excessive SAGV block time %u, ignoring\n",
3723 i915->sagv_block_time_us))
3724 i915->sagv_block_time_us = 0;
3726 if (!intel_has_sagv(i915))
3727 i915->sagv_block_time_us = 0;
3731 * SAGV dynamically adjusts the system agent voltage and clock frequencies
3732 * depending on power and performance requirements. The display engine access
3733 * to system memory is blocked during the adjustment time. Because of the
3734 * blocking time, having this enabled can cause full system hangs and/or pipe
3735 * underruns if we don't meet all of the following requirements:
3737 * - <= 1 pipe enabled
3738 * - All planes can enable watermarks for latencies >= SAGV engine block time
3739 * - We're not using an interlaced display configuration
3741 static void skl_sagv_enable(struct drm_i915_private *dev_priv)
3745 if (!intel_has_sagv(dev_priv))
3748 if (dev_priv->sagv_status == I915_SAGV_ENABLED)
3751 drm_dbg_kms(&dev_priv->drm, "Enabling SAGV\n");
3752 ret = snb_pcode_write(&dev_priv->uncore, GEN9_PCODE_SAGV_CONTROL,
3755 /* We don't need to wait for SAGV when enabling */
3758 * Some skl systems, pre-release machines in particular,
3759 * don't actually have SAGV.
3761 if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) {
3762 drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n");
3763 dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
3765 } else if (ret < 0) {
3766 drm_err(&dev_priv->drm, "Failed to enable SAGV\n");
3770 dev_priv->sagv_status = I915_SAGV_ENABLED;
3773 static void skl_sagv_disable(struct drm_i915_private *dev_priv)
3777 if (!intel_has_sagv(dev_priv))
3780 if (dev_priv->sagv_status == I915_SAGV_DISABLED)
3783 drm_dbg_kms(&dev_priv->drm, "Disabling SAGV\n");
3784 /* bspec says to keep retrying for at least 1 ms */
3785 ret = skl_pcode_request(&dev_priv->uncore, GEN9_PCODE_SAGV_CONTROL,
3787 GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED,
3790 * Some skl systems, pre-release machines in particular,
3791 * don't actually have SAGV.
3793 if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) {
3794 drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n");
3795 dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
3797 } else if (ret < 0) {
3798 drm_err(&dev_priv->drm, "Failed to disable SAGV (%d)\n", ret);
3802 dev_priv->sagv_status = I915_SAGV_DISABLED;
3805 static void skl_sagv_pre_plane_update(struct intel_atomic_state *state)
3807 struct drm_i915_private *i915 = to_i915(state->base.dev);
3808 const struct intel_bw_state *new_bw_state =
3809 intel_atomic_get_new_bw_state(state);
3814 if (!intel_can_enable_sagv(i915, new_bw_state))
3815 skl_sagv_disable(i915);
3818 static void skl_sagv_post_plane_update(struct intel_atomic_state *state)
3820 struct drm_i915_private *i915 = to_i915(state->base.dev);
3821 const struct intel_bw_state *new_bw_state =
3822 intel_atomic_get_new_bw_state(state);
3827 if (intel_can_enable_sagv(i915, new_bw_state))
3828 skl_sagv_enable(i915);
3831 static void icl_sagv_pre_plane_update(struct intel_atomic_state *state)
3833 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
3834 const struct intel_bw_state *old_bw_state =
3835 intel_atomic_get_old_bw_state(state);
3836 const struct intel_bw_state *new_bw_state =
3837 intel_atomic_get_new_bw_state(state);
3838 u16 old_mask, new_mask;
3843 old_mask = old_bw_state->qgv_points_mask;
3844 new_mask = old_bw_state->qgv_points_mask | new_bw_state->qgv_points_mask;
3846 if (old_mask == new_mask)
3849 WARN_ON(!new_bw_state->base.changed);
3851 drm_dbg_kms(&dev_priv->drm, "Restricting QGV points: 0x%x -> 0x%x\n",
3852 old_mask, new_mask);
3855 * Restrict required qgv points before updating the configuration.
3856 * According to BSpec we can't mask and unmask qgv points at the same
3857 * time. Also masking should be done before updating the configuration
3858 * and unmasking afterwards.
3860 icl_pcode_restrict_qgv_points(dev_priv, new_mask);
3863 static void icl_sagv_post_plane_update(struct intel_atomic_state *state)
3865 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
3866 const struct intel_bw_state *old_bw_state =
3867 intel_atomic_get_old_bw_state(state);
3868 const struct intel_bw_state *new_bw_state =
3869 intel_atomic_get_new_bw_state(state);
3870 u16 old_mask, new_mask;
3875 old_mask = old_bw_state->qgv_points_mask | new_bw_state->qgv_points_mask;
3876 new_mask = new_bw_state->qgv_points_mask;
3878 if (old_mask == new_mask)
3881 WARN_ON(!new_bw_state->base.changed);
3883 drm_dbg_kms(&dev_priv->drm, "Relaxing QGV points: 0x%x -> 0x%x\n",
3884 old_mask, new_mask);
3887 * Allow required qgv points after updating the configuration.
3888 * According to BSpec we can't mask and unmask qgv points at the same
3889 * time. Also masking should be done before updating the configuration
3890 * and unmasking afterwards.
3892 icl_pcode_restrict_qgv_points(dev_priv, new_mask);
3895 void intel_sagv_pre_plane_update(struct intel_atomic_state *state)
3897 struct drm_i915_private *i915 = to_i915(state->base.dev);
3900 * Just return if we can't control SAGV or don't have it.
3901 * This is different from situation when we have SAGV but just can't
3902 * afford it due to DBuf limitation - in case if SAGV is completely
3903 * disabled in a BIOS, we are not even allowed to send a PCode request,
3904 * as it will throw an error. So have to check it here.
3906 if (!intel_has_sagv(i915))
3909 if (DISPLAY_VER(i915) >= 11)
3910 icl_sagv_pre_plane_update(state);
3912 skl_sagv_pre_plane_update(state);
3915 void intel_sagv_post_plane_update(struct intel_atomic_state *state)
3917 struct drm_i915_private *i915 = to_i915(state->base.dev);
3920 * Just return if we can't control SAGV or don't have it.
3921 * This is different from situation when we have SAGV but just can't
3922 * afford it due to DBuf limitation - in case if SAGV is completely
3923 * disabled in a BIOS, we are not even allowed to send a PCode request,
3924 * as it will throw an error. So have to check it here.
3926 if (!intel_has_sagv(i915))
3929 if (DISPLAY_VER(i915) >= 11)
3930 icl_sagv_post_plane_update(state);
3932 skl_sagv_post_plane_update(state);
3935 static bool skl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state)
3937 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3938 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3939 enum plane_id plane_id;
3940 int max_level = INT_MAX;
3942 if (!intel_has_sagv(dev_priv))
3945 if (!crtc_state->hw.active)
3948 if (crtc_state->hw.pipe_mode.flags & DRM_MODE_FLAG_INTERLACE)
3951 for_each_plane_id_on_crtc(crtc, plane_id) {
3952 const struct skl_plane_wm *wm =
3953 &crtc_state->wm.skl.optimal.planes[plane_id];
3956 /* Skip this plane if it's not enabled */
3957 if (!wm->wm[0].enable)
3960 /* Find the highest enabled wm level for this plane */
3961 for (level = ilk_wm_max_level(dev_priv);
3962 !wm->wm[level].enable; --level)
3965 /* Highest common enabled wm level for all planes */
3966 max_level = min(level, max_level);
3969 /* No enabled planes? */
3970 if (max_level == INT_MAX)
3973 for_each_plane_id_on_crtc(crtc, plane_id) {
3974 const struct skl_plane_wm *wm =
3975 &crtc_state->wm.skl.optimal.planes[plane_id];
3978 * All enabled planes must have enabled a common wm level that
3979 * can tolerate memory latencies higher than sagv_block_time_us
3981 if (wm->wm[0].enable && !wm->wm[max_level].can_sagv)
3988 static bool tgl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state)
3990 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3991 enum plane_id plane_id;
3993 if (!crtc_state->hw.active)
3996 for_each_plane_id_on_crtc(crtc, plane_id) {
3997 const struct skl_plane_wm *wm =
3998 &crtc_state->wm.skl.optimal.planes[plane_id];
4000 if (wm->wm[0].enable && !wm->sagv.wm0.enable)
4007 static bool intel_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state)
4009 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4010 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4012 if (DISPLAY_VER(dev_priv) >= 12)
4013 return tgl_crtc_can_enable_sagv(crtc_state);
4015 return skl_crtc_can_enable_sagv(crtc_state);
4018 bool intel_can_enable_sagv(struct drm_i915_private *dev_priv,
4019 const struct intel_bw_state *bw_state)
4021 if (DISPLAY_VER(dev_priv) < 11 &&
4022 bw_state->active_pipes && !is_power_of_2(bw_state->active_pipes))
4025 return bw_state->pipe_sagv_reject == 0;
4028 static int intel_compute_sagv_mask(struct intel_atomic_state *state)
4030 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
4032 struct intel_crtc *crtc;
4033 struct intel_crtc_state *new_crtc_state;
4034 struct intel_bw_state *new_bw_state = NULL;
4035 const struct intel_bw_state *old_bw_state = NULL;
4038 for_each_new_intel_crtc_in_state(state, crtc,
4039 new_crtc_state, i) {
4040 new_bw_state = intel_atomic_get_bw_state(state);
4041 if (IS_ERR(new_bw_state))
4042 return PTR_ERR(new_bw_state);
4044 old_bw_state = intel_atomic_get_old_bw_state(state);
4046 if (intel_crtc_can_enable_sagv(new_crtc_state))
4047 new_bw_state->pipe_sagv_reject &= ~BIT(crtc->pipe);
4049 new_bw_state->pipe_sagv_reject |= BIT(crtc->pipe);
4055 new_bw_state->active_pipes =
4056 intel_calc_active_pipes(state, old_bw_state->active_pipes);
4058 if (new_bw_state->active_pipes != old_bw_state->active_pipes) {
4059 ret = intel_atomic_lock_global_state(&new_bw_state->base);
4064 if (intel_can_enable_sagv(dev_priv, new_bw_state) !=
4065 intel_can_enable_sagv(dev_priv, old_bw_state)) {
4066 ret = intel_atomic_serialize_global_state(&new_bw_state->base);
4069 } else if (new_bw_state->pipe_sagv_reject != old_bw_state->pipe_sagv_reject) {
4070 ret = intel_atomic_lock_global_state(&new_bw_state->base);
4075 for_each_new_intel_crtc_in_state(state, crtc,
4076 new_crtc_state, i) {
4077 struct skl_pipe_wm *pipe_wm = &new_crtc_state->wm.skl.optimal;
4080 * We store use_sagv_wm in the crtc state rather than relying on
4081 * that bw state since we have no convenient way to get at the
4082 * latter from the plane commit hooks (especially in the legacy
4085 pipe_wm->use_sagv_wm = !HAS_HW_SAGV_WM(dev_priv) &&
4086 DISPLAY_VER(dev_priv) >= 12 &&
4087 intel_can_enable_sagv(dev_priv, new_bw_state);
4093 static u16 skl_ddb_entry_init(struct skl_ddb_entry *entry,
4096 entry->start = start;
4102 static int intel_dbuf_slice_size(struct drm_i915_private *dev_priv)
4104 return INTEL_INFO(dev_priv)->display.dbuf.size /
4105 hweight8(INTEL_INFO(dev_priv)->display.dbuf.slice_mask);
4109 skl_ddb_entry_for_slices(struct drm_i915_private *dev_priv, u8 slice_mask,
4110 struct skl_ddb_entry *ddb)
4112 int slice_size = intel_dbuf_slice_size(dev_priv);
4120 ddb->start = (ffs(slice_mask) - 1) * slice_size;
4121 ddb->end = fls(slice_mask) * slice_size;
4123 WARN_ON(ddb->start >= ddb->end);
4124 WARN_ON(ddb->end > INTEL_INFO(dev_priv)->display.dbuf.size);
4127 static unsigned int mbus_ddb_offset(struct drm_i915_private *i915, u8 slice_mask)
4129 struct skl_ddb_entry ddb;
4131 if (slice_mask & (BIT(DBUF_S1) | BIT(DBUF_S2)))
4132 slice_mask = BIT(DBUF_S1);
4133 else if (slice_mask & (BIT(DBUF_S3) | BIT(DBUF_S4)))
4134 slice_mask = BIT(DBUF_S3);
4136 skl_ddb_entry_for_slices(i915, slice_mask, &ddb);
4141 u32 skl_ddb_dbuf_slice_mask(struct drm_i915_private *dev_priv,
4142 const struct skl_ddb_entry *entry)
4144 int slice_size = intel_dbuf_slice_size(dev_priv);
4145 enum dbuf_slice start_slice, end_slice;
4148 if (!skl_ddb_entry_size(entry))
4151 start_slice = entry->start / slice_size;
4152 end_slice = (entry->end - 1) / slice_size;
4155 * Per plane DDB entry can in a really worst case be on multiple slices
4156 * but single entry is anyway contigious.
4158 while (start_slice <= end_slice) {
4159 slice_mask |= BIT(start_slice);
4166 static unsigned int intel_crtc_ddb_weight(const struct intel_crtc_state *crtc_state)
4168 const struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
4169 int hdisplay, vdisplay;
4171 if (!crtc_state->hw.active)
4175 * Watermark/ddb requirement highly depends upon width of the
4176 * framebuffer, So instead of allocating DDB equally among pipes
4177 * distribute DDB based on resolution/width of the display.
4179 drm_mode_get_hv_timing(pipe_mode, &hdisplay, &vdisplay);
4184 static void intel_crtc_dbuf_weights(const struct intel_dbuf_state *dbuf_state,
4186 unsigned int *weight_start,
4187 unsigned int *weight_end,
4188 unsigned int *weight_total)
4190 struct drm_i915_private *dev_priv =
4191 to_i915(dbuf_state->base.state->base.dev);
4198 for_each_pipe(dev_priv, pipe) {
4199 int weight = dbuf_state->weight[pipe];
4202 * Do not account pipes using other slice sets
4203 * luckily as of current BSpec slice sets do not partially
4204 * intersect(pipes share either same one slice or same slice set
4205 * i.e no partial intersection), so it is enough to check for
4208 if (dbuf_state->slices[pipe] != dbuf_state->slices[for_pipe])
4211 *weight_total += weight;
4212 if (pipe < for_pipe) {
4213 *weight_start += weight;
4214 *weight_end += weight;
4215 } else if (pipe == for_pipe) {
4216 *weight_end += weight;
4222 skl_crtc_allocate_ddb(struct intel_atomic_state *state, struct intel_crtc *crtc)
4224 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4225 unsigned int weight_total, weight_start, weight_end;
4226 const struct intel_dbuf_state *old_dbuf_state =
4227 intel_atomic_get_old_dbuf_state(state);
4228 struct intel_dbuf_state *new_dbuf_state =
4229 intel_atomic_get_new_dbuf_state(state);
4230 struct intel_crtc_state *crtc_state;
4231 struct skl_ddb_entry ddb_slices;
4232 enum pipe pipe = crtc->pipe;
4233 unsigned int mbus_offset = 0;
4235 u32 dbuf_slice_mask;
4239 if (new_dbuf_state->weight[pipe] == 0) {
4240 skl_ddb_entry_init(&new_dbuf_state->ddb[pipe], 0, 0);
4244 dbuf_slice_mask = new_dbuf_state->slices[pipe];
4246 skl_ddb_entry_for_slices(dev_priv, dbuf_slice_mask, &ddb_slices);
4247 mbus_offset = mbus_ddb_offset(dev_priv, dbuf_slice_mask);
4248 ddb_range_size = skl_ddb_entry_size(&ddb_slices);
4250 intel_crtc_dbuf_weights(new_dbuf_state, pipe,
4251 &weight_start, &weight_end, &weight_total);
4253 start = ddb_range_size * weight_start / weight_total;
4254 end = ddb_range_size * weight_end / weight_total;
4256 skl_ddb_entry_init(&new_dbuf_state->ddb[pipe],
4257 ddb_slices.start - mbus_offset + start,
4258 ddb_slices.start - mbus_offset + end);
4261 if (old_dbuf_state->slices[pipe] == new_dbuf_state->slices[pipe] &&
4262 skl_ddb_entry_equal(&old_dbuf_state->ddb[pipe],
4263 &new_dbuf_state->ddb[pipe]))
4266 ret = intel_atomic_lock_global_state(&new_dbuf_state->base);
4270 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
4271 if (IS_ERR(crtc_state))
4272 return PTR_ERR(crtc_state);
4275 * Used for checking overlaps, so we need absolute
4276 * offsets instead of MBUS relative offsets.
4278 crtc_state->wm.skl.ddb.start = mbus_offset + new_dbuf_state->ddb[pipe].start;
4279 crtc_state->wm.skl.ddb.end = mbus_offset + new_dbuf_state->ddb[pipe].end;
4281 drm_dbg_kms(&dev_priv->drm,
4282 "[CRTC:%d:%s] dbuf slices 0x%x -> 0x%x, ddb (%d - %d) -> (%d - %d), active pipes 0x%x -> 0x%x\n",
4283 crtc->base.base.id, crtc->base.name,
4284 old_dbuf_state->slices[pipe], new_dbuf_state->slices[pipe],
4285 old_dbuf_state->ddb[pipe].start, old_dbuf_state->ddb[pipe].end,
4286 new_dbuf_state->ddb[pipe].start, new_dbuf_state->ddb[pipe].end,
4287 old_dbuf_state->active_pipes, new_dbuf_state->active_pipes);
4292 static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state,
4293 int width, const struct drm_format_info *format,
4294 u64 modifier, unsigned int rotation,
4295 u32 plane_pixel_rate, struct skl_wm_params *wp,
4298 static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state,
4299 struct intel_plane *plane,
4301 unsigned int latency,
4302 const struct skl_wm_params *wp,
4303 const struct skl_wm_level *result_prev,
4304 struct skl_wm_level *result /* out */);
4307 skl_cursor_allocation(const struct intel_crtc_state *crtc_state,
4310 struct intel_plane *plane = to_intel_plane(crtc_state->uapi.crtc->cursor);
4311 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4312 int level, max_level = ilk_wm_max_level(dev_priv);
4313 struct skl_wm_level wm = {};
4314 int ret, min_ddb_alloc = 0;
4315 struct skl_wm_params wp;
4317 ret = skl_compute_wm_params(crtc_state, 256,
4318 drm_format_info(DRM_FORMAT_ARGB8888),
4319 DRM_FORMAT_MOD_LINEAR,
4321 crtc_state->pixel_rate, &wp, 0);
4322 drm_WARN_ON(&dev_priv->drm, ret);
4324 for (level = 0; level <= max_level; level++) {
4325 unsigned int latency = dev_priv->wm.skl_latency[level];
4327 skl_compute_plane_wm(crtc_state, plane, level, latency, &wp, &wm, &wm);
4328 if (wm.min_ddb_alloc == U16_MAX)
4331 min_ddb_alloc = wm.min_ddb_alloc;
4334 return max(num_active == 1 ? 32 : 8, min_ddb_alloc);
4337 static void skl_ddb_entry_init_from_hw(struct skl_ddb_entry *entry, u32 reg)
4339 skl_ddb_entry_init(entry,
4340 REG_FIELD_GET(PLANE_BUF_START_MASK, reg),
4341 REG_FIELD_GET(PLANE_BUF_END_MASK, reg));
4347 skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv,
4348 const enum pipe pipe,
4349 const enum plane_id plane_id,
4350 struct skl_ddb_entry *ddb,
4351 struct skl_ddb_entry *ddb_y)
4355 /* Cursor doesn't support NV12/planar, so no extra calculation needed */
4356 if (plane_id == PLANE_CURSOR) {
4357 val = intel_uncore_read(&dev_priv->uncore, CUR_BUF_CFG(pipe));
4358 skl_ddb_entry_init_from_hw(ddb, val);
4362 val = intel_uncore_read(&dev_priv->uncore, PLANE_BUF_CFG(pipe, plane_id));
4363 skl_ddb_entry_init_from_hw(ddb, val);
4365 if (DISPLAY_VER(dev_priv) >= 11)
4368 val = intel_uncore_read(&dev_priv->uncore, PLANE_NV12_BUF_CFG(pipe, plane_id));
4369 skl_ddb_entry_init_from_hw(ddb_y, val);
4372 static void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc,
4373 struct skl_ddb_entry *ddb,
4374 struct skl_ddb_entry *ddb_y)
4376 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4377 enum intel_display_power_domain power_domain;
4378 enum pipe pipe = crtc->pipe;
4379 intel_wakeref_t wakeref;
4380 enum plane_id plane_id;
4382 power_domain = POWER_DOMAIN_PIPE(pipe);
4383 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
4387 for_each_plane_id_on_crtc(crtc, plane_id)
4388 skl_ddb_get_hw_plane_state(dev_priv, pipe,
4393 intel_display_power_put(dev_priv, power_domain, wakeref);
4396 struct dbuf_slice_conf_entry {
4398 u8 dbuf_mask[I915_MAX_PIPES];
4403 * Table taken from Bspec 12716
4404 * Pipes do have some preferred DBuf slice affinity,
4405 * plus there are some hardcoded requirements on how
4406 * those should be distributed for multipipe scenarios.
4407 * For more DBuf slices algorithm can get even more messy
4408 * and less readable, so decided to use a table almost
4409 * as is from BSpec itself - that way it is at least easier
4410 * to compare, change and check.
4412 static const struct dbuf_slice_conf_entry icl_allowed_dbufs[] =
4413 /* Autogenerated with igt/tools/intel_dbuf_map tool: */
4416 .active_pipes = BIT(PIPE_A),
4418 [PIPE_A] = BIT(DBUF_S1),
4422 .active_pipes = BIT(PIPE_B),
4424 [PIPE_B] = BIT(DBUF_S1),
4428 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B),
4430 [PIPE_A] = BIT(DBUF_S1),
4431 [PIPE_B] = BIT(DBUF_S2),
4435 .active_pipes = BIT(PIPE_C),
4437 [PIPE_C] = BIT(DBUF_S2),
4441 .active_pipes = BIT(PIPE_A) | BIT(PIPE_C),
4443 [PIPE_A] = BIT(DBUF_S1),
4444 [PIPE_C] = BIT(DBUF_S2),
4448 .active_pipes = BIT(PIPE_B) | BIT(PIPE_C),
4450 [PIPE_B] = BIT(DBUF_S1),
4451 [PIPE_C] = BIT(DBUF_S2),
4455 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C),
4457 [PIPE_A] = BIT(DBUF_S1),
4458 [PIPE_B] = BIT(DBUF_S1),
4459 [PIPE_C] = BIT(DBUF_S2),
4466 * Table taken from Bspec 49255
4467 * Pipes do have some preferred DBuf slice affinity,
4468 * plus there are some hardcoded requirements on how
4469 * those should be distributed for multipipe scenarios.
4470 * For more DBuf slices algorithm can get even more messy
4471 * and less readable, so decided to use a table almost
4472 * as is from BSpec itself - that way it is at least easier
4473 * to compare, change and check.
4475 static const struct dbuf_slice_conf_entry tgl_allowed_dbufs[] =
4476 /* Autogenerated with igt/tools/intel_dbuf_map tool: */
4479 .active_pipes = BIT(PIPE_A),
4481 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4485 .active_pipes = BIT(PIPE_B),
4487 [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2),
4491 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B),
4493 [PIPE_A] = BIT(DBUF_S2),
4494 [PIPE_B] = BIT(DBUF_S1),
4498 .active_pipes = BIT(PIPE_C),
4500 [PIPE_C] = BIT(DBUF_S2) | BIT(DBUF_S1),
4504 .active_pipes = BIT(PIPE_A) | BIT(PIPE_C),
4506 [PIPE_A] = BIT(DBUF_S1),
4507 [PIPE_C] = BIT(DBUF_S2),
4511 .active_pipes = BIT(PIPE_B) | BIT(PIPE_C),
4513 [PIPE_B] = BIT(DBUF_S1),
4514 [PIPE_C] = BIT(DBUF_S2),
4518 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C),
4520 [PIPE_A] = BIT(DBUF_S1),
4521 [PIPE_B] = BIT(DBUF_S1),
4522 [PIPE_C] = BIT(DBUF_S2),
4526 .active_pipes = BIT(PIPE_D),
4528 [PIPE_D] = BIT(DBUF_S2) | BIT(DBUF_S1),
4532 .active_pipes = BIT(PIPE_A) | BIT(PIPE_D),
4534 [PIPE_A] = BIT(DBUF_S1),
4535 [PIPE_D] = BIT(DBUF_S2),
4539 .active_pipes = BIT(PIPE_B) | BIT(PIPE_D),
4541 [PIPE_B] = BIT(DBUF_S1),
4542 [PIPE_D] = BIT(DBUF_S2),
4546 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D),
4548 [PIPE_A] = BIT(DBUF_S1),
4549 [PIPE_B] = BIT(DBUF_S1),
4550 [PIPE_D] = BIT(DBUF_S2),
4554 .active_pipes = BIT(PIPE_C) | BIT(PIPE_D),
4556 [PIPE_C] = BIT(DBUF_S1),
4557 [PIPE_D] = BIT(DBUF_S2),
4561 .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D),
4563 [PIPE_A] = BIT(DBUF_S1),
4564 [PIPE_C] = BIT(DBUF_S2),
4565 [PIPE_D] = BIT(DBUF_S2),
4569 .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
4571 [PIPE_B] = BIT(DBUF_S1),
4572 [PIPE_C] = BIT(DBUF_S2),
4573 [PIPE_D] = BIT(DBUF_S2),
4577 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
4579 [PIPE_A] = BIT(DBUF_S1),
4580 [PIPE_B] = BIT(DBUF_S1),
4581 [PIPE_C] = BIT(DBUF_S2),
4582 [PIPE_D] = BIT(DBUF_S2),
4588 static const struct dbuf_slice_conf_entry dg2_allowed_dbufs[] = {
4590 .active_pipes = BIT(PIPE_A),
4592 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4596 .active_pipes = BIT(PIPE_B),
4598 [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2),
4602 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B),
4604 [PIPE_A] = BIT(DBUF_S1),
4605 [PIPE_B] = BIT(DBUF_S2),
4609 .active_pipes = BIT(PIPE_C),
4611 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4615 .active_pipes = BIT(PIPE_A) | BIT(PIPE_C),
4617 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4618 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4622 .active_pipes = BIT(PIPE_B) | BIT(PIPE_C),
4624 [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2),
4625 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4629 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C),
4631 [PIPE_A] = BIT(DBUF_S1),
4632 [PIPE_B] = BIT(DBUF_S2),
4633 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4637 .active_pipes = BIT(PIPE_D),
4639 [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4),
4643 .active_pipes = BIT(PIPE_A) | BIT(PIPE_D),
4645 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4646 [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4),
4650 .active_pipes = BIT(PIPE_B) | BIT(PIPE_D),
4652 [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2),
4653 [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4),
4657 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D),
4659 [PIPE_A] = BIT(DBUF_S1),
4660 [PIPE_B] = BIT(DBUF_S2),
4661 [PIPE_D] = BIT(DBUF_S3) | BIT(DBUF_S4),
4665 .active_pipes = BIT(PIPE_C) | BIT(PIPE_D),
4667 [PIPE_C] = BIT(DBUF_S3),
4668 [PIPE_D] = BIT(DBUF_S4),
4672 .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D),
4674 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4675 [PIPE_C] = BIT(DBUF_S3),
4676 [PIPE_D] = BIT(DBUF_S4),
4680 .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
4682 [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2),
4683 [PIPE_C] = BIT(DBUF_S3),
4684 [PIPE_D] = BIT(DBUF_S4),
4688 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
4690 [PIPE_A] = BIT(DBUF_S1),
4691 [PIPE_B] = BIT(DBUF_S2),
4692 [PIPE_C] = BIT(DBUF_S3),
4693 [PIPE_D] = BIT(DBUF_S4),
4699 static const struct dbuf_slice_conf_entry adlp_allowed_dbufs[] = {
4701 * Keep the join_mbus cases first so check_mbus_joined()
4702 * will prefer them over the !join_mbus cases.
4705 .active_pipes = BIT(PIPE_A),
4707 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2) | BIT(DBUF_S3) | BIT(DBUF_S4),
4712 .active_pipes = BIT(PIPE_B),
4714 [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2) | BIT(DBUF_S3) | BIT(DBUF_S4),
4719 .active_pipes = BIT(PIPE_A),
4721 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4726 .active_pipes = BIT(PIPE_B),
4728 [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4),
4733 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B),
4735 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4736 [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4),
4740 .active_pipes = BIT(PIPE_C),
4742 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4746 .active_pipes = BIT(PIPE_A) | BIT(PIPE_C),
4748 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4749 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4753 .active_pipes = BIT(PIPE_B) | BIT(PIPE_C),
4755 [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4),
4756 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4760 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C),
4762 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4763 [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4),
4764 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4768 .active_pipes = BIT(PIPE_D),
4770 [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2),
4774 .active_pipes = BIT(PIPE_A) | BIT(PIPE_D),
4776 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4777 [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2),
4781 .active_pipes = BIT(PIPE_B) | BIT(PIPE_D),
4783 [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4),
4784 [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2),
4788 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D),
4790 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4791 [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4),
4792 [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2),
4796 .active_pipes = BIT(PIPE_C) | BIT(PIPE_D),
4798 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4799 [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2),
4803 .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D),
4805 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4806 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4807 [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2),
4811 .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
4813 [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4),
4814 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4815 [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2),
4819 .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
4821 [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4822 [PIPE_B] = BIT(DBUF_S3) | BIT(DBUF_S4),
4823 [PIPE_C] = BIT(DBUF_S3) | BIT(DBUF_S4),
4824 [PIPE_D] = BIT(DBUF_S1) | BIT(DBUF_S2),
4831 static bool check_mbus_joined(u8 active_pipes,
4832 const struct dbuf_slice_conf_entry *dbuf_slices)
4836 for (i = 0; dbuf_slices[i].active_pipes != 0; i++) {
4837 if (dbuf_slices[i].active_pipes == active_pipes)
4838 return dbuf_slices[i].join_mbus;
4843 static bool adlp_check_mbus_joined(u8 active_pipes)
4845 return check_mbus_joined(active_pipes, adlp_allowed_dbufs);
4848 static u8 compute_dbuf_slices(enum pipe pipe, u8 active_pipes, bool join_mbus,
4849 const struct dbuf_slice_conf_entry *dbuf_slices)
4853 for (i = 0; dbuf_slices[i].active_pipes != 0; i++) {
4854 if (dbuf_slices[i].active_pipes == active_pipes &&
4855 dbuf_slices[i].join_mbus == join_mbus)
4856 return dbuf_slices[i].dbuf_mask[pipe];
4862 * This function finds an entry with same enabled pipe configuration and
4863 * returns correspondent DBuf slice mask as stated in BSpec for particular
4866 static u8 icl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes, bool join_mbus)
4869 * FIXME: For ICL this is still a bit unclear as prev BSpec revision
4870 * required calculating "pipe ratio" in order to determine
4871 * if one or two slices can be used for single pipe configurations
4872 * as additional constraint to the existing table.
4873 * However based on recent info, it should be not "pipe ratio"
4874 * but rather ratio between pixel_rate and cdclk with additional
4875 * constants, so for now we are using only table until this is
4876 * clarified. Also this is the reason why crtc_state param is
4877 * still here - we will need it once those additional constraints
4880 return compute_dbuf_slices(pipe, active_pipes, join_mbus,
4884 static u8 tgl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes, bool join_mbus)
4886 return compute_dbuf_slices(pipe, active_pipes, join_mbus,
4890 static u8 adlp_compute_dbuf_slices(enum pipe pipe, u8 active_pipes, bool join_mbus)
4892 return compute_dbuf_slices(pipe, active_pipes, join_mbus,
4893 adlp_allowed_dbufs);
4896 static u8 dg2_compute_dbuf_slices(enum pipe pipe, u8 active_pipes, bool join_mbus)
4898 return compute_dbuf_slices(pipe, active_pipes, join_mbus,
4902 static u8 skl_compute_dbuf_slices(struct intel_crtc *crtc, u8 active_pipes, bool join_mbus)
4904 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4905 enum pipe pipe = crtc->pipe;
4907 if (IS_DG2(dev_priv))
4908 return dg2_compute_dbuf_slices(pipe, active_pipes, join_mbus);
4909 else if (IS_ALDERLAKE_P(dev_priv))
4910 return adlp_compute_dbuf_slices(pipe, active_pipes, join_mbus);
4911 else if (DISPLAY_VER(dev_priv) == 12)
4912 return tgl_compute_dbuf_slices(pipe, active_pipes, join_mbus);
4913 else if (DISPLAY_VER(dev_priv) == 11)
4914 return icl_compute_dbuf_slices(pipe, active_pipes, join_mbus);
4916 * For anything else just return one slice yet.
4917 * Should be extended for other platforms.
4919 return active_pipes & BIT(pipe) ? BIT(DBUF_S1) : 0;
4923 use_minimal_wm0_only(const struct intel_crtc_state *crtc_state,
4924 struct intel_plane *plane)
4926 struct drm_i915_private *i915 = to_i915(plane->base.dev);
4928 return DISPLAY_VER(i915) >= 13 &&
4929 crtc_state->uapi.async_flip &&
4934 skl_total_relative_data_rate(const struct intel_crtc_state *crtc_state)
4936 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4937 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4938 enum plane_id plane_id;
4941 for_each_plane_id_on_crtc(crtc, plane_id) {
4942 if (plane_id == PLANE_CURSOR)
4945 data_rate += crtc_state->rel_data_rate[plane_id];
4947 if (DISPLAY_VER(i915) < 11)
4948 data_rate += crtc_state->rel_data_rate_y[plane_id];
4954 static const struct skl_wm_level *
4955 skl_plane_wm_level(const struct skl_pipe_wm *pipe_wm,
4956 enum plane_id plane_id,
4959 const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id];
4961 if (level == 0 && pipe_wm->use_sagv_wm)
4962 return &wm->sagv.wm0;
4964 return &wm->wm[level];
4967 static const struct skl_wm_level *
4968 skl_plane_trans_wm(const struct skl_pipe_wm *pipe_wm,
4969 enum plane_id plane_id)
4971 const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id];
4973 if (pipe_wm->use_sagv_wm)
4974 return &wm->sagv.trans_wm;
4976 return &wm->trans_wm;
4980 * We only disable the watermarks for each plane if
4981 * they exceed the ddb allocation of said plane. This
4982 * is done so that we don't end up touching cursor
4983 * watermarks needlessly when some other plane reduces
4984 * our max possible watermark level.
4986 * Bspec has this to say about the PLANE_WM enable bit:
4987 * "All the watermarks at this level for all enabled
4988 * planes must be enabled before the level will be used."
4989 * So this is actually safe to do.
4992 skl_check_wm_level(struct skl_wm_level *wm, const struct skl_ddb_entry *ddb)
4994 if (wm->min_ddb_alloc > skl_ddb_entry_size(ddb))
4995 memset(wm, 0, sizeof(*wm));
4999 skl_check_nv12_wm_level(struct skl_wm_level *wm, struct skl_wm_level *uv_wm,
5000 const struct skl_ddb_entry *ddb_y, const struct skl_ddb_entry *ddb)
5002 if (wm->min_ddb_alloc > skl_ddb_entry_size(ddb_y) ||
5003 uv_wm->min_ddb_alloc > skl_ddb_entry_size(ddb)) {
5004 memset(wm, 0, sizeof(*wm));
5005 memset(uv_wm, 0, sizeof(*uv_wm));
5009 static bool icl_need_wm1_wa(struct drm_i915_private *i915,
5010 enum plane_id plane_id)
5013 * Wa_1408961008:icl, ehl
5014 * Wa_14012656716:tgl, adl
5015 * Underruns with WM1+ disabled
5017 return DISPLAY_VER(i915) == 11 ||
5018 (IS_DISPLAY_VER(i915, 12, 13) && plane_id == PLANE_CURSOR);
5021 struct skl_plane_ddb_iter {
5027 skl_allocate_plane_ddb(struct skl_plane_ddb_iter *iter,
5028 struct skl_ddb_entry *ddb,
5029 const struct skl_wm_level *wm,
5032 u16 size, extra = 0;
5035 extra = min_t(u16, iter->size,
5036 DIV64_U64_ROUND_UP(iter->size * data_rate,
5038 iter->size -= extra;
5039 iter->data_rate -= data_rate;
5043 * Keep ddb entry of all disabled planes explicitly zeroed
5044 * to avoid skl_ddb_add_affected_planes() adding them to
5045 * the state when other planes change their allocations.
5047 size = wm->min_ddb_alloc + extra;
5049 iter->start = skl_ddb_entry_init(ddb, iter->start,
5050 iter->start + size);
5054 skl_crtc_allocate_plane_ddb(struct intel_atomic_state *state,
5055 struct intel_crtc *crtc)
5057 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5058 struct intel_crtc_state *crtc_state =
5059 intel_atomic_get_new_crtc_state(state, crtc);
5060 const struct intel_dbuf_state *dbuf_state =
5061 intel_atomic_get_new_dbuf_state(state);
5062 const struct skl_ddb_entry *alloc = &dbuf_state->ddb[crtc->pipe];
5063 int num_active = hweight8(dbuf_state->active_pipes);
5064 struct skl_plane_ddb_iter iter;
5065 enum plane_id plane_id;
5070 /* Clear the partitioning for disabled planes. */
5071 memset(crtc_state->wm.skl.plane_ddb, 0, sizeof(crtc_state->wm.skl.plane_ddb));
5072 memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y));
5074 if (!crtc_state->hw.active)
5077 iter.start = alloc->start;
5078 iter.size = skl_ddb_entry_size(alloc);
5082 /* Allocate fixed number of blocks for cursor. */
5083 cursor_size = skl_cursor_allocation(crtc_state, num_active);
5084 iter.size -= cursor_size;
5085 skl_ddb_entry_init(&crtc_state->wm.skl.plane_ddb[PLANE_CURSOR],
5086 alloc->end - cursor_size, alloc->end);
5088 iter.data_rate = skl_total_relative_data_rate(crtc_state);
5091 * Find the highest watermark level for which we can satisfy the block
5092 * requirement of active planes.
5094 for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) {
5096 for_each_plane_id_on_crtc(crtc, plane_id) {
5097 const struct skl_plane_wm *wm =
5098 &crtc_state->wm.skl.optimal.planes[plane_id];
5100 if (plane_id == PLANE_CURSOR) {
5101 const struct skl_ddb_entry *ddb =
5102 &crtc_state->wm.skl.plane_ddb[plane_id];
5104 if (wm->wm[level].min_ddb_alloc > skl_ddb_entry_size(ddb)) {
5105 drm_WARN_ON(&dev_priv->drm,
5106 wm->wm[level].min_ddb_alloc != U16_MAX);
5113 blocks += wm->wm[level].min_ddb_alloc;
5114 blocks += wm->uv_wm[level].min_ddb_alloc;
5117 if (blocks <= iter.size) {
5118 iter.size -= blocks;
5124 drm_dbg_kms(&dev_priv->drm,
5125 "Requested display configuration exceeds system DDB limitations");
5126 drm_dbg_kms(&dev_priv->drm, "minimum required %d/%d\n",
5131 /* avoid the WARN later when we don't allocate any extra DDB */
5132 if (iter.data_rate == 0)
5136 * Grant each plane the blocks it requires at the highest achievable
5137 * watermark level, plus an extra share of the leftover blocks
5138 * proportional to its relative data rate.
5140 for_each_plane_id_on_crtc(crtc, plane_id) {
5141 struct skl_ddb_entry *ddb =
5142 &crtc_state->wm.skl.plane_ddb[plane_id];
5143 struct skl_ddb_entry *ddb_y =
5144 &crtc_state->wm.skl.plane_ddb_y[plane_id];
5145 const struct skl_plane_wm *wm =
5146 &crtc_state->wm.skl.optimal.planes[plane_id];
5148 if (plane_id == PLANE_CURSOR)
5151 if (DISPLAY_VER(dev_priv) < 11 &&
5152 crtc_state->nv12_planes & BIT(plane_id)) {
5153 skl_allocate_plane_ddb(&iter, ddb_y, &wm->wm[level],
5154 crtc_state->rel_data_rate_y[plane_id]);
5155 skl_allocate_plane_ddb(&iter, ddb, &wm->uv_wm[level],
5156 crtc_state->rel_data_rate[plane_id]);
5158 skl_allocate_plane_ddb(&iter, ddb, &wm->wm[level],
5159 crtc_state->rel_data_rate[plane_id]);
5162 drm_WARN_ON(&dev_priv->drm, iter.size != 0 || iter.data_rate != 0);
5165 * When we calculated watermark values we didn't know how high
5166 * of a level we'd actually be able to hit, so we just marked
5167 * all levels as "enabled." Go back now and disable the ones
5168 * that aren't actually possible.
5170 for (level++; level <= ilk_wm_max_level(dev_priv); level++) {
5171 for_each_plane_id_on_crtc(crtc, plane_id) {
5172 const struct skl_ddb_entry *ddb =
5173 &crtc_state->wm.skl.plane_ddb[plane_id];
5174 const struct skl_ddb_entry *ddb_y =
5175 &crtc_state->wm.skl.plane_ddb_y[plane_id];
5176 struct skl_plane_wm *wm =
5177 &crtc_state->wm.skl.optimal.planes[plane_id];
5179 if (DISPLAY_VER(dev_priv) < 11 &&
5180 crtc_state->nv12_planes & BIT(plane_id))
5181 skl_check_nv12_wm_level(&wm->wm[level],
5185 skl_check_wm_level(&wm->wm[level], ddb);
5187 if (icl_need_wm1_wa(dev_priv, plane_id) &&
5188 level == 1 && wm->wm[0].enable) {
5189 wm->wm[level].blocks = wm->wm[0].blocks;
5190 wm->wm[level].lines = wm->wm[0].lines;
5191 wm->wm[level].ignore_lines = wm->wm[0].ignore_lines;
5197 * Go back and disable the transition and SAGV watermarks
5198 * if it turns out we don't have enough DDB blocks for them.
5200 for_each_plane_id_on_crtc(crtc, plane_id) {
5201 const struct skl_ddb_entry *ddb =
5202 &crtc_state->wm.skl.plane_ddb[plane_id];
5203 const struct skl_ddb_entry *ddb_y =
5204 &crtc_state->wm.skl.plane_ddb_y[plane_id];
5205 struct skl_plane_wm *wm =
5206 &crtc_state->wm.skl.optimal.planes[plane_id];
5208 if (DISPLAY_VER(dev_priv) < 11 &&
5209 crtc_state->nv12_planes & BIT(plane_id)) {
5210 skl_check_wm_level(&wm->trans_wm, ddb_y);
5212 WARN_ON(skl_ddb_entry_size(ddb_y));
5214 skl_check_wm_level(&wm->trans_wm, ddb);
5217 skl_check_wm_level(&wm->sagv.wm0, ddb);
5218 skl_check_wm_level(&wm->sagv.trans_wm, ddb);
5225 * The max latency should be 257 (max the punit can code is 255 and we add 2us
5226 * for the read latency) and cpp should always be <= 8, so that
5227 * should allow pixel_rate up to ~2 GHz which seems sufficient since max
5228 * 2xcdclk is 1350 MHz and the pixel rate should never exceed that.
5230 static uint_fixed_16_16_t
5231 skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate,
5232 u8 cpp, u32 latency, u32 dbuf_block_size)
5234 u32 wm_intermediate_val;
5235 uint_fixed_16_16_t ret;
5238 return FP_16_16_MAX;
5240 wm_intermediate_val = latency * pixel_rate * cpp;
5241 ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size);
5243 if (DISPLAY_VER(dev_priv) >= 10)
5244 ret = add_fixed16_u32(ret, 1);
5249 static uint_fixed_16_16_t
5250 skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency,
5251 uint_fixed_16_16_t plane_blocks_per_line)
5253 u32 wm_intermediate_val;
5254 uint_fixed_16_16_t ret;
5257 return FP_16_16_MAX;
5259 wm_intermediate_val = latency * pixel_rate;
5260 wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val,
5261 pipe_htotal * 1000);
5262 ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line);
5266 static uint_fixed_16_16_t
5267 intel_get_linetime_us(const struct intel_crtc_state *crtc_state)
5269 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5272 uint_fixed_16_16_t linetime_us;
5274 if (!crtc_state->hw.active)
5275 return u32_to_fixed16(0);
5277 pixel_rate = crtc_state->pixel_rate;
5279 if (drm_WARN_ON(&dev_priv->drm, pixel_rate == 0))
5280 return u32_to_fixed16(0);
5282 crtc_htotal = crtc_state->hw.pipe_mode.crtc_htotal;
5283 linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate);
5289 skl_compute_wm_params(const struct intel_crtc_state *crtc_state,
5290 int width, const struct drm_format_info *format,
5291 u64 modifier, unsigned int rotation,
5292 u32 plane_pixel_rate, struct skl_wm_params *wp,
5295 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5296 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5299 /* only planar format has two planes */
5300 if (color_plane == 1 &&
5301 !intel_format_info_is_yuv_semiplanar(format, modifier)) {
5302 drm_dbg_kms(&dev_priv->drm,
5303 "Non planar format have single plane\n");
5307 wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED ||
5308 modifier == I915_FORMAT_MOD_4_TILED ||
5309 modifier == I915_FORMAT_MOD_Yf_TILED ||
5310 modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
5311 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
5312 wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED;
5313 wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
5314 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
5315 wp->is_planar = intel_format_info_is_yuv_semiplanar(format, modifier);
5318 if (color_plane == 1 && wp->is_planar)
5321 wp->cpp = format->cpp[color_plane];
5322 wp->plane_pixel_rate = plane_pixel_rate;
5324 if (DISPLAY_VER(dev_priv) >= 11 &&
5325 modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1)
5326 wp->dbuf_block_size = 256;
5328 wp->dbuf_block_size = 512;
5330 if (drm_rotation_90_or_270(rotation)) {
5333 wp->y_min_scanlines = 16;
5336 wp->y_min_scanlines = 8;
5339 wp->y_min_scanlines = 4;
5342 MISSING_CASE(wp->cpp);
5346 wp->y_min_scanlines = 4;
5349 if (skl_needs_memory_bw_wa(dev_priv))
5350 wp->y_min_scanlines *= 2;
5352 wp->plane_bytes_per_line = wp->width * wp->cpp;
5354 interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line *
5355 wp->y_min_scanlines,
5356 wp->dbuf_block_size);
5358 if (DISPLAY_VER(dev_priv) >= 10)
5361 wp->plane_blocks_per_line = div_fixed16(interm_pbpl,
5362 wp->y_min_scanlines);
5364 interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line,
5365 wp->dbuf_block_size);
5367 if (!wp->x_tiled || DISPLAY_VER(dev_priv) >= 10)
5370 wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl);
5373 wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines,
5374 wp->plane_blocks_per_line);
5376 wp->linetime_us = fixed16_to_u32_round_up(
5377 intel_get_linetime_us(crtc_state));
5383 skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state,
5384 const struct intel_plane_state *plane_state,
5385 struct skl_wm_params *wp, int color_plane)
5387 const struct drm_framebuffer *fb = plane_state->hw.fb;
5391 * Src coordinates are already rotated by 270 degrees for
5392 * the 90/270 degree plane rotation cases (to match the
5393 * GTT mapping), hence no need to account for rotation here.
5395 width = drm_rect_width(&plane_state->uapi.src) >> 16;
5397 return skl_compute_wm_params(crtc_state, width,
5398 fb->format, fb->modifier,
5399 plane_state->hw.rotation,
5400 intel_plane_pixel_rate(crtc_state, plane_state),
5404 static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level)
5406 if (DISPLAY_VER(dev_priv) >= 10)
5409 /* The number of lines are ignored for the level 0 watermark. */
5413 static int skl_wm_max_lines(struct drm_i915_private *dev_priv)
5415 if (DISPLAY_VER(dev_priv) >= 13)
5421 static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state,
5422 struct intel_plane *plane,
5424 unsigned int latency,
5425 const struct skl_wm_params *wp,
5426 const struct skl_wm_level *result_prev,
5427 struct skl_wm_level *result /* out */)
5429 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5430 uint_fixed_16_16_t method1, method2;
5431 uint_fixed_16_16_t selected_result;
5432 u32 blocks, lines, min_ddb_alloc = 0;
5435 (use_minimal_wm0_only(crtc_state, plane) && level > 0)) {
5437 result->min_ddb_alloc = U16_MAX;
5442 * WaIncreaseLatencyIPCEnabled: kbl,cfl
5443 * Display WA #1141: kbl,cfl
5445 if ((IS_KABYLAKE(dev_priv) ||
5446 IS_COFFEELAKE(dev_priv) ||
5447 IS_COMETLAKE(dev_priv)) &&
5448 dev_priv->ipc_enabled)
5451 if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled)
5454 method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate,
5455 wp->cpp, latency, wp->dbuf_block_size);
5456 method2 = skl_wm_method2(wp->plane_pixel_rate,
5457 crtc_state->hw.pipe_mode.crtc_htotal,
5459 wp->plane_blocks_per_line);
5462 selected_result = max_fixed16(method2, wp->y_tile_minimum);
5464 if ((wp->cpp * crtc_state->hw.pipe_mode.crtc_htotal /
5465 wp->dbuf_block_size < 1) &&
5466 (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) {
5467 selected_result = method2;
5468 } else if (latency >= wp->linetime_us) {
5469 if (DISPLAY_VER(dev_priv) == 9)
5470 selected_result = min_fixed16(method1, method2);
5472 selected_result = method2;
5474 selected_result = method1;
5478 blocks = fixed16_to_u32_round_up(selected_result) + 1;
5480 * Lets have blocks at minimum equivalent to plane_blocks_per_line
5481 * as there will be at minimum one line for lines configuration. This
5482 * is a work around for FIFO underruns observed with resolutions like
5483 * 4k 60 Hz in single channel DRAM configurations.
5485 * As per the Bspec 49325, if the ddb allocation can hold at least
5486 * one plane_blocks_per_line, we should have selected method2 in
5487 * the above logic. Assuming that modern versions have enough dbuf
5488 * and method2 guarantees blocks equivalent to at least 1 line,
5489 * select the blocks as plane_blocks_per_line.
5491 * TODO: Revisit the logic when we have better understanding on DRAM
5492 * channels' impact on the level 0 memory latency and the relevant
5495 if (skl_wm_has_lines(dev_priv, level))
5496 blocks = max(blocks,
5497 fixed16_to_u32_round_up(wp->plane_blocks_per_line));
5498 lines = div_round_up_fixed16(selected_result,
5499 wp->plane_blocks_per_line);
5501 if (DISPLAY_VER(dev_priv) == 9) {
5502 /* Display WA #1125: skl,bxt,kbl */
5503 if (level == 0 && wp->rc_surface)
5504 blocks += fixed16_to_u32_round_up(wp->y_tile_minimum);
5506 /* Display WA #1126: skl,bxt,kbl */
5507 if (level >= 1 && level <= 7) {
5509 blocks += fixed16_to_u32_round_up(wp->y_tile_minimum);
5510 lines += wp->y_min_scanlines;
5516 * Make sure result blocks for higher latency levels are
5517 * atleast as high as level below the current level.
5518 * Assumption in DDB algorithm optimization for special
5519 * cases. Also covers Display WA #1125 for RC.
5521 if (result_prev->blocks > blocks)
5522 blocks = result_prev->blocks;
5526 if (DISPLAY_VER(dev_priv) >= 11) {
5530 if (lines % wp->y_min_scanlines == 0)
5531 extra_lines = wp->y_min_scanlines;
5533 extra_lines = wp->y_min_scanlines * 2 -
5534 lines % wp->y_min_scanlines;
5536 min_ddb_alloc = mul_round_up_u32_fixed16(lines + extra_lines,
5537 wp->plane_blocks_per_line);
5539 min_ddb_alloc = blocks + DIV_ROUND_UP(blocks, 10);
5543 if (!skl_wm_has_lines(dev_priv, level))
5546 if (lines > skl_wm_max_lines(dev_priv)) {
5548 result->min_ddb_alloc = U16_MAX;
5553 * If lines is valid, assume we can use this watermark level
5554 * for now. We'll come back and disable it after we calculate the
5555 * DDB allocation if it turns out we don't actually have enough
5556 * blocks to satisfy it.
5558 result->blocks = blocks;
5559 result->lines = lines;
5560 /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */
5561 result->min_ddb_alloc = max(min_ddb_alloc, blocks) + 1;
5562 result->enable = true;
5564 if (DISPLAY_VER(dev_priv) < 12 && dev_priv->sagv_block_time_us)
5565 result->can_sagv = latency >= dev_priv->sagv_block_time_us;
5569 skl_compute_wm_levels(const struct intel_crtc_state *crtc_state,
5570 struct intel_plane *plane,
5571 const struct skl_wm_params *wm_params,
5572 struct skl_wm_level *levels)
5574 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5575 int level, max_level = ilk_wm_max_level(dev_priv);
5576 struct skl_wm_level *result_prev = &levels[0];
5578 for (level = 0; level <= max_level; level++) {
5579 struct skl_wm_level *result = &levels[level];
5580 unsigned int latency = dev_priv->wm.skl_latency[level];
5582 skl_compute_plane_wm(crtc_state, plane, level, latency,
5583 wm_params, result_prev, result);
5585 result_prev = result;
5589 static void tgl_compute_sagv_wm(const struct intel_crtc_state *crtc_state,
5590 struct intel_plane *plane,
5591 const struct skl_wm_params *wm_params,
5592 struct skl_plane_wm *plane_wm)
5594 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5595 struct skl_wm_level *sagv_wm = &plane_wm->sagv.wm0;
5596 struct skl_wm_level *levels = plane_wm->wm;
5597 unsigned int latency = 0;
5599 if (dev_priv->sagv_block_time_us)
5600 latency = dev_priv->sagv_block_time_us + dev_priv->wm.skl_latency[0];
5602 skl_compute_plane_wm(crtc_state, plane, 0, latency,
5603 wm_params, &levels[0],
5607 static void skl_compute_transition_wm(struct drm_i915_private *dev_priv,
5608 struct skl_wm_level *trans_wm,
5609 const struct skl_wm_level *wm0,
5610 const struct skl_wm_params *wp)
5612 u16 trans_min, trans_amount, trans_y_tile_min;
5613 u16 wm0_blocks, trans_offset, blocks;
5615 /* Transition WM don't make any sense if ipc is disabled */
5616 if (!dev_priv->ipc_enabled)
5620 * WaDisableTWM:skl,kbl,cfl,bxt
5621 * Transition WM are not recommended by HW team for GEN9
5623 if (DISPLAY_VER(dev_priv) == 9)
5626 if (DISPLAY_VER(dev_priv) >= 11)
5631 /* Display WA #1140: glk,cnl */
5632 if (DISPLAY_VER(dev_priv) == 10)
5635 trans_amount = 10; /* This is configurable amount */
5637 trans_offset = trans_min + trans_amount;
5640 * The spec asks for Selected Result Blocks for wm0 (the real value),
5641 * not Result Blocks (the integer value). Pay attention to the capital
5642 * letters. The value wm_l0->blocks is actually Result Blocks, but
5643 * since Result Blocks is the ceiling of Selected Result Blocks plus 1,
5644 * and since we later will have to get the ceiling of the sum in the
5645 * transition watermarks calculation, we can just pretend Selected
5646 * Result Blocks is Result Blocks minus 1 and it should work for the
5647 * current platforms.
5649 wm0_blocks = wm0->blocks - 1;
5653 (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum);
5654 blocks = max(wm0_blocks, trans_y_tile_min) + trans_offset;
5656 blocks = wm0_blocks + trans_offset;
5661 * Just assume we can enable the transition watermark. After
5662 * computing the DDB we'll come back and disable it if that
5663 * assumption turns out to be false.
5665 trans_wm->blocks = blocks;
5666 trans_wm->min_ddb_alloc = max_t(u16, wm0->min_ddb_alloc, blocks + 1);
5667 trans_wm->enable = true;
5670 static int skl_build_plane_wm_single(struct intel_crtc_state *crtc_state,
5671 const struct intel_plane_state *plane_state,
5672 struct intel_plane *plane, int color_plane)
5674 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5675 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5676 struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane->id];
5677 struct skl_wm_params wm_params;
5680 ret = skl_compute_plane_wm_params(crtc_state, plane_state,
5681 &wm_params, color_plane);
5685 skl_compute_wm_levels(crtc_state, plane, &wm_params, wm->wm);
5687 skl_compute_transition_wm(dev_priv, &wm->trans_wm,
5688 &wm->wm[0], &wm_params);
5690 if (DISPLAY_VER(dev_priv) >= 12) {
5691 tgl_compute_sagv_wm(crtc_state, plane, &wm_params, wm);
5693 skl_compute_transition_wm(dev_priv, &wm->sagv.trans_wm,
5694 &wm->sagv.wm0, &wm_params);
5700 static int skl_build_plane_wm_uv(struct intel_crtc_state *crtc_state,
5701 const struct intel_plane_state *plane_state,
5702 struct intel_plane *plane)
5704 struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane->id];
5705 struct skl_wm_params wm_params;
5708 wm->is_planar = true;
5710 /* uv plane watermarks must also be validated for NV12/Planar */
5711 ret = skl_compute_plane_wm_params(crtc_state, plane_state,
5716 skl_compute_wm_levels(crtc_state, plane, &wm_params, wm->uv_wm);
5721 static int skl_build_plane_wm(struct intel_crtc_state *crtc_state,
5722 const struct intel_plane_state *plane_state)
5724 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
5725 enum plane_id plane_id = plane->id;
5726 struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id];
5727 const struct drm_framebuffer *fb = plane_state->hw.fb;
5730 memset(wm, 0, sizeof(*wm));
5732 if (!intel_wm_plane_visible(crtc_state, plane_state))
5735 ret = skl_build_plane_wm_single(crtc_state, plane_state,
5740 if (fb->format->is_yuv && fb->format->num_planes > 1) {
5741 ret = skl_build_plane_wm_uv(crtc_state, plane_state,
5750 static int icl_build_plane_wm(struct intel_crtc_state *crtc_state,
5751 const struct intel_plane_state *plane_state)
5753 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
5754 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
5755 enum plane_id plane_id = plane->id;
5756 struct skl_plane_wm *wm = &crtc_state->wm.skl.raw.planes[plane_id];
5759 /* Watermarks calculated in master */
5760 if (plane_state->planar_slave)
5763 memset(wm, 0, sizeof(*wm));
5765 if (plane_state->planar_linked_plane) {
5766 const struct drm_framebuffer *fb = plane_state->hw.fb;
5768 drm_WARN_ON(&dev_priv->drm,
5769 !intel_wm_plane_visible(crtc_state, plane_state));
5770 drm_WARN_ON(&dev_priv->drm, !fb->format->is_yuv ||
5771 fb->format->num_planes == 1);
5773 ret = skl_build_plane_wm_single(crtc_state, plane_state,
5774 plane_state->planar_linked_plane, 0);
5778 ret = skl_build_plane_wm_single(crtc_state, plane_state,
5782 } else if (intel_wm_plane_visible(crtc_state, plane_state)) {
5783 ret = skl_build_plane_wm_single(crtc_state, plane_state,
5792 static int skl_build_pipe_wm(struct intel_atomic_state *state,
5793 struct intel_crtc *crtc)
5795 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5796 struct intel_crtc_state *crtc_state =
5797 intel_atomic_get_new_crtc_state(state, crtc);
5798 const struct intel_plane_state *plane_state;
5799 struct intel_plane *plane;
5802 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
5804 * FIXME should perhaps check {old,new}_plane_crtc->hw.crtc
5805 * instead but we don't populate that correctly for NV12 Y
5806 * planes so for now hack this.
5808 if (plane->pipe != crtc->pipe)
5811 if (DISPLAY_VER(dev_priv) >= 11)
5812 ret = icl_build_plane_wm(crtc_state, plane_state);
5814 ret = skl_build_plane_wm(crtc_state, plane_state);
5819 crtc_state->wm.skl.optimal = crtc_state->wm.skl.raw;
5824 static void skl_ddb_entry_write(struct drm_i915_private *dev_priv,
5826 const struct skl_ddb_entry *entry)
5829 intel_de_write_fw(dev_priv, reg,
5830 PLANE_BUF_END(entry->end - 1) |
5831 PLANE_BUF_START(entry->start));
5833 intel_de_write_fw(dev_priv, reg, 0);
5836 static void skl_write_wm_level(struct drm_i915_private *dev_priv,
5838 const struct skl_wm_level *level)
5844 if (level->ignore_lines)
5845 val |= PLANE_WM_IGNORE_LINES;
5846 val |= REG_FIELD_PREP(PLANE_WM_BLOCKS_MASK, level->blocks);
5847 val |= REG_FIELD_PREP(PLANE_WM_LINES_MASK, level->lines);
5849 intel_de_write_fw(dev_priv, reg, val);
5852 void skl_write_plane_wm(struct intel_plane *plane,
5853 const struct intel_crtc_state *crtc_state)
5855 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
5856 int level, max_level = ilk_wm_max_level(dev_priv);
5857 enum plane_id plane_id = plane->id;
5858 enum pipe pipe = plane->pipe;
5859 const struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal;
5860 const struct skl_ddb_entry *ddb =
5861 &crtc_state->wm.skl.plane_ddb[plane_id];
5862 const struct skl_ddb_entry *ddb_y =
5863 &crtc_state->wm.skl.plane_ddb_y[plane_id];
5865 for (level = 0; level <= max_level; level++)
5866 skl_write_wm_level(dev_priv, PLANE_WM(pipe, plane_id, level),
5867 skl_plane_wm_level(pipe_wm, plane_id, level));
5869 skl_write_wm_level(dev_priv, PLANE_WM_TRANS(pipe, plane_id),
5870 skl_plane_trans_wm(pipe_wm, plane_id));
5872 if (HAS_HW_SAGV_WM(dev_priv)) {
5873 const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id];
5875 skl_write_wm_level(dev_priv, PLANE_WM_SAGV(pipe, plane_id),
5877 skl_write_wm_level(dev_priv, PLANE_WM_SAGV_TRANS(pipe, plane_id),
5878 &wm->sagv.trans_wm);
5881 skl_ddb_entry_write(dev_priv,
5882 PLANE_BUF_CFG(pipe, plane_id), ddb);
5884 if (DISPLAY_VER(dev_priv) < 11)
5885 skl_ddb_entry_write(dev_priv,
5886 PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_y);
5889 void skl_write_cursor_wm(struct intel_plane *plane,
5890 const struct intel_crtc_state *crtc_state)
5892 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
5893 int level, max_level = ilk_wm_max_level(dev_priv);
5894 enum plane_id plane_id = plane->id;
5895 enum pipe pipe = plane->pipe;
5896 const struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal;
5897 const struct skl_ddb_entry *ddb =
5898 &crtc_state->wm.skl.plane_ddb[plane_id];
5900 for (level = 0; level <= max_level; level++)
5901 skl_write_wm_level(dev_priv, CUR_WM(pipe, level),
5902 skl_plane_wm_level(pipe_wm, plane_id, level));
5904 skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe),
5905 skl_plane_trans_wm(pipe_wm, plane_id));
5907 if (HAS_HW_SAGV_WM(dev_priv)) {
5908 const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id];
5910 skl_write_wm_level(dev_priv, CUR_WM_SAGV(pipe),
5912 skl_write_wm_level(dev_priv, CUR_WM_SAGV_TRANS(pipe),
5913 &wm->sagv.trans_wm);
5916 skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb);
5919 static bool skl_wm_level_equals(const struct skl_wm_level *l1,
5920 const struct skl_wm_level *l2)
5922 return l1->enable == l2->enable &&
5923 l1->ignore_lines == l2->ignore_lines &&
5924 l1->lines == l2->lines &&
5925 l1->blocks == l2->blocks;
5928 static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv,
5929 const struct skl_plane_wm *wm1,
5930 const struct skl_plane_wm *wm2)
5932 int level, max_level = ilk_wm_max_level(dev_priv);
5934 for (level = 0; level <= max_level; level++) {
5936 * We don't check uv_wm as the hardware doesn't actually
5937 * use it. It only gets used for calculating the required
5940 if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level]))
5944 return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm) &&
5945 skl_wm_level_equals(&wm1->sagv.wm0, &wm2->sagv.wm0) &&
5946 skl_wm_level_equals(&wm1->sagv.trans_wm, &wm2->sagv.trans_wm);
5949 static bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a,
5950 const struct skl_ddb_entry *b)
5952 return a->start < b->end && b->start < a->end;
5955 static void skl_ddb_entry_union(struct skl_ddb_entry *a,
5956 const struct skl_ddb_entry *b)
5958 if (a->end && b->end) {
5959 a->start = min(a->start, b->start);
5960 a->end = max(a->end, b->end);
5961 } else if (b->end) {
5962 a->start = b->start;
5967 bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb,
5968 const struct skl_ddb_entry *entries,
5969 int num_entries, int ignore_idx)
5973 for (i = 0; i < num_entries; i++) {
5974 if (i != ignore_idx &&
5975 skl_ddb_entries_overlap(ddb, &entries[i]))
5983 skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state,
5984 struct intel_crtc_state *new_crtc_state)
5986 struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->uapi.state);
5987 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
5988 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5989 struct intel_plane *plane;
5991 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5992 struct intel_plane_state *plane_state;
5993 enum plane_id plane_id = plane->id;
5995 if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb[plane_id],
5996 &new_crtc_state->wm.skl.plane_ddb[plane_id]) &&
5997 skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id],
5998 &new_crtc_state->wm.skl.plane_ddb_y[plane_id]))
6001 plane_state = intel_atomic_get_plane_state(state, plane);
6002 if (IS_ERR(plane_state))
6003 return PTR_ERR(plane_state);
6005 new_crtc_state->update_planes |= BIT(plane_id);
6011 static u8 intel_dbuf_enabled_slices(const struct intel_dbuf_state *dbuf_state)
6013 struct drm_i915_private *dev_priv = to_i915(dbuf_state->base.state->base.dev);
6018 * FIXME: For now we always enable slice S1 as per
6019 * the Bspec display initialization sequence.
6021 enabled_slices = BIT(DBUF_S1);
6023 for_each_pipe(dev_priv, pipe)
6024 enabled_slices |= dbuf_state->slices[pipe];
6026 return enabled_slices;
6030 skl_compute_ddb(struct intel_atomic_state *state)
6032 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6033 const struct intel_dbuf_state *old_dbuf_state;
6034 struct intel_dbuf_state *new_dbuf_state = NULL;
6035 const struct intel_crtc_state *old_crtc_state;
6036 struct intel_crtc_state *new_crtc_state;
6037 struct intel_crtc *crtc;
6040 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6041 new_dbuf_state = intel_atomic_get_dbuf_state(state);
6042 if (IS_ERR(new_dbuf_state))
6043 return PTR_ERR(new_dbuf_state);
6045 old_dbuf_state = intel_atomic_get_old_dbuf_state(state);
6049 if (!new_dbuf_state)
6052 new_dbuf_state->active_pipes =
6053 intel_calc_active_pipes(state, old_dbuf_state->active_pipes);
6055 if (old_dbuf_state->active_pipes != new_dbuf_state->active_pipes) {
6056 ret = intel_atomic_lock_global_state(&new_dbuf_state->base);
6061 if (HAS_MBUS_JOINING(dev_priv))
6062 new_dbuf_state->joined_mbus =
6063 adlp_check_mbus_joined(new_dbuf_state->active_pipes);
6065 for_each_intel_crtc(&dev_priv->drm, crtc) {
6066 enum pipe pipe = crtc->pipe;
6068 new_dbuf_state->slices[pipe] =
6069 skl_compute_dbuf_slices(crtc, new_dbuf_state->active_pipes,
6070 new_dbuf_state->joined_mbus);
6072 if (old_dbuf_state->slices[pipe] == new_dbuf_state->slices[pipe])
6075 ret = intel_atomic_lock_global_state(&new_dbuf_state->base);
6080 new_dbuf_state->enabled_slices = intel_dbuf_enabled_slices(new_dbuf_state);
6082 if (old_dbuf_state->enabled_slices != new_dbuf_state->enabled_slices ||
6083 old_dbuf_state->joined_mbus != new_dbuf_state->joined_mbus) {
6084 ret = intel_atomic_serialize_global_state(&new_dbuf_state->base);
6088 if (old_dbuf_state->joined_mbus != new_dbuf_state->joined_mbus) {
6089 /* TODO: Implement vblank synchronized MBUS joining changes */
6090 ret = intel_modeset_all_pipes(state);
6095 drm_dbg_kms(&dev_priv->drm,
6096 "Enabled dbuf slices 0x%x -> 0x%x (total dbuf slices 0x%x), mbus joined? %s->%s\n",
6097 old_dbuf_state->enabled_slices,
6098 new_dbuf_state->enabled_slices,
6099 INTEL_INFO(dev_priv)->display.dbuf.slice_mask,
6100 str_yes_no(old_dbuf_state->joined_mbus),
6101 str_yes_no(new_dbuf_state->joined_mbus));
6104 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6105 enum pipe pipe = crtc->pipe;
6107 new_dbuf_state->weight[pipe] = intel_crtc_ddb_weight(new_crtc_state);
6109 if (old_dbuf_state->weight[pipe] == new_dbuf_state->weight[pipe])
6112 ret = intel_atomic_lock_global_state(&new_dbuf_state->base);
6117 for_each_intel_crtc(&dev_priv->drm, crtc) {
6118 ret = skl_crtc_allocate_ddb(state, crtc);
6123 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6124 new_crtc_state, i) {
6125 ret = skl_crtc_allocate_plane_ddb(state, crtc);
6129 ret = skl_ddb_add_affected_planes(old_crtc_state,
6138 static char enast(bool enable)
6140 return enable ? '*' : ' ';
6144 skl_print_wm_changes(struct intel_atomic_state *state)
6146 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6147 const struct intel_crtc_state *old_crtc_state;
6148 const struct intel_crtc_state *new_crtc_state;
6149 struct intel_plane *plane;
6150 struct intel_crtc *crtc;
6153 if (!drm_debug_enabled(DRM_UT_KMS))
6156 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6157 new_crtc_state, i) {
6158 const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm;
6160 old_pipe_wm = &old_crtc_state->wm.skl.optimal;
6161 new_pipe_wm = &new_crtc_state->wm.skl.optimal;
6163 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
6164 enum plane_id plane_id = plane->id;
6165 const struct skl_ddb_entry *old, *new;
6167 old = &old_crtc_state->wm.skl.plane_ddb[plane_id];
6168 new = &new_crtc_state->wm.skl.plane_ddb[plane_id];
6170 if (skl_ddb_entry_equal(old, new))
6173 drm_dbg_kms(&dev_priv->drm,
6174 "[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n",
6175 plane->base.base.id, plane->base.name,
6176 old->start, old->end, new->start, new->end,
6177 skl_ddb_entry_size(old), skl_ddb_entry_size(new));
6180 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
6181 enum plane_id plane_id = plane->id;
6182 const struct skl_plane_wm *old_wm, *new_wm;
6184 old_wm = &old_pipe_wm->planes[plane_id];
6185 new_wm = &new_pipe_wm->planes[plane_id];
6187 if (skl_plane_wm_equals(dev_priv, old_wm, new_wm))
6190 drm_dbg_kms(&dev_priv->drm,
6191 "[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm,%cstwm"
6192 " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm,%cstwm\n",
6193 plane->base.base.id, plane->base.name,
6194 enast(old_wm->wm[0].enable), enast(old_wm->wm[1].enable),
6195 enast(old_wm->wm[2].enable), enast(old_wm->wm[3].enable),
6196 enast(old_wm->wm[4].enable), enast(old_wm->wm[5].enable),
6197 enast(old_wm->wm[6].enable), enast(old_wm->wm[7].enable),
6198 enast(old_wm->trans_wm.enable),
6199 enast(old_wm->sagv.wm0.enable),
6200 enast(old_wm->sagv.trans_wm.enable),
6201 enast(new_wm->wm[0].enable), enast(new_wm->wm[1].enable),
6202 enast(new_wm->wm[2].enable), enast(new_wm->wm[3].enable),
6203 enast(new_wm->wm[4].enable), enast(new_wm->wm[5].enable),
6204 enast(new_wm->wm[6].enable), enast(new_wm->wm[7].enable),
6205 enast(new_wm->trans_wm.enable),
6206 enast(new_wm->sagv.wm0.enable),
6207 enast(new_wm->sagv.trans_wm.enable));
6209 drm_dbg_kms(&dev_priv->drm,
6210 "[PLANE:%d:%s] lines %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%4d"
6211 " -> %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%4d\n",
6212 plane->base.base.id, plane->base.name,
6213 enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].lines,
6214 enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].lines,
6215 enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].lines,
6216 enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].lines,
6217 enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].lines,
6218 enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].lines,
6219 enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].lines,
6220 enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].lines,
6221 enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.lines,
6222 enast(old_wm->sagv.wm0.ignore_lines), old_wm->sagv.wm0.lines,
6223 enast(old_wm->sagv.trans_wm.ignore_lines), old_wm->sagv.trans_wm.lines,
6224 enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].lines,
6225 enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].lines,
6226 enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].lines,
6227 enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].lines,
6228 enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].lines,
6229 enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].lines,
6230 enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].lines,
6231 enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].lines,
6232 enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.lines,
6233 enast(new_wm->sagv.wm0.ignore_lines), new_wm->sagv.wm0.lines,
6234 enast(new_wm->sagv.trans_wm.ignore_lines), new_wm->sagv.trans_wm.lines);
6236 drm_dbg_kms(&dev_priv->drm,
6237 "[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d"
6238 " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d\n",
6239 plane->base.base.id, plane->base.name,
6240 old_wm->wm[0].blocks, old_wm->wm[1].blocks,
6241 old_wm->wm[2].blocks, old_wm->wm[3].blocks,
6242 old_wm->wm[4].blocks, old_wm->wm[5].blocks,
6243 old_wm->wm[6].blocks, old_wm->wm[7].blocks,
6244 old_wm->trans_wm.blocks,
6245 old_wm->sagv.wm0.blocks,
6246 old_wm->sagv.trans_wm.blocks,
6247 new_wm->wm[0].blocks, new_wm->wm[1].blocks,
6248 new_wm->wm[2].blocks, new_wm->wm[3].blocks,
6249 new_wm->wm[4].blocks, new_wm->wm[5].blocks,
6250 new_wm->wm[6].blocks, new_wm->wm[7].blocks,
6251 new_wm->trans_wm.blocks,
6252 new_wm->sagv.wm0.blocks,
6253 new_wm->sagv.trans_wm.blocks);
6255 drm_dbg_kms(&dev_priv->drm,
6256 "[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d"
6257 " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%5d\n",
6258 plane->base.base.id, plane->base.name,
6259 old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc,
6260 old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc,
6261 old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc,
6262 old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc,
6263 old_wm->trans_wm.min_ddb_alloc,
6264 old_wm->sagv.wm0.min_ddb_alloc,
6265 old_wm->sagv.trans_wm.min_ddb_alloc,
6266 new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc,
6267 new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc,
6268 new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc,
6269 new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc,
6270 new_wm->trans_wm.min_ddb_alloc,
6271 new_wm->sagv.wm0.min_ddb_alloc,
6272 new_wm->sagv.trans_wm.min_ddb_alloc);
6277 static bool skl_plane_selected_wm_equals(struct intel_plane *plane,
6278 const struct skl_pipe_wm *old_pipe_wm,
6279 const struct skl_pipe_wm *new_pipe_wm)
6281 struct drm_i915_private *i915 = to_i915(plane->base.dev);
6282 int level, max_level = ilk_wm_max_level(i915);
6284 for (level = 0; level <= max_level; level++) {
6286 * We don't check uv_wm as the hardware doesn't actually
6287 * use it. It only gets used for calculating the required
6290 if (!skl_wm_level_equals(skl_plane_wm_level(old_pipe_wm, plane->id, level),
6291 skl_plane_wm_level(new_pipe_wm, plane->id, level)))
6295 if (HAS_HW_SAGV_WM(i915)) {
6296 const struct skl_plane_wm *old_wm = &old_pipe_wm->planes[plane->id];
6297 const struct skl_plane_wm *new_wm = &new_pipe_wm->planes[plane->id];
6299 if (!skl_wm_level_equals(&old_wm->sagv.wm0, &new_wm->sagv.wm0) ||
6300 !skl_wm_level_equals(&old_wm->sagv.trans_wm, &new_wm->sagv.trans_wm))
6304 return skl_wm_level_equals(skl_plane_trans_wm(old_pipe_wm, plane->id),
6305 skl_plane_trans_wm(new_pipe_wm, plane->id));
6309 * To make sure the cursor watermark registers are always consistent
6310 * with our computed state the following scenario needs special
6314 * 2. move cursor entirely offscreen
6317 * Step 2. does call .disable_plane() but does not zero the watermarks
6318 * (since we consider an offscreen cursor still active for the purposes
6319 * of watermarks). Step 3. would not normally call .disable_plane()
6320 * because the actual plane visibility isn't changing, and we don't
6321 * deallocate the cursor ddb until the pipe gets disabled. So we must
6322 * force step 3. to call .disable_plane() to update the watermark
6323 * registers properly.
6325 * Other planes do not suffer from this issues as their watermarks are
6326 * calculated based on the actual plane visibility. The only time this
6327 * can trigger for the other planes is during the initial readout as the
6328 * default value of the watermarks registers is not zero.
6330 static int skl_wm_add_affected_planes(struct intel_atomic_state *state,
6331 struct intel_crtc *crtc)
6333 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6334 const struct intel_crtc_state *old_crtc_state =
6335 intel_atomic_get_old_crtc_state(state, crtc);
6336 struct intel_crtc_state *new_crtc_state =
6337 intel_atomic_get_new_crtc_state(state, crtc);
6338 struct intel_plane *plane;
6340 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
6341 struct intel_plane_state *plane_state;
6342 enum plane_id plane_id = plane->id;
6345 * Force a full wm update for every plane on modeset.
6346 * Required because the reset value of the wm registers
6347 * is non-zero, whereas we want all disabled planes to
6348 * have zero watermarks. So if we turn off the relevant
6349 * power well the hardware state will go out of sync
6350 * with the software state.
6352 if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) &&
6353 skl_plane_selected_wm_equals(plane,
6354 &old_crtc_state->wm.skl.optimal,
6355 &new_crtc_state->wm.skl.optimal))
6358 plane_state = intel_atomic_get_plane_state(state, plane);
6359 if (IS_ERR(plane_state))
6360 return PTR_ERR(plane_state);
6362 new_crtc_state->update_planes |= BIT(plane_id);
6369 skl_compute_wm(struct intel_atomic_state *state)
6371 struct intel_crtc *crtc;
6372 struct intel_crtc_state *new_crtc_state;
6375 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6376 ret = skl_build_pipe_wm(state, crtc);
6381 ret = skl_compute_ddb(state);
6385 ret = intel_compute_sagv_mask(state);
6390 * skl_compute_ddb() will have adjusted the final watermarks
6391 * based on how much ddb is available. Now we can actually
6392 * check if the final watermarks changed.
6394 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6395 ret = skl_wm_add_affected_planes(state, crtc);
6400 skl_print_wm_changes(state);
6405 static void ilk_compute_wm_config(struct drm_i915_private *dev_priv,
6406 struct intel_wm_config *config)
6408 struct intel_crtc *crtc;
6410 /* Compute the currently _active_ config */
6411 for_each_intel_crtc(&dev_priv->drm, crtc) {
6412 const struct intel_pipe_wm *wm = &crtc->wm.active.ilk;
6414 if (!wm->pipe_enabled)
6417 config->sprites_enabled |= wm->sprites_enabled;
6418 config->sprites_scaled |= wm->sprites_scaled;
6419 config->num_pipes_active++;
6423 static void ilk_program_watermarks(struct drm_i915_private *dev_priv)
6425 struct intel_pipe_wm lp_wm_1_2 = {}, lp_wm_5_6 = {}, *best_lp_wm;
6426 struct ilk_wm_maximums max;
6427 struct intel_wm_config config = {};
6428 struct ilk_wm_values results = {};
6429 enum intel_ddb_partitioning partitioning;
6431 ilk_compute_wm_config(dev_priv, &config);
6433 ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max);
6434 ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2);
6436 /* 5/6 split only in single pipe config on IVB+ */
6437 if (DISPLAY_VER(dev_priv) >= 7 &&
6438 config.num_pipes_active == 1 && config.sprites_enabled) {
6439 ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max);
6440 ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6);
6442 best_lp_wm = ilk_find_best_result(dev_priv, &lp_wm_1_2, &lp_wm_5_6);
6444 best_lp_wm = &lp_wm_1_2;
6447 partitioning = (best_lp_wm == &lp_wm_1_2) ?
6448 INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6;
6450 ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results);
6452 ilk_write_wm_values(dev_priv, &results);
6455 static void ilk_initial_watermarks(struct intel_atomic_state *state,
6456 struct intel_crtc *crtc)
6458 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6459 const struct intel_crtc_state *crtc_state =
6460 intel_atomic_get_new_crtc_state(state, crtc);
6462 mutex_lock(&dev_priv->wm.wm_mutex);
6463 crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate;
6464 ilk_program_watermarks(dev_priv);
6465 mutex_unlock(&dev_priv->wm.wm_mutex);
6468 static void ilk_optimize_watermarks(struct intel_atomic_state *state,
6469 struct intel_crtc *crtc)
6471 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6472 const struct intel_crtc_state *crtc_state =
6473 intel_atomic_get_new_crtc_state(state, crtc);
6475 if (!crtc_state->wm.need_postvbl_update)
6478 mutex_lock(&dev_priv->wm.wm_mutex);
6479 crtc->wm.active.ilk = crtc_state->wm.ilk.optimal;
6480 ilk_program_watermarks(dev_priv);
6481 mutex_unlock(&dev_priv->wm.wm_mutex);
6484 static void skl_wm_level_from_reg_val(u32 val, struct skl_wm_level *level)
6486 level->enable = val & PLANE_WM_EN;
6487 level->ignore_lines = val & PLANE_WM_IGNORE_LINES;
6488 level->blocks = REG_FIELD_GET(PLANE_WM_BLOCKS_MASK, val);
6489 level->lines = REG_FIELD_GET(PLANE_WM_LINES_MASK, val);
6492 static void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc,
6493 struct skl_pipe_wm *out)
6495 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6496 enum pipe pipe = crtc->pipe;
6497 int level, max_level;
6498 enum plane_id plane_id;
6501 max_level = ilk_wm_max_level(dev_priv);
6503 for_each_plane_id_on_crtc(crtc, plane_id) {
6504 struct skl_plane_wm *wm = &out->planes[plane_id];
6506 for (level = 0; level <= max_level; level++) {
6507 if (plane_id != PLANE_CURSOR)
6508 val = intel_uncore_read(&dev_priv->uncore, PLANE_WM(pipe, plane_id, level));
6510 val = intel_uncore_read(&dev_priv->uncore, CUR_WM(pipe, level));
6512 skl_wm_level_from_reg_val(val, &wm->wm[level]);
6515 if (plane_id != PLANE_CURSOR)
6516 val = intel_uncore_read(&dev_priv->uncore, PLANE_WM_TRANS(pipe, plane_id));
6518 val = intel_uncore_read(&dev_priv->uncore, CUR_WM_TRANS(pipe));
6520 skl_wm_level_from_reg_val(val, &wm->trans_wm);
6522 if (HAS_HW_SAGV_WM(dev_priv)) {
6523 if (plane_id != PLANE_CURSOR)
6524 val = intel_uncore_read(&dev_priv->uncore,
6525 PLANE_WM_SAGV(pipe, plane_id));
6527 val = intel_uncore_read(&dev_priv->uncore,
6530 skl_wm_level_from_reg_val(val, &wm->sagv.wm0);
6532 if (plane_id != PLANE_CURSOR)
6533 val = intel_uncore_read(&dev_priv->uncore,
6534 PLANE_WM_SAGV_TRANS(pipe, plane_id));
6536 val = intel_uncore_read(&dev_priv->uncore,
6537 CUR_WM_SAGV_TRANS(pipe));
6539 skl_wm_level_from_reg_val(val, &wm->sagv.trans_wm);
6540 } else if (DISPLAY_VER(dev_priv) >= 12) {
6541 wm->sagv.wm0 = wm->wm[0];
6542 wm->sagv.trans_wm = wm->trans_wm;
6547 void skl_wm_get_hw_state(struct drm_i915_private *dev_priv)
6549 struct intel_dbuf_state *dbuf_state =
6550 to_intel_dbuf_state(dev_priv->dbuf.obj.state);
6551 struct intel_crtc *crtc;
6553 if (HAS_MBUS_JOINING(dev_priv))
6554 dbuf_state->joined_mbus = intel_de_read(dev_priv, MBUS_CTL) & MBUS_JOIN;
6556 for_each_intel_crtc(&dev_priv->drm, crtc) {
6557 struct intel_crtc_state *crtc_state =
6558 to_intel_crtc_state(crtc->base.state);
6559 enum pipe pipe = crtc->pipe;
6560 unsigned int mbus_offset;
6561 enum plane_id plane_id;
6564 skl_pipe_wm_get_hw_state(crtc, &crtc_state->wm.skl.optimal);
6565 crtc_state->wm.skl.raw = crtc_state->wm.skl.optimal;
6567 memset(&dbuf_state->ddb[pipe], 0, sizeof(dbuf_state->ddb[pipe]));
6569 for_each_plane_id_on_crtc(crtc, plane_id) {
6570 struct skl_ddb_entry *ddb =
6571 &crtc_state->wm.skl.plane_ddb[plane_id];
6572 struct skl_ddb_entry *ddb_y =
6573 &crtc_state->wm.skl.plane_ddb_y[plane_id];
6575 skl_ddb_get_hw_plane_state(dev_priv, crtc->pipe,
6576 plane_id, ddb, ddb_y);
6578 skl_ddb_entry_union(&dbuf_state->ddb[pipe], ddb);
6579 skl_ddb_entry_union(&dbuf_state->ddb[pipe], ddb_y);
6582 dbuf_state->weight[pipe] = intel_crtc_ddb_weight(crtc_state);
6585 * Used for checking overlaps, so we need absolute
6586 * offsets instead of MBUS relative offsets.
6588 slices = skl_compute_dbuf_slices(crtc, dbuf_state->active_pipes,
6589 dbuf_state->joined_mbus);
6590 mbus_offset = mbus_ddb_offset(dev_priv, slices);
6591 crtc_state->wm.skl.ddb.start = mbus_offset + dbuf_state->ddb[pipe].start;
6592 crtc_state->wm.skl.ddb.end = mbus_offset + dbuf_state->ddb[pipe].end;
6594 /* The slices actually used by the planes on the pipe */
6595 dbuf_state->slices[pipe] =
6596 skl_ddb_dbuf_slice_mask(dev_priv, &crtc_state->wm.skl.ddb);
6598 drm_dbg_kms(&dev_priv->drm,
6599 "[CRTC:%d:%s] dbuf slices 0x%x, ddb (%d - %d), active pipes 0x%x, mbus joined: %s\n",
6600 crtc->base.base.id, crtc->base.name,
6601 dbuf_state->slices[pipe], dbuf_state->ddb[pipe].start,
6602 dbuf_state->ddb[pipe].end, dbuf_state->active_pipes,
6603 str_yes_no(dbuf_state->joined_mbus));
6606 dbuf_state->enabled_slices = dev_priv->dbuf.enabled_slices;
6609 static bool skl_dbuf_is_misconfigured(struct drm_i915_private *i915)
6611 const struct intel_dbuf_state *dbuf_state =
6612 to_intel_dbuf_state(i915->dbuf.obj.state);
6613 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
6614 struct intel_crtc *crtc;
6616 for_each_intel_crtc(&i915->drm, crtc) {
6617 const struct intel_crtc_state *crtc_state =
6618 to_intel_crtc_state(crtc->base.state);
6620 entries[crtc->pipe] = crtc_state->wm.skl.ddb;
6623 for_each_intel_crtc(&i915->drm, crtc) {
6624 const struct intel_crtc_state *crtc_state =
6625 to_intel_crtc_state(crtc->base.state);
6628 slices = skl_compute_dbuf_slices(crtc, dbuf_state->active_pipes,
6629 dbuf_state->joined_mbus);
6630 if (dbuf_state->slices[crtc->pipe] & ~slices)
6633 if (skl_ddb_allocation_overlaps(&crtc_state->wm.skl.ddb, entries,
6634 I915_MAX_PIPES, crtc->pipe))
6641 void skl_wm_sanitize(struct drm_i915_private *i915)
6643 struct intel_crtc *crtc;
6646 * On TGL/RKL (at least) the BIOS likes to assign the planes
6647 * to the wrong DBUF slices. This will cause an infinite loop
6648 * in skl_commit_modeset_enables() as it can't find a way to
6649 * transition between the old bogus DBUF layout to the new
6650 * proper DBUF layout without DBUF allocation overlaps between
6651 * the planes (which cannot be allowed or else the hardware
6652 * may hang). If we detect a bogus DBUF layout just turn off
6653 * all the planes so that skl_commit_modeset_enables() can
6654 * simply ignore them.
6656 if (!skl_dbuf_is_misconfigured(i915))
6659 drm_dbg_kms(&i915->drm, "BIOS has misprogrammed the DBUF, disabling all planes\n");
6661 for_each_intel_crtc(&i915->drm, crtc) {
6662 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
6663 const struct intel_plane_state *plane_state =
6664 to_intel_plane_state(plane->base.state);
6665 struct intel_crtc_state *crtc_state =
6666 to_intel_crtc_state(crtc->base.state);
6668 if (plane_state->uapi.visible)
6669 intel_plane_disable_noatomic(crtc, plane);
6671 drm_WARN_ON(&i915->drm, crtc_state->active_planes != 0);
6673 memset(&crtc_state->wm.skl.ddb, 0, sizeof(crtc_state->wm.skl.ddb));
6677 static void ilk_pipe_wm_get_hw_state(struct intel_crtc *crtc)
6679 struct drm_device *dev = crtc->base.dev;
6680 struct drm_i915_private *dev_priv = to_i915(dev);
6681 struct ilk_wm_values *hw = &dev_priv->wm.hw;
6682 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
6683 struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal;
6684 enum pipe pipe = crtc->pipe;
6686 hw->wm_pipe[pipe] = intel_uncore_read(&dev_priv->uncore, WM0_PIPE_ILK(pipe));
6688 memset(active, 0, sizeof(*active));
6690 active->pipe_enabled = crtc->active;
6692 if (active->pipe_enabled) {
6693 u32 tmp = hw->wm_pipe[pipe];
6696 * For active pipes LP0 watermark is marked as
6697 * enabled, and LP1+ watermaks as disabled since
6698 * we can't really reverse compute them in case
6699 * multiple pipes are active.
6701 active->wm[0].enable = true;
6702 active->wm[0].pri_val = REG_FIELD_GET(WM0_PIPE_PRIMARY_MASK, tmp);
6703 active->wm[0].spr_val = REG_FIELD_GET(WM0_PIPE_SPRITE_MASK, tmp);
6704 active->wm[0].cur_val = REG_FIELD_GET(WM0_PIPE_CURSOR_MASK, tmp);
6706 int level, max_level = ilk_wm_max_level(dev_priv);
6709 * For inactive pipes, all watermark levels
6710 * should be marked as enabled but zeroed,
6711 * which is what we'd compute them to.
6713 for (level = 0; level <= max_level; level++)
6714 active->wm[level].enable = true;
6717 crtc->wm.active.ilk = *active;
6720 #define _FW_WM(value, plane) \
6721 (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT)
6722 #define _FW_WM_VLV(value, plane) \
6723 (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT)
6725 static void g4x_read_wm_values(struct drm_i915_private *dev_priv,
6726 struct g4x_wm_values *wm)
6730 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW1);
6731 wm->sr.plane = _FW_WM(tmp, SR);
6732 wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB);
6733 wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB);
6734 wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA);
6736 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW2);
6737 wm->fbc_en = tmp & DSPFW_FBC_SR_EN;
6738 wm->sr.fbc = _FW_WM(tmp, FBC_SR);
6739 wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR);
6740 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB);
6741 wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA);
6742 wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA);
6744 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW3);
6745 wm->hpll_en = tmp & DSPFW_HPLL_SR_EN;
6746 wm->sr.cursor = _FW_WM(tmp, CURSOR_SR);
6747 wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR);
6748 wm->hpll.plane = _FW_WM(tmp, HPLL_SR);
6751 static void vlv_read_wm_values(struct drm_i915_private *dev_priv,
6752 struct vlv_wm_values *wm)
6757 for_each_pipe(dev_priv, pipe) {
6758 tmp = intel_uncore_read(&dev_priv->uncore, VLV_DDL(pipe));
6760 wm->ddl[pipe].plane[PLANE_PRIMARY] =
6761 (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
6762 wm->ddl[pipe].plane[PLANE_CURSOR] =
6763 (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
6764 wm->ddl[pipe].plane[PLANE_SPRITE0] =
6765 (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
6766 wm->ddl[pipe].plane[PLANE_SPRITE1] =
6767 (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
6770 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW1);
6771 wm->sr.plane = _FW_WM(tmp, SR);
6772 wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB);
6773 wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB);
6774 wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEA);
6776 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW2);
6777 wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB);
6778 wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA);
6779 wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEA);
6781 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW3);
6782 wm->sr.cursor = _FW_WM(tmp, CURSOR_SR);
6784 if (IS_CHERRYVIEW(dev_priv)) {
6785 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW7_CHV);
6786 wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED);
6787 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEC);
6789 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW8_CHV);
6790 wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF);
6791 wm->pipe[PIPE_C].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEE);
6793 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW9_CHV);
6794 wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC);
6795 wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC);
6797 tmp = intel_uncore_read(&dev_priv->uncore, DSPHOWM);
6798 wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9;
6799 wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8;
6800 wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8;
6801 wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8;
6802 wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8;
6803 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8;
6804 wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8;
6805 wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8;
6806 wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8;
6807 wm->pipe[PIPE_A].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEA_HI) << 8;
6809 tmp = intel_uncore_read(&dev_priv->uncore, DSPFW7);
6810 wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED);
6811 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEC);
6813 tmp = intel_uncore_read(&dev_priv->uncore, DSPHOWM);
6814 wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9;
6815 wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8;
6816 wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8;
6817 wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8;
6818 wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8;
6819 wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8;
6820 wm->pipe[PIPE_A].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEA_HI) << 8;
6827 void g4x_wm_get_hw_state(struct drm_i915_private *dev_priv)
6829 struct g4x_wm_values *wm = &dev_priv->wm.g4x;
6830 struct intel_crtc *crtc;
6832 g4x_read_wm_values(dev_priv, wm);
6834 wm->cxsr = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF) & FW_BLC_SELF_EN;
6836 for_each_intel_crtc(&dev_priv->drm, crtc) {
6837 struct intel_crtc_state *crtc_state =
6838 to_intel_crtc_state(crtc->base.state);
6839 struct g4x_wm_state *active = &crtc->wm.active.g4x;
6840 struct g4x_pipe_wm *raw;
6841 enum pipe pipe = crtc->pipe;
6842 enum plane_id plane_id;
6843 int level, max_level;
6845 active->cxsr = wm->cxsr;
6846 active->hpll_en = wm->hpll_en;
6847 active->fbc_en = wm->fbc_en;
6849 active->sr = wm->sr;
6850 active->hpll = wm->hpll;
6852 for_each_plane_id_on_crtc(crtc, plane_id) {
6853 active->wm.plane[plane_id] =
6854 wm->pipe[pipe].plane[plane_id];
6857 if (wm->cxsr && wm->hpll_en)
6858 max_level = G4X_WM_LEVEL_HPLL;
6860 max_level = G4X_WM_LEVEL_SR;
6862 max_level = G4X_WM_LEVEL_NORMAL;
6864 level = G4X_WM_LEVEL_NORMAL;
6865 raw = &crtc_state->wm.g4x.raw[level];
6866 for_each_plane_id_on_crtc(crtc, plane_id)
6867 raw->plane[plane_id] = active->wm.plane[plane_id];
6869 level = G4X_WM_LEVEL_SR;
6870 if (level > max_level)
6873 raw = &crtc_state->wm.g4x.raw[level];
6874 raw->plane[PLANE_PRIMARY] = active->sr.plane;
6875 raw->plane[PLANE_CURSOR] = active->sr.cursor;
6876 raw->plane[PLANE_SPRITE0] = 0;
6877 raw->fbc = active->sr.fbc;
6879 level = G4X_WM_LEVEL_HPLL;
6880 if (level > max_level)
6883 raw = &crtc_state->wm.g4x.raw[level];
6884 raw->plane[PLANE_PRIMARY] = active->hpll.plane;
6885 raw->plane[PLANE_CURSOR] = active->hpll.cursor;
6886 raw->plane[PLANE_SPRITE0] = 0;
6887 raw->fbc = active->hpll.fbc;
6891 for_each_plane_id_on_crtc(crtc, plane_id)
6892 g4x_raw_plane_wm_set(crtc_state, level,
6893 plane_id, USHRT_MAX);
6894 g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX);
6896 crtc_state->wm.g4x.optimal = *active;
6897 crtc_state->wm.g4x.intermediate = *active;
6899 drm_dbg_kms(&dev_priv->drm,
6900 "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n",
6902 wm->pipe[pipe].plane[PLANE_PRIMARY],
6903 wm->pipe[pipe].plane[PLANE_CURSOR],
6904 wm->pipe[pipe].plane[PLANE_SPRITE0]);
6907 drm_dbg_kms(&dev_priv->drm,
6908 "Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n",
6909 wm->sr.plane, wm->sr.cursor, wm->sr.fbc);
6910 drm_dbg_kms(&dev_priv->drm,
6911 "Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n",
6912 wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc);
6913 drm_dbg_kms(&dev_priv->drm, "Initial SR=%s HPLL=%s FBC=%s\n",
6914 str_yes_no(wm->cxsr), str_yes_no(wm->hpll_en),
6915 str_yes_no(wm->fbc_en));
6918 void g4x_wm_sanitize(struct drm_i915_private *dev_priv)
6920 struct intel_plane *plane;
6921 struct intel_crtc *crtc;
6923 mutex_lock(&dev_priv->wm.wm_mutex);
6925 for_each_intel_plane(&dev_priv->drm, plane) {
6926 struct intel_crtc *crtc =
6927 intel_crtc_for_pipe(dev_priv, plane->pipe);
6928 struct intel_crtc_state *crtc_state =
6929 to_intel_crtc_state(crtc->base.state);
6930 struct intel_plane_state *plane_state =
6931 to_intel_plane_state(plane->base.state);
6932 struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal;
6933 enum plane_id plane_id = plane->id;
6936 if (plane_state->uapi.visible)
6939 for (level = 0; level < 3; level++) {
6940 struct g4x_pipe_wm *raw =
6941 &crtc_state->wm.g4x.raw[level];
6943 raw->plane[plane_id] = 0;
6944 wm_state->wm.plane[plane_id] = 0;
6947 if (plane_id == PLANE_PRIMARY) {
6948 for (level = 0; level < 3; level++) {
6949 struct g4x_pipe_wm *raw =
6950 &crtc_state->wm.g4x.raw[level];
6954 wm_state->sr.fbc = 0;
6955 wm_state->hpll.fbc = 0;
6956 wm_state->fbc_en = false;
6960 for_each_intel_crtc(&dev_priv->drm, crtc) {
6961 struct intel_crtc_state *crtc_state =
6962 to_intel_crtc_state(crtc->base.state);
6964 crtc_state->wm.g4x.intermediate =
6965 crtc_state->wm.g4x.optimal;
6966 crtc->wm.active.g4x = crtc_state->wm.g4x.optimal;
6969 g4x_program_watermarks(dev_priv);
6971 mutex_unlock(&dev_priv->wm.wm_mutex);
6974 void vlv_wm_get_hw_state(struct drm_i915_private *dev_priv)
6976 struct vlv_wm_values *wm = &dev_priv->wm.vlv;
6977 struct intel_crtc *crtc;
6980 vlv_read_wm_values(dev_priv, wm);
6982 wm->cxsr = intel_uncore_read(&dev_priv->uncore, FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
6983 wm->level = VLV_WM_LEVEL_PM2;
6985 if (IS_CHERRYVIEW(dev_priv)) {
6986 vlv_punit_get(dev_priv);
6988 val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM);
6989 if (val & DSP_MAXFIFO_PM5_ENABLE)
6990 wm->level = VLV_WM_LEVEL_PM5;
6993 * If DDR DVFS is disabled in the BIOS, Punit
6994 * will never ack the request. So if that happens
6995 * assume we don't have to enable/disable DDR DVFS
6996 * dynamically. To test that just set the REQ_ACK
6997 * bit to poke the Punit, but don't change the
6998 * HIGH/LOW bits so that we don't actually change
6999 * the current state.
7001 val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
7002 val |= FORCE_DDR_FREQ_REQ_ACK;
7003 vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val);
7005 if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) &
7006 FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) {
7007 drm_dbg_kms(&dev_priv->drm,
7008 "Punit not acking DDR DVFS request, "
7009 "assuming DDR DVFS is disabled\n");
7010 dev_priv->wm.max_level = VLV_WM_LEVEL_PM5;
7012 val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
7013 if ((val & FORCE_DDR_HIGH_FREQ) == 0)
7014 wm->level = VLV_WM_LEVEL_DDR_DVFS;
7017 vlv_punit_put(dev_priv);
7020 for_each_intel_crtc(&dev_priv->drm, crtc) {
7021 struct intel_crtc_state *crtc_state =
7022 to_intel_crtc_state(crtc->base.state);
7023 struct vlv_wm_state *active = &crtc->wm.active.vlv;
7024 const struct vlv_fifo_state *fifo_state =
7025 &crtc_state->wm.vlv.fifo_state;
7026 enum pipe pipe = crtc->pipe;
7027 enum plane_id plane_id;
7030 vlv_get_fifo_size(crtc_state);
7032 active->num_levels = wm->level + 1;
7033 active->cxsr = wm->cxsr;
7035 for (level = 0; level < active->num_levels; level++) {
7036 struct g4x_pipe_wm *raw =
7037 &crtc_state->wm.vlv.raw[level];
7039 active->sr[level].plane = wm->sr.plane;
7040 active->sr[level].cursor = wm->sr.cursor;
7042 for_each_plane_id_on_crtc(crtc, plane_id) {
7043 active->wm[level].plane[plane_id] =
7044 wm->pipe[pipe].plane[plane_id];
7046 raw->plane[plane_id] =
7047 vlv_invert_wm_value(active->wm[level].plane[plane_id],
7048 fifo_state->plane[plane_id]);
7052 for_each_plane_id_on_crtc(crtc, plane_id)
7053 vlv_raw_plane_wm_set(crtc_state, level,
7054 plane_id, USHRT_MAX);
7055 vlv_invalidate_wms(crtc, active, level);
7057 crtc_state->wm.vlv.optimal = *active;
7058 crtc_state->wm.vlv.intermediate = *active;
7060 drm_dbg_kms(&dev_priv->drm,
7061 "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n",
7063 wm->pipe[pipe].plane[PLANE_PRIMARY],
7064 wm->pipe[pipe].plane[PLANE_CURSOR],
7065 wm->pipe[pipe].plane[PLANE_SPRITE0],
7066 wm->pipe[pipe].plane[PLANE_SPRITE1]);
7069 drm_dbg_kms(&dev_priv->drm,
7070 "Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n",
7071 wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr);
7074 void vlv_wm_sanitize(struct drm_i915_private *dev_priv)
7076 struct intel_plane *plane;
7077 struct intel_crtc *crtc;
7079 mutex_lock(&dev_priv->wm.wm_mutex);
7081 for_each_intel_plane(&dev_priv->drm, plane) {
7082 struct intel_crtc *crtc =
7083 intel_crtc_for_pipe(dev_priv, plane->pipe);
7084 struct intel_crtc_state *crtc_state =
7085 to_intel_crtc_state(crtc->base.state);
7086 struct intel_plane_state *plane_state =
7087 to_intel_plane_state(plane->base.state);
7088 struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal;
7089 const struct vlv_fifo_state *fifo_state =
7090 &crtc_state->wm.vlv.fifo_state;
7091 enum plane_id plane_id = plane->id;
7094 if (plane_state->uapi.visible)
7097 for (level = 0; level < wm_state->num_levels; level++) {
7098 struct g4x_pipe_wm *raw =
7099 &crtc_state->wm.vlv.raw[level];
7101 raw->plane[plane_id] = 0;
7103 wm_state->wm[level].plane[plane_id] =
7104 vlv_invert_wm_value(raw->plane[plane_id],
7105 fifo_state->plane[plane_id]);
7109 for_each_intel_crtc(&dev_priv->drm, crtc) {
7110 struct intel_crtc_state *crtc_state =
7111 to_intel_crtc_state(crtc->base.state);
7113 crtc_state->wm.vlv.intermediate =
7114 crtc_state->wm.vlv.optimal;
7115 crtc->wm.active.vlv = crtc_state->wm.vlv.optimal;
7118 vlv_program_watermarks(dev_priv);
7120 mutex_unlock(&dev_priv->wm.wm_mutex);
7124 * FIXME should probably kill this and improve
7125 * the real watermark readout/sanitation instead
7127 static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv)
7129 intel_uncore_write(&dev_priv->uncore, WM3_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM3_LP_ILK) & ~WM_LP_ENABLE);
7130 intel_uncore_write(&dev_priv->uncore, WM2_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM2_LP_ILK) & ~WM_LP_ENABLE);
7131 intel_uncore_write(&dev_priv->uncore, WM1_LP_ILK, intel_uncore_read(&dev_priv->uncore, WM1_LP_ILK) & ~WM_LP_ENABLE);
7134 * Don't touch WM_LP_SPRITE_ENABLE here.
7135 * Doing so could cause underruns.
7139 void ilk_wm_get_hw_state(struct drm_i915_private *dev_priv)
7141 struct ilk_wm_values *hw = &dev_priv->wm.hw;
7142 struct intel_crtc *crtc;
7144 ilk_init_lp_watermarks(dev_priv);
7146 for_each_intel_crtc(&dev_priv->drm, crtc)
7147 ilk_pipe_wm_get_hw_state(crtc);
7149 hw->wm_lp[0] = intel_uncore_read(&dev_priv->uncore, WM1_LP_ILK);
7150 hw->wm_lp[1] = intel_uncore_read(&dev_priv->uncore, WM2_LP_ILK);
7151 hw->wm_lp[2] = intel_uncore_read(&dev_priv->uncore, WM3_LP_ILK);
7153 hw->wm_lp_spr[0] = intel_uncore_read(&dev_priv->uncore, WM1S_LP_ILK);
7154 if (DISPLAY_VER(dev_priv) >= 7) {
7155 hw->wm_lp_spr[1] = intel_uncore_read(&dev_priv->uncore, WM2S_LP_IVB);
7156 hw->wm_lp_spr[2] = intel_uncore_read(&dev_priv->uncore, WM3S_LP_IVB);
7159 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
7160 hw->partitioning = (intel_uncore_read(&dev_priv->uncore, WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ?
7161 INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
7162 else if (IS_IVYBRIDGE(dev_priv))
7163 hw->partitioning = (intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ?
7164 INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
7167 !(intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) & DISP_FBC_WM_DIS);
7170 void intel_wm_state_verify(struct intel_crtc *crtc,
7171 struct intel_crtc_state *new_crtc_state)
7173 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7174 struct skl_hw_state {
7175 struct skl_ddb_entry ddb[I915_MAX_PLANES];
7176 struct skl_ddb_entry ddb_y[I915_MAX_PLANES];
7177 struct skl_pipe_wm wm;
7179 const struct skl_pipe_wm *sw_wm = &new_crtc_state->wm.skl.optimal;
7180 int level, max_level = ilk_wm_max_level(dev_priv);
7181 struct intel_plane *plane;
7182 u8 hw_enabled_slices;
7184 if (DISPLAY_VER(dev_priv) < 9 || !new_crtc_state->hw.active)
7187 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
7191 skl_pipe_wm_get_hw_state(crtc, &hw->wm);
7193 skl_pipe_ddb_get_hw_state(crtc, hw->ddb, hw->ddb_y);
7195 hw_enabled_slices = intel_enabled_dbuf_slices_mask(dev_priv);
7197 if (DISPLAY_VER(dev_priv) >= 11 &&
7198 hw_enabled_slices != dev_priv->dbuf.enabled_slices)
7199 drm_err(&dev_priv->drm,
7200 "mismatch in DBUF Slices (expected 0x%x, got 0x%x)\n",
7201 dev_priv->dbuf.enabled_slices,
7204 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
7205 const struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
7206 const struct skl_wm_level *hw_wm_level, *sw_wm_level;
7209 for (level = 0; level <= max_level; level++) {
7210 hw_wm_level = &hw->wm.planes[plane->id].wm[level];
7211 sw_wm_level = skl_plane_wm_level(sw_wm, plane->id, level);
7213 if (skl_wm_level_equals(hw_wm_level, sw_wm_level))
7216 drm_err(&dev_priv->drm,
7217 "[PLANE:%d:%s] mismatch in WM%d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
7218 plane->base.base.id, plane->base.name, level,
7219 sw_wm_level->enable,
7220 sw_wm_level->blocks,
7222 hw_wm_level->enable,
7223 hw_wm_level->blocks,
7224 hw_wm_level->lines);
7227 hw_wm_level = &hw->wm.planes[plane->id].trans_wm;
7228 sw_wm_level = skl_plane_trans_wm(sw_wm, plane->id);
7230 if (!skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
7231 drm_err(&dev_priv->drm,
7232 "[PLANE:%d:%s] mismatch in trans WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
7233 plane->base.base.id, plane->base.name,
7234 sw_wm_level->enable,
7235 sw_wm_level->blocks,
7237 hw_wm_level->enable,
7238 hw_wm_level->blocks,
7239 hw_wm_level->lines);
7242 hw_wm_level = &hw->wm.planes[plane->id].sagv.wm0;
7243 sw_wm_level = &sw_wm->planes[plane->id].sagv.wm0;
7245 if (HAS_HW_SAGV_WM(dev_priv) &&
7246 !skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
7247 drm_err(&dev_priv->drm,
7248 "[PLANE:%d:%s] mismatch in SAGV WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
7249 plane->base.base.id, plane->base.name,
7250 sw_wm_level->enable,
7251 sw_wm_level->blocks,
7253 hw_wm_level->enable,
7254 hw_wm_level->blocks,
7255 hw_wm_level->lines);
7258 hw_wm_level = &hw->wm.planes[plane->id].sagv.trans_wm;
7259 sw_wm_level = &sw_wm->planes[plane->id].sagv.trans_wm;
7261 if (HAS_HW_SAGV_WM(dev_priv) &&
7262 !skl_wm_level_equals(hw_wm_level, sw_wm_level)) {
7263 drm_err(&dev_priv->drm,
7264 "[PLANE:%d:%s] mismatch in SAGV trans WM (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
7265 plane->base.base.id, plane->base.name,
7266 sw_wm_level->enable,
7267 sw_wm_level->blocks,
7269 hw_wm_level->enable,
7270 hw_wm_level->blocks,
7271 hw_wm_level->lines);
7275 hw_ddb_entry = &hw->ddb[PLANE_CURSOR];
7276 sw_ddb_entry = &new_crtc_state->wm.skl.plane_ddb[PLANE_CURSOR];
7278 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
7279 drm_err(&dev_priv->drm,
7280 "[PLANE:%d:%s] mismatch in DDB (expected (%u,%u), found (%u,%u))\n",
7281 plane->base.base.id, plane->base.name,
7282 sw_ddb_entry->start, sw_ddb_entry->end,
7283 hw_ddb_entry->start, hw_ddb_entry->end);
7290 void intel_enable_ipc(struct drm_i915_private *dev_priv)
7294 if (!HAS_IPC(dev_priv))
7297 val = intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL2);
7299 if (dev_priv->ipc_enabled)
7300 val |= DISP_IPC_ENABLE;
7302 val &= ~DISP_IPC_ENABLE;
7304 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL2, val);
7307 static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv)
7309 /* Display WA #0477 WaDisableIPC: skl */
7310 if (IS_SKYLAKE(dev_priv))
7313 /* Display WA #1141: SKL:all KBL:all CFL */
7314 if (IS_KABYLAKE(dev_priv) ||
7315 IS_COFFEELAKE(dev_priv) ||
7316 IS_COMETLAKE(dev_priv))
7317 return dev_priv->dram_info.symmetric_memory;
7322 void intel_init_ipc(struct drm_i915_private *dev_priv)
7324 if (!HAS_IPC(dev_priv))
7327 dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv);
7329 intel_enable_ipc(dev_priv);
7332 static void ibx_init_clock_gating(struct drm_i915_private *dev_priv)
7335 * On Ibex Peak and Cougar Point, we need to disable clock
7336 * gating for the panel power sequencer or it will fail to
7337 * start up when no ports are active.
7339 intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
7342 static void g4x_disable_trickle_feed(struct drm_i915_private *dev_priv)
7346 for_each_pipe(dev_priv, pipe) {
7347 intel_uncore_write(&dev_priv->uncore, DSPCNTR(pipe),
7348 intel_uncore_read(&dev_priv->uncore, DSPCNTR(pipe)) |
7349 DISP_TRICKLE_FEED_DISABLE);
7351 intel_uncore_write(&dev_priv->uncore, DSPSURF(pipe), intel_uncore_read(&dev_priv->uncore, DSPSURF(pipe)));
7352 intel_uncore_posting_read(&dev_priv->uncore, DSPSURF(pipe));
7356 static void ilk_init_clock_gating(struct drm_i915_private *dev_priv)
7358 u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
7362 * WaFbcDisableDpfcClockGating:ilk
7364 dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE |
7365 ILK_DPFCUNIT_CLOCK_GATE_DISABLE |
7366 ILK_DPFDUNIT_CLOCK_GATE_ENABLE;
7368 intel_uncore_write(&dev_priv->uncore, PCH_3DCGDIS0,
7369 MARIUNIT_CLOCK_GATE_DISABLE |
7370 SVSMUNIT_CLOCK_GATE_DISABLE);
7371 intel_uncore_write(&dev_priv->uncore, PCH_3DCGDIS1,
7372 VFMUNIT_CLOCK_GATE_DISABLE);
7375 * According to the spec the following bits should be set in
7376 * order to enable memory self-refresh
7377 * The bit 22/21 of 0x42004
7378 * The bit 5 of 0x42020
7379 * The bit 15 of 0x45000
7381 intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2,
7382 (intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) |
7383 ILK_DPARB_GATE | ILK_VSDPFD_FULL));
7384 dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE;
7385 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL,
7386 (intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) |
7390 * Based on the document from hardware guys the following bits
7391 * should be set unconditionally in order to enable FBC.
7392 * The bit 22 of 0x42000
7393 * The bit 22 of 0x42004
7394 * The bit 7,8,9 of 0x42020.
7396 if (IS_IRONLAKE_M(dev_priv)) {
7397 /* WaFbcAsynchFlipDisableFbcQueue:ilk */
7398 intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1,
7399 intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) |
7401 intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2,
7402 intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) |
7406 intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, dspclk_gate);
7408 intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2,
7409 intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) |
7410 ILK_ELPIN_409_SELECT);
7412 g4x_disable_trickle_feed(dev_priv);
7414 ibx_init_clock_gating(dev_priv);
7417 static void cpt_init_clock_gating(struct drm_i915_private *dev_priv)
7423 * On Ibex Peak and Cougar Point, we need to disable clock
7424 * gating for the panel power sequencer or it will fail to
7425 * start up when no ports are active.
7427 intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE |
7428 PCH_DPLUNIT_CLOCK_GATE_DISABLE |
7429 PCH_CPUNIT_CLOCK_GATE_DISABLE);
7430 intel_uncore_write(&dev_priv->uncore, SOUTH_CHICKEN2, intel_uncore_read(&dev_priv->uncore, SOUTH_CHICKEN2) |
7431 DPLS_EDP_PPS_FIX_DIS);
7432 /* The below fixes the weird display corruption, a few pixels shifted
7433 * downward, on (only) LVDS of some HP laptops with IVY.
7435 for_each_pipe(dev_priv, pipe) {
7436 val = intel_uncore_read(&dev_priv->uncore, TRANS_CHICKEN2(pipe));
7437 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
7438 val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
7439 if (dev_priv->vbt.fdi_rx_polarity_inverted)
7440 val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
7441 val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER;
7442 val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH;
7443 intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN2(pipe), val);
7445 /* WADP0ClockGatingDisable */
7446 for_each_pipe(dev_priv, pipe) {
7447 intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN1(pipe),
7448 TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
7452 static void gen6_check_mch_setup(struct drm_i915_private *dev_priv)
7456 tmp = intel_uncore_read(&dev_priv->uncore, MCH_SSKPD);
7457 if (REG_FIELD_GET(SSKPD_WM0_MASK_SNB, tmp) != 12)
7458 drm_dbg_kms(&dev_priv->drm,
7459 "Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n",
7463 static void gen6_init_clock_gating(struct drm_i915_private *dev_priv)
7465 u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
7467 intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, dspclk_gate);
7469 intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2,
7470 intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) |
7471 ILK_ELPIN_409_SELECT);
7473 intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1,
7474 intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) |
7475 GEN6_BLBUNIT_CLOCK_GATE_DISABLE |
7476 GEN6_CSUNIT_CLOCK_GATE_DISABLE);
7478 /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
7479 * gating disable must be set. Failure to set it results in
7480 * flickering pixels due to Z write ordering failures after
7481 * some amount of runtime in the Mesa "fire" demo, and Unigine
7482 * Sanctuary and Tropics, and apparently anything else with
7483 * alpha test or pixel discard.
7485 * According to the spec, bit 11 (RCCUNIT) must also be set,
7486 * but we didn't debug actual testcases to find it out.
7488 * WaDisableRCCUnitClockGating:snb
7489 * WaDisableRCPBUnitClockGating:snb
7491 intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2,
7492 GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
7493 GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
7496 * According to the spec the following bits should be
7497 * set in order to enable memory self-refresh and fbc:
7498 * The bit21 and bit22 of 0x42000
7499 * The bit21 and bit22 of 0x42004
7500 * The bit5 and bit7 of 0x42020
7501 * The bit14 of 0x70180
7502 * The bit14 of 0x71180
7504 * WaFbcAsynchFlipDisableFbcQueue:snb
7506 intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1,
7507 intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) |
7508 ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
7509 intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2,
7510 intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN2) |
7511 ILK_DPARB_GATE | ILK_VSDPFD_FULL);
7512 intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D,
7513 intel_uncore_read(&dev_priv->uncore, ILK_DSPCLK_GATE_D) |
7514 ILK_DPARBUNIT_CLOCK_GATE_ENABLE |
7515 ILK_DPFDUNIT_CLOCK_GATE_ENABLE);
7517 g4x_disable_trickle_feed(dev_priv);
7519 cpt_init_clock_gating(dev_priv);
7521 gen6_check_mch_setup(dev_priv);
7524 static void lpt_init_clock_gating(struct drm_i915_private *dev_priv)
7527 * TODO: this bit should only be enabled when really needed, then
7528 * disabled when not needed anymore in order to save power.
7530 if (HAS_PCH_LPT_LP(dev_priv))
7531 intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D,
7532 intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D) |
7533 PCH_LP_PARTITION_LEVEL_DISABLE);
7535 /* WADPOClockGatingDisable:hsw */
7536 intel_uncore_write(&dev_priv->uncore, TRANS_CHICKEN1(PIPE_A),
7537 intel_uncore_read(&dev_priv->uncore, TRANS_CHICKEN1(PIPE_A)) |
7538 TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
7541 static void lpt_suspend_hw(struct drm_i915_private *dev_priv)
7543 if (HAS_PCH_LPT_LP(dev_priv)) {
7544 u32 val = intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D);
7546 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
7547 intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, val);
7551 static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv,
7552 int general_prio_credits,
7553 int high_prio_credits)
7558 /* WaTempDisableDOPClkGating:bdw */
7559 misccpctl = intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL);
7560 intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
7562 val = intel_uncore_read(&dev_priv->uncore, GEN8_L3SQCREG1);
7563 val &= ~L3_PRIO_CREDITS_MASK;
7564 val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits);
7565 val |= L3_HIGH_PRIO_CREDITS(high_prio_credits);
7566 intel_uncore_write(&dev_priv->uncore, GEN8_L3SQCREG1, val);
7569 * Wait at least 100 clocks before re-enabling clock gating.
7570 * See the definition of L3SQCREG1 in BSpec.
7572 intel_uncore_posting_read(&dev_priv->uncore, GEN8_L3SQCREG1);
7574 intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, misccpctl);
7577 static void icl_init_clock_gating(struct drm_i915_private *dev_priv)
7579 /* Wa_1409120013:icl,ehl */
7580 intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A),
7581 DPFC_CHICKEN_COMP_DUMMY_PIXEL);
7583 /*Wa_14010594013:icl, ehl */
7584 intel_uncore_rmw(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1,
7585 0, ICL_DELAY_PMRSP);
7588 static void gen12lp_init_clock_gating(struct drm_i915_private *dev_priv)
7590 /* Wa_1409120013:tgl,rkl,adl-s,dg1,dg2 */
7591 if (IS_TIGERLAKE(dev_priv) || IS_ROCKETLAKE(dev_priv) ||
7592 IS_ALDERLAKE_S(dev_priv) || IS_DG1(dev_priv) || IS_DG2(dev_priv))
7593 intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A),
7594 DPFC_CHICKEN_COMP_DUMMY_PIXEL);
7596 /* Wa_1409825376:tgl (pre-prod)*/
7597 if (IS_TGL_DISPLAY_STEP(dev_priv, STEP_A0, STEP_C0))
7598 intel_uncore_write(&dev_priv->uncore, GEN9_CLKGATE_DIS_3, intel_uncore_read(&dev_priv->uncore, GEN9_CLKGATE_DIS_3) |
7599 TGL_VRH_GATING_DIS);
7601 /* Wa_14013723622:tgl,rkl,dg1,adl-s */
7602 if (DISPLAY_VER(dev_priv) == 12)
7603 intel_uncore_rmw(&dev_priv->uncore, CLKREQ_POLICY,
7604 CLKREQ_POLICY_MEM_UP_OVRD, 0);
7607 static void adlp_init_clock_gating(struct drm_i915_private *dev_priv)
7609 gen12lp_init_clock_gating(dev_priv);
7611 /* Wa_22011091694:adlp */
7612 intel_de_rmw(dev_priv, GEN9_CLKGATE_DIS_5, 0, DPCE_GATING_DIS);
7614 /* Bspec/49189 Initialize Sequence */
7615 intel_de_rmw(dev_priv, GEN8_CHICKEN_DCPR_1, DDI_CLOCK_REG_ACCESS, 0);
7618 static void dg1_init_clock_gating(struct drm_i915_private *dev_priv)
7620 gen12lp_init_clock_gating(dev_priv);
7622 /* Wa_1409836686:dg1[a0] */
7623 if (IS_DG1_GRAPHICS_STEP(dev_priv, STEP_A0, STEP_B0))
7624 intel_uncore_write(&dev_priv->uncore, GEN9_CLKGATE_DIS_3, intel_uncore_read(&dev_priv->uncore, GEN9_CLKGATE_DIS_3) |
7628 static void xehpsdv_init_clock_gating(struct drm_i915_private *dev_priv)
7630 /* Wa_22010146351:xehpsdv */
7631 if (IS_XEHPSDV_GRAPHICS_STEP(dev_priv, STEP_A0, STEP_B0))
7632 intel_uncore_rmw(&dev_priv->uncore, XEHP_CLOCK_GATE_DIS, 0, SGR_DIS);
7635 static void dg2_init_clock_gating(struct drm_i915_private *i915)
7637 /* Wa_22010954014:dg2 */
7638 intel_uncore_rmw(&i915->uncore, XEHP_CLOCK_GATE_DIS, 0,
7642 * Wa_14010733611:dg2_g10
7643 * Wa_22010146351:dg2_g10
7645 if (IS_DG2_GRAPHICS_STEP(i915, G10, STEP_A0, STEP_B0))
7646 intel_uncore_rmw(&i915->uncore, XEHP_CLOCK_GATE_DIS, 0,
7647 SGR_DIS | SGGI_DIS);
7650 static void pvc_init_clock_gating(struct drm_i915_private *dev_priv)
7652 /* Wa_14012385139:pvc */
7653 if (IS_PVC_BD_STEP(dev_priv, STEP_A0, STEP_B0))
7654 intel_uncore_rmw(&dev_priv->uncore, XEHP_CLOCK_GATE_DIS, 0, SGR_DIS);
7656 /* Wa_22010954014:pvc */
7657 if (IS_PVC_BD_STEP(dev_priv, STEP_A0, STEP_B0))
7658 intel_uncore_rmw(&dev_priv->uncore, XEHP_CLOCK_GATE_DIS, 0, SGSI_SIDECLK_DIS);
7661 static void cnp_init_clock_gating(struct drm_i915_private *dev_priv)
7663 if (!HAS_PCH_CNP(dev_priv))
7666 /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */
7667 intel_uncore_write(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D, intel_uncore_read(&dev_priv->uncore, SOUTH_DSPCLK_GATE_D) |
7668 CNP_PWM_CGE_GATING_DISABLE);
7671 static void cfl_init_clock_gating(struct drm_i915_private *dev_priv)
7673 cnp_init_clock_gating(dev_priv);
7674 gen9_init_clock_gating(dev_priv);
7676 /* WAC6entrylatency:cfl */
7677 intel_uncore_write(&dev_priv->uncore, FBC_LLC_READ_CTRL, intel_uncore_read(&dev_priv->uncore, FBC_LLC_READ_CTRL) |
7678 FBC_LLC_FULLY_OPEN);
7681 * WaFbcTurnOffFbcWatermark:cfl
7682 * Display WA #0562: cfl
7684 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) |
7688 * WaFbcNukeOnHostModify:cfl
7689 * Display WA #0873: cfl
7691 intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A),
7692 intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A)) |
7693 DPFC_NUKE_ON_ANY_MODIFICATION);
7696 static void kbl_init_clock_gating(struct drm_i915_private *dev_priv)
7698 gen9_init_clock_gating(dev_priv);
7700 /* WAC6entrylatency:kbl */
7701 intel_uncore_write(&dev_priv->uncore, FBC_LLC_READ_CTRL, intel_uncore_read(&dev_priv->uncore, FBC_LLC_READ_CTRL) |
7702 FBC_LLC_FULLY_OPEN);
7704 /* WaDisableSDEUnitClockGating:kbl */
7705 if (IS_KBL_GRAPHICS_STEP(dev_priv, 0, STEP_C0))
7706 intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) |
7707 GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
7709 /* WaDisableGamClockGating:kbl */
7710 if (IS_KBL_GRAPHICS_STEP(dev_priv, 0, STEP_C0))
7711 intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) |
7712 GEN6_GAMUNIT_CLOCK_GATE_DISABLE);
7715 * WaFbcTurnOffFbcWatermark:kbl
7716 * Display WA #0562: kbl
7718 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) |
7722 * WaFbcNukeOnHostModify:kbl
7723 * Display WA #0873: kbl
7725 intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A),
7726 intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A)) |
7727 DPFC_NUKE_ON_ANY_MODIFICATION);
7730 static void skl_init_clock_gating(struct drm_i915_private *dev_priv)
7732 gen9_init_clock_gating(dev_priv);
7734 /* WaDisableDopClockGating:skl */
7735 intel_uncore_write(&dev_priv->uncore, GEN7_MISCCPCTL, intel_uncore_read(&dev_priv->uncore, GEN7_MISCCPCTL) &
7736 ~GEN7_DOP_CLOCK_GATE_ENABLE);
7738 /* WAC6entrylatency:skl */
7739 intel_uncore_write(&dev_priv->uncore, FBC_LLC_READ_CTRL, intel_uncore_read(&dev_priv->uncore, FBC_LLC_READ_CTRL) |
7740 FBC_LLC_FULLY_OPEN);
7743 * WaFbcTurnOffFbcWatermark:skl
7744 * Display WA #0562: skl
7746 intel_uncore_write(&dev_priv->uncore, DISP_ARB_CTL, intel_uncore_read(&dev_priv->uncore, DISP_ARB_CTL) |
7750 * WaFbcNukeOnHostModify:skl
7751 * Display WA #0873: skl
7753 intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A),
7754 intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A)) |
7755 DPFC_NUKE_ON_ANY_MODIFICATION);
7758 * WaFbcHighMemBwCorruptionAvoidance:skl
7759 * Display WA #0883: skl
7761 intel_uncore_write(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A),
7762 intel_uncore_read(&dev_priv->uncore, ILK_DPFC_CHICKEN(INTEL_FBC_A)) |
7763 DPFC_DISABLE_DUMMY0);
7766 static void bdw_init_clock_gating(struct drm_i915_private *dev_priv)
7770 /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */
7771 intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A),
7772 intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A)) |
7775 /* WaSwitchSolVfFArbitrationPriority:bdw */
7776 intel_uncore_write(&dev_priv->uncore, GAM_ECOCHK, intel_uncore_read(&dev_priv->uncore, GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
7778 /* WaPsrDPAMaskVBlankInSRD:bdw */
7779 intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR1_1,
7780 intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD);
7782 for_each_pipe(dev_priv, pipe) {
7783 /* WaPsrDPRSUnmaskVBlankInSRD:bdw */
7784 intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe),
7785 intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(pipe)) |
7786 BDW_DPRS_MASK_VBLANK_SRD);
7789 /* WaVSRefCountFullforceMissDisable:bdw */
7790 /* WaDSRefCountFullforceMissDisable:bdw */
7791 intel_uncore_write(&dev_priv->uncore, GEN7_FF_THREAD_MODE,
7792 intel_uncore_read(&dev_priv->uncore, GEN7_FF_THREAD_MODE) &
7793 ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
7795 intel_uncore_write(&dev_priv->uncore, RING_PSMI_CTL(RENDER_RING_BASE),
7796 _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
7798 /* WaDisableSDEUnitClockGating:bdw */
7799 intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) |
7800 GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
7802 /* WaProgramL3SqcReg1Default:bdw */
7803 gen8_set_l3sqc_credits(dev_priv, 30, 2);
7805 /* WaKVMNotificationOnConfigChange:bdw */
7806 intel_uncore_write(&dev_priv->uncore, CHICKEN_PAR2_1, intel_uncore_read(&dev_priv->uncore, CHICKEN_PAR2_1)
7807 | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT);
7809 lpt_init_clock_gating(dev_priv);
7811 /* WaDisableDopClockGating:bdw
7813 * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP
7816 intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1,
7817 intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE);
7820 static void hsw_init_clock_gating(struct drm_i915_private *dev_priv)
7822 /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */
7823 intel_uncore_write(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A),
7824 intel_uncore_read(&dev_priv->uncore, CHICKEN_PIPESL_1(PIPE_A)) |
7827 /* This is required by WaCatErrorRejectionIssue:hsw */
7828 intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
7829 intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
7830 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
7832 /* WaSwitchSolVfFArbitrationPriority:hsw */
7833 intel_uncore_write(&dev_priv->uncore, GAM_ECOCHK, intel_uncore_read(&dev_priv->uncore, GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
7835 lpt_init_clock_gating(dev_priv);
7838 static void ivb_init_clock_gating(struct drm_i915_private *dev_priv)
7842 intel_uncore_write(&dev_priv->uncore, ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE);
7844 /* WaFbcAsynchFlipDisableFbcQueue:ivb */
7845 intel_uncore_write(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1,
7846 intel_uncore_read(&dev_priv->uncore, ILK_DISPLAY_CHICKEN1) |
7849 /* WaDisableBackToBackFlipFix:ivb */
7850 intel_uncore_write(&dev_priv->uncore, IVB_CHICKEN3,
7851 CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
7852 CHICKEN3_DGMG_DONE_FIX_DISABLE);
7854 if (IS_IVB_GT1(dev_priv))
7855 intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2,
7856 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
7858 /* must write both registers */
7859 intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2,
7860 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
7861 intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2_GT2,
7862 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
7866 * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
7867 * This implements the WaDisableRCZUnitClockGating:ivb workaround.
7869 intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2,
7870 GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
7872 /* This is required by WaCatErrorRejectionIssue:ivb */
7873 intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
7874 intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
7875 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
7877 g4x_disable_trickle_feed(dev_priv);
7879 snpcr = intel_uncore_read(&dev_priv->uncore, GEN6_MBCUNIT_SNPCR);
7880 snpcr &= ~GEN6_MBC_SNPCR_MASK;
7881 snpcr |= GEN6_MBC_SNPCR_MED;
7882 intel_uncore_write(&dev_priv->uncore, GEN6_MBCUNIT_SNPCR, snpcr);
7884 if (!HAS_PCH_NOP(dev_priv))
7885 cpt_init_clock_gating(dev_priv);
7887 gen6_check_mch_setup(dev_priv);
7890 static void vlv_init_clock_gating(struct drm_i915_private *dev_priv)
7892 /* WaDisableBackToBackFlipFix:vlv */
7893 intel_uncore_write(&dev_priv->uncore, IVB_CHICKEN3,
7894 CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
7895 CHICKEN3_DGMG_DONE_FIX_DISABLE);
7897 /* WaDisableDopClockGating:vlv */
7898 intel_uncore_write(&dev_priv->uncore, GEN7_ROW_CHICKEN2,
7899 _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
7901 /* This is required by WaCatErrorRejectionIssue:vlv */
7902 intel_uncore_write(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
7903 intel_uncore_read(&dev_priv->uncore, GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
7904 GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
7907 * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
7908 * This implements the WaDisableRCZUnitClockGating:vlv workaround.
7910 intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL2,
7911 GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
7913 /* WaDisableL3Bank2xClockGate:vlv
7914 * Disabling L3 clock gating- MMIO 940c[25] = 1
7915 * Set bit 25, to disable L3_BANK_2x_CLK_GATING */
7916 intel_uncore_write(&dev_priv->uncore, GEN7_UCGCTL4,
7917 intel_uncore_read(&dev_priv->uncore, GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE);
7920 * WaDisableVLVClockGating_VBIIssue:vlv
7921 * Disable clock gating on th GCFG unit to prevent a delay
7922 * in the reporting of vblank events.
7924 intel_uncore_write(&dev_priv->uncore, VLV_GUNIT_CLOCK_GATE, GCFG_DIS);
7927 static void chv_init_clock_gating(struct drm_i915_private *dev_priv)
7929 /* WaVSRefCountFullforceMissDisable:chv */
7930 /* WaDSRefCountFullforceMissDisable:chv */
7931 intel_uncore_write(&dev_priv->uncore, GEN7_FF_THREAD_MODE,
7932 intel_uncore_read(&dev_priv->uncore, GEN7_FF_THREAD_MODE) &
7933 ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
7935 /* WaDisableSemaphoreAndSyncFlipWait:chv */
7936 intel_uncore_write(&dev_priv->uncore, RING_PSMI_CTL(RENDER_RING_BASE),
7937 _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
7939 /* WaDisableCSUnitClockGating:chv */
7940 intel_uncore_write(&dev_priv->uncore, GEN6_UCGCTL1, intel_uncore_read(&dev_priv->uncore, GEN6_UCGCTL1) |
7941 GEN6_CSUNIT_CLOCK_GATE_DISABLE);
7943 /* WaDisableSDEUnitClockGating:chv */
7944 intel_uncore_write(&dev_priv->uncore, GEN8_UCGCTL6, intel_uncore_read(&dev_priv->uncore, GEN8_UCGCTL6) |
7945 GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
7948 * WaProgramL3SqcReg1Default:chv
7949 * See gfxspecs/Related Documents/Performance Guide/
7950 * LSQC Setting Recommendations.
7952 gen8_set_l3sqc_credits(dev_priv, 38, 2);
7955 static void g4x_init_clock_gating(struct drm_i915_private *dev_priv)
7959 intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D1, 0);
7960 intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
7961 GS_UNIT_CLOCK_GATE_DISABLE |
7962 CL_UNIT_CLOCK_GATE_DISABLE);
7963 intel_uncore_write(&dev_priv->uncore, RAMCLK_GATE_D, 0);
7964 dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
7965 OVRUNIT_CLOCK_GATE_DISABLE |
7966 OVCUNIT_CLOCK_GATE_DISABLE;
7967 if (IS_GM45(dev_priv))
7968 dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
7969 intel_uncore_write(&dev_priv->uncore, DSPCLK_GATE_D, dspclk_gate);
7971 g4x_disable_trickle_feed(dev_priv);
7974 static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv)
7976 struct intel_uncore *uncore = &dev_priv->uncore;
7978 intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
7979 intel_uncore_write(uncore, RENCLK_GATE_D2, 0);
7980 intel_uncore_write(uncore, DSPCLK_GATE_D, 0);
7981 intel_uncore_write(uncore, RAMCLK_GATE_D, 0);
7982 intel_uncore_write16(uncore, DEUC, 0);
7983 intel_uncore_write(uncore,
7985 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
7988 static void i965g_init_clock_gating(struct drm_i915_private *dev_priv)
7990 intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
7991 I965_RCC_CLOCK_GATE_DISABLE |
7992 I965_RCPB_CLOCK_GATE_DISABLE |
7993 I965_ISC_CLOCK_GATE_DISABLE |
7994 I965_FBC_CLOCK_GATE_DISABLE);
7995 intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D2, 0);
7996 intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE,
7997 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
8000 static void gen3_init_clock_gating(struct drm_i915_private *dev_priv)
8002 u32 dstate = intel_uncore_read(&dev_priv->uncore, D_STATE);
8004 dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
8005 DSTATE_DOT_CLOCK_GATING;
8006 intel_uncore_write(&dev_priv->uncore, D_STATE, dstate);
8008 if (IS_PINEVIEW(dev_priv))
8009 intel_uncore_write(&dev_priv->uncore, ECOSKPD(RENDER_RING_BASE),
8010 _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY));
8012 /* IIR "flip pending" means done if this bit is set */
8013 intel_uncore_write(&dev_priv->uncore, ECOSKPD(RENDER_RING_BASE),
8014 _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
8016 /* interrupts should cause a wake up from C3 */
8017 intel_uncore_write(&dev_priv->uncore, INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN));
8019 /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
8020 intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE));
8022 intel_uncore_write(&dev_priv->uncore, MI_ARB_STATE,
8023 _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
8026 static void i85x_init_clock_gating(struct drm_i915_private *dev_priv)
8028 intel_uncore_write(&dev_priv->uncore, RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
8030 /* interrupts should cause a wake up from C3 */
8031 intel_uncore_write(&dev_priv->uncore, MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) |
8032 _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE));
8034 intel_uncore_write(&dev_priv->uncore, MEM_MODE,
8035 _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE));
8038 * Have FBC ignore 3D activity since we use software
8039 * render tracking, and otherwise a pure 3D workload
8040 * (even if it just renders a single frame and then does
8041 * abosultely nothing) would not allow FBC to recompress
8042 * until a 2D blit occurs.
8044 intel_uncore_write(&dev_priv->uncore, SCPD0,
8045 _MASKED_BIT_ENABLE(SCPD_FBC_IGNORE_3D));
8048 static void i830_init_clock_gating(struct drm_i915_private *dev_priv)
8050 intel_uncore_write(&dev_priv->uncore, MEM_MODE,
8051 _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) |
8052 _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE));
8055 void intel_init_clock_gating(struct drm_i915_private *dev_priv)
8057 dev_priv->clock_gating_funcs->init_clock_gating(dev_priv);
8060 void intel_suspend_hw(struct drm_i915_private *dev_priv)
8062 if (HAS_PCH_LPT(dev_priv))
8063 lpt_suspend_hw(dev_priv);
8066 static void nop_init_clock_gating(struct drm_i915_private *dev_priv)
8068 drm_dbg_kms(&dev_priv->drm,
8069 "No clock gating settings or workarounds applied.\n");
8072 #define CG_FUNCS(platform) \
8073 static const struct drm_i915_clock_gating_funcs platform##_clock_gating_funcs = { \
8074 .init_clock_gating = platform##_init_clock_gating, \
8106 * intel_init_clock_gating_hooks - setup the clock gating hooks
8107 * @dev_priv: device private
8109 * Setup the hooks that configure which clocks of a given platform can be
8110 * gated and also apply various GT and display specific workarounds for these
8111 * platforms. Note that some GT specific workarounds are applied separately
8112 * when GPU contexts or batchbuffers start their execution.
8114 void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv)
8116 if (IS_PONTEVECCHIO(dev_priv))
8117 dev_priv->clock_gating_funcs = &pvc_clock_gating_funcs;
8118 else if (IS_DG2(dev_priv))
8119 dev_priv->clock_gating_funcs = &dg2_clock_gating_funcs;
8120 else if (IS_XEHPSDV(dev_priv))
8121 dev_priv->clock_gating_funcs = &xehpsdv_clock_gating_funcs;
8122 else if (IS_ALDERLAKE_P(dev_priv))
8123 dev_priv->clock_gating_funcs = &adlp_clock_gating_funcs;
8124 else if (IS_DG1(dev_priv))
8125 dev_priv->clock_gating_funcs = &dg1_clock_gating_funcs;
8126 else if (GRAPHICS_VER(dev_priv) == 12)
8127 dev_priv->clock_gating_funcs = &gen12lp_clock_gating_funcs;
8128 else if (GRAPHICS_VER(dev_priv) == 11)
8129 dev_priv->clock_gating_funcs = &icl_clock_gating_funcs;
8130 else if (IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv))
8131 dev_priv->clock_gating_funcs = &cfl_clock_gating_funcs;
8132 else if (IS_SKYLAKE(dev_priv))
8133 dev_priv->clock_gating_funcs = &skl_clock_gating_funcs;
8134 else if (IS_KABYLAKE(dev_priv))
8135 dev_priv->clock_gating_funcs = &kbl_clock_gating_funcs;
8136 else if (IS_BROXTON(dev_priv))
8137 dev_priv->clock_gating_funcs = &bxt_clock_gating_funcs;
8138 else if (IS_GEMINILAKE(dev_priv))
8139 dev_priv->clock_gating_funcs = &glk_clock_gating_funcs;
8140 else if (IS_BROADWELL(dev_priv))
8141 dev_priv->clock_gating_funcs = &bdw_clock_gating_funcs;
8142 else if (IS_CHERRYVIEW(dev_priv))
8143 dev_priv->clock_gating_funcs = &chv_clock_gating_funcs;
8144 else if (IS_HASWELL(dev_priv))
8145 dev_priv->clock_gating_funcs = &hsw_clock_gating_funcs;
8146 else if (IS_IVYBRIDGE(dev_priv))
8147 dev_priv->clock_gating_funcs = &ivb_clock_gating_funcs;
8148 else if (IS_VALLEYVIEW(dev_priv))
8149 dev_priv->clock_gating_funcs = &vlv_clock_gating_funcs;
8150 else if (GRAPHICS_VER(dev_priv) == 6)
8151 dev_priv->clock_gating_funcs = &gen6_clock_gating_funcs;
8152 else if (GRAPHICS_VER(dev_priv) == 5)
8153 dev_priv->clock_gating_funcs = &ilk_clock_gating_funcs;
8154 else if (IS_G4X(dev_priv))
8155 dev_priv->clock_gating_funcs = &g4x_clock_gating_funcs;
8156 else if (IS_I965GM(dev_priv))
8157 dev_priv->clock_gating_funcs = &i965gm_clock_gating_funcs;
8158 else if (IS_I965G(dev_priv))
8159 dev_priv->clock_gating_funcs = &i965g_clock_gating_funcs;
8160 else if (GRAPHICS_VER(dev_priv) == 3)
8161 dev_priv->clock_gating_funcs = &gen3_clock_gating_funcs;
8162 else if (IS_I85X(dev_priv) || IS_I865G(dev_priv))
8163 dev_priv->clock_gating_funcs = &i85x_clock_gating_funcs;
8164 else if (GRAPHICS_VER(dev_priv) == 2)
8165 dev_priv->clock_gating_funcs = &i830_clock_gating_funcs;
8167 MISSING_CASE(INTEL_DEVID(dev_priv));
8168 dev_priv->clock_gating_funcs = &nop_clock_gating_funcs;
8172 static const struct drm_i915_wm_disp_funcs skl_wm_funcs = {
8173 .compute_global_watermarks = skl_compute_wm,
8176 static const struct drm_i915_wm_disp_funcs ilk_wm_funcs = {
8177 .compute_pipe_wm = ilk_compute_pipe_wm,
8178 .compute_intermediate_wm = ilk_compute_intermediate_wm,
8179 .initial_watermarks = ilk_initial_watermarks,
8180 .optimize_watermarks = ilk_optimize_watermarks,
8183 static const struct drm_i915_wm_disp_funcs vlv_wm_funcs = {
8184 .compute_pipe_wm = vlv_compute_pipe_wm,
8185 .compute_intermediate_wm = vlv_compute_intermediate_wm,
8186 .initial_watermarks = vlv_initial_watermarks,
8187 .optimize_watermarks = vlv_optimize_watermarks,
8188 .atomic_update_watermarks = vlv_atomic_update_fifo,
8191 static const struct drm_i915_wm_disp_funcs g4x_wm_funcs = {
8192 .compute_pipe_wm = g4x_compute_pipe_wm,
8193 .compute_intermediate_wm = g4x_compute_intermediate_wm,
8194 .initial_watermarks = g4x_initial_watermarks,
8195 .optimize_watermarks = g4x_optimize_watermarks,
8198 static const struct drm_i915_wm_disp_funcs pnv_wm_funcs = {
8199 .update_wm = pnv_update_wm,
8202 static const struct drm_i915_wm_disp_funcs i965_wm_funcs = {
8203 .update_wm = i965_update_wm,
8206 static const struct drm_i915_wm_disp_funcs i9xx_wm_funcs = {
8207 .update_wm = i9xx_update_wm,
8210 static const struct drm_i915_wm_disp_funcs i845_wm_funcs = {
8211 .update_wm = i845_update_wm,
8214 static const struct drm_i915_wm_disp_funcs nop_funcs = {
8217 /* Set up chip specific power management-related functions */
8218 void intel_init_pm(struct drm_i915_private *dev_priv)
8221 if (IS_PINEVIEW(dev_priv))
8222 pnv_get_mem_freq(dev_priv);
8223 else if (GRAPHICS_VER(dev_priv) == 5)
8224 ilk_get_mem_freq(dev_priv);
8226 intel_sagv_init(dev_priv);
8228 /* For FIFO watermark updates */
8229 if (DISPLAY_VER(dev_priv) >= 9) {
8230 skl_setup_wm_latency(dev_priv);
8231 dev_priv->wm_disp = &skl_wm_funcs;
8232 } else if (HAS_PCH_SPLIT(dev_priv)) {
8233 ilk_setup_wm_latency(dev_priv);
8235 if ((DISPLAY_VER(dev_priv) == 5 && dev_priv->wm.pri_latency[1] &&
8236 dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) ||
8237 (DISPLAY_VER(dev_priv) != 5 && dev_priv->wm.pri_latency[0] &&
8238 dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) {
8239 dev_priv->wm_disp = &ilk_wm_funcs;
8241 drm_dbg_kms(&dev_priv->drm,
8242 "Failed to read display plane latency. "
8244 dev_priv->wm_disp = &nop_funcs;
8246 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
8247 vlv_setup_wm_latency(dev_priv);
8248 dev_priv->wm_disp = &vlv_wm_funcs;
8249 } else if (IS_G4X(dev_priv)) {
8250 g4x_setup_wm_latency(dev_priv);
8251 dev_priv->wm_disp = &g4x_wm_funcs;
8252 } else if (IS_PINEVIEW(dev_priv)) {
8253 if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv),
8256 dev_priv->mem_freq)) {
8257 drm_info(&dev_priv->drm,
8258 "failed to find known CxSR latency "
8259 "(found ddr%s fsb freq %d, mem freq %d), "
8261 (dev_priv->is_ddr3 == 1) ? "3" : "2",
8262 dev_priv->fsb_freq, dev_priv->mem_freq);
8263 /* Disable CxSR and never update its watermark again */
8264 intel_set_memory_cxsr(dev_priv, false);
8265 dev_priv->wm_disp = &nop_funcs;
8267 dev_priv->wm_disp = &pnv_wm_funcs;
8268 } else if (DISPLAY_VER(dev_priv) == 4) {
8269 dev_priv->wm_disp = &i965_wm_funcs;
8270 } else if (DISPLAY_VER(dev_priv) == 3) {
8271 dev_priv->wm_disp = &i9xx_wm_funcs;
8272 } else if (DISPLAY_VER(dev_priv) == 2) {
8273 if (INTEL_NUM_PIPES(dev_priv) == 1)
8274 dev_priv->wm_disp = &i845_wm_funcs;
8276 dev_priv->wm_disp = &i9xx_wm_funcs;
8278 drm_err(&dev_priv->drm,
8279 "unexpected fall-through in %s\n", __func__);
8280 dev_priv->wm_disp = &nop_funcs;
8284 void intel_pm_setup(struct drm_i915_private *dev_priv)
8286 dev_priv->runtime_pm.suspended = false;
8287 atomic_set(&dev_priv->runtime_pm.wakeref_count, 0);
8290 static struct intel_global_state *intel_dbuf_duplicate_state(struct intel_global_obj *obj)
8292 struct intel_dbuf_state *dbuf_state;
8294 dbuf_state = kmemdup(obj->state, sizeof(*dbuf_state), GFP_KERNEL);
8298 return &dbuf_state->base;
8301 static void intel_dbuf_destroy_state(struct intel_global_obj *obj,
8302 struct intel_global_state *state)
8307 static const struct intel_global_state_funcs intel_dbuf_funcs = {
8308 .atomic_duplicate_state = intel_dbuf_duplicate_state,
8309 .atomic_destroy_state = intel_dbuf_destroy_state,
8312 struct intel_dbuf_state *
8313 intel_atomic_get_dbuf_state(struct intel_atomic_state *state)
8315 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
8316 struct intel_global_state *dbuf_state;
8318 dbuf_state = intel_atomic_get_global_obj_state(state, &dev_priv->dbuf.obj);
8319 if (IS_ERR(dbuf_state))
8320 return ERR_CAST(dbuf_state);
8322 return to_intel_dbuf_state(dbuf_state);
8325 int intel_dbuf_init(struct drm_i915_private *dev_priv)
8327 struct intel_dbuf_state *dbuf_state;
8329 dbuf_state = kzalloc(sizeof(*dbuf_state), GFP_KERNEL);
8333 intel_atomic_global_obj_init(dev_priv, &dev_priv->dbuf.obj,
8334 &dbuf_state->base, &intel_dbuf_funcs);
8340 * Configure MBUS_CTL and all DBUF_CTL_S of each slice to join_mbus state before
8341 * update the request state of all DBUS slices.
8343 static void update_mbus_pre_enable(struct intel_atomic_state *state)
8345 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
8346 u32 mbus_ctl, dbuf_min_tracker_val;
8347 enum dbuf_slice slice;
8348 const struct intel_dbuf_state *dbuf_state =
8349 intel_atomic_get_new_dbuf_state(state);
8351 if (!HAS_MBUS_JOINING(dev_priv))
8355 * TODO: Implement vblank synchronized MBUS joining changes.
8356 * Must be properly coordinated with dbuf reprogramming.
8358 if (dbuf_state->joined_mbus) {
8359 mbus_ctl = MBUS_HASHING_MODE_1x4 | MBUS_JOIN |
8360 MBUS_JOIN_PIPE_SELECT_NONE;
8361 dbuf_min_tracker_val = DBUF_MIN_TRACKER_STATE_SERVICE(3);
8363 mbus_ctl = MBUS_HASHING_MODE_2x2 |
8364 MBUS_JOIN_PIPE_SELECT_NONE;
8365 dbuf_min_tracker_val = DBUF_MIN_TRACKER_STATE_SERVICE(1);
8368 intel_de_rmw(dev_priv, MBUS_CTL,
8369 MBUS_HASHING_MODE_MASK | MBUS_JOIN |
8370 MBUS_JOIN_PIPE_SELECT_MASK, mbus_ctl);
8372 for_each_dbuf_slice(dev_priv, slice)
8373 intel_de_rmw(dev_priv, DBUF_CTL_S(slice),
8374 DBUF_MIN_TRACKER_STATE_SERVICE_MASK,
8375 dbuf_min_tracker_val);
8378 void intel_dbuf_pre_plane_update(struct intel_atomic_state *state)
8380 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
8381 const struct intel_dbuf_state *new_dbuf_state =
8382 intel_atomic_get_new_dbuf_state(state);
8383 const struct intel_dbuf_state *old_dbuf_state =
8384 intel_atomic_get_old_dbuf_state(state);
8386 if (!new_dbuf_state ||
8387 ((new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices)
8388 && (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus)))
8391 WARN_ON(!new_dbuf_state->base.changed);
8393 update_mbus_pre_enable(state);
8394 gen9_dbuf_slices_update(dev_priv,
8395 old_dbuf_state->enabled_slices |
8396 new_dbuf_state->enabled_slices);
8399 void intel_dbuf_post_plane_update(struct intel_atomic_state *state)
8401 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
8402 const struct intel_dbuf_state *new_dbuf_state =
8403 intel_atomic_get_new_dbuf_state(state);
8404 const struct intel_dbuf_state *old_dbuf_state =
8405 intel_atomic_get_old_dbuf_state(state);
8407 if (!new_dbuf_state ||
8408 ((new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices)
8409 && (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus)))
8412 WARN_ON(!new_dbuf_state->base.changed);
8414 gen9_dbuf_slices_update(dev_priv,
8415 new_dbuf_state->enabled_slices);
8418 void intel_mbus_dbox_update(struct intel_atomic_state *state)
8420 struct drm_i915_private *i915 = to_i915(state->base.dev);
8421 const struct intel_dbuf_state *new_dbuf_state, *old_dbuf_state;
8422 const struct intel_crtc_state *new_crtc_state;
8423 const struct intel_crtc *crtc;
8427 if (DISPLAY_VER(i915) < 11)
8430 new_dbuf_state = intel_atomic_get_new_dbuf_state(state);
8431 old_dbuf_state = intel_atomic_get_old_dbuf_state(state);
8432 if (!new_dbuf_state ||
8433 (new_dbuf_state->joined_mbus == old_dbuf_state->joined_mbus &&
8434 new_dbuf_state->active_pipes == old_dbuf_state->active_pipes))
8437 if (DISPLAY_VER(i915) >= 12) {
8438 val |= MBUS_DBOX_B2B_TRANSACTIONS_MAX(16);
8439 val |= MBUS_DBOX_B2B_TRANSACTIONS_DELAY(1);
8440 val |= MBUS_DBOX_REGULATE_B2B_TRANSACTIONS_EN;
8443 /* Wa_22010947358:adl-p */
8444 if (IS_ALDERLAKE_P(i915))
8445 val |= new_dbuf_state->joined_mbus ? MBUS_DBOX_A_CREDIT(6) :
8446 MBUS_DBOX_A_CREDIT(4);
8448 val |= MBUS_DBOX_A_CREDIT(2);
8450 if (IS_ALDERLAKE_P(i915)) {
8451 val |= MBUS_DBOX_BW_CREDIT(2);
8452 val |= MBUS_DBOX_B_CREDIT(8);
8453 } else if (DISPLAY_VER(i915) >= 12) {
8454 val |= MBUS_DBOX_BW_CREDIT(2);
8455 val |= MBUS_DBOX_B_CREDIT(12);
8457 val |= MBUS_DBOX_BW_CREDIT(1);
8458 val |= MBUS_DBOX_B_CREDIT(8);
8461 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
8462 if (!new_crtc_state->hw.active ||
8463 !intel_crtc_needs_modeset(new_crtc_state))
8466 intel_de_write(i915, PIPE_MBUS_DBOX_CTL(crtc->pipe), val);