1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2012 Intel Corporation
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun * paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun * Software.
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*4882a593Smuzhiyun * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*4882a593Smuzhiyun * IN THE SOFTWARE.
22*4882a593Smuzhiyun *
23*4882a593Smuzhiyun * Authors:
24*4882a593Smuzhiyun * Eugeni Dodonov <eugeni.dodonov@intel.com>
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun */
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun #include <linux/module.h>
29*4882a593Smuzhiyun #include <linux/pm_runtime.h>
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #include <drm/drm_atomic_helper.h>
32*4882a593Smuzhiyun #include <drm/drm_fourcc.h>
33*4882a593Smuzhiyun #include <drm/drm_plane_helper.h>
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #include "display/intel_atomic.h"
36*4882a593Smuzhiyun #include "display/intel_bw.h"
37*4882a593Smuzhiyun #include "display/intel_display_types.h"
38*4882a593Smuzhiyun #include "display/intel_fbc.h"
39*4882a593Smuzhiyun #include "display/intel_sprite.h"
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #include "gt/intel_llc.h"
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun #include "i915_drv.h"
44*4882a593Smuzhiyun #include "i915_fixed.h"
45*4882a593Smuzhiyun #include "i915_irq.h"
46*4882a593Smuzhiyun #include "i915_trace.h"
47*4882a593Smuzhiyun #include "intel_pm.h"
48*4882a593Smuzhiyun #include "intel_sideband.h"
49*4882a593Smuzhiyun #include "../../../platform/x86/intel_ips.h"
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun /* Stores plane specific WM parameters */
52*4882a593Smuzhiyun struct skl_wm_params {
53*4882a593Smuzhiyun bool x_tiled, y_tiled;
54*4882a593Smuzhiyun bool rc_surface;
55*4882a593Smuzhiyun bool is_planar;
56*4882a593Smuzhiyun u32 width;
57*4882a593Smuzhiyun u8 cpp;
58*4882a593Smuzhiyun u32 plane_pixel_rate;
59*4882a593Smuzhiyun u32 y_min_scanlines;
60*4882a593Smuzhiyun u32 plane_bytes_per_line;
61*4882a593Smuzhiyun uint_fixed_16_16_t plane_blocks_per_line;
62*4882a593Smuzhiyun uint_fixed_16_16_t y_tile_minimum;
63*4882a593Smuzhiyun u32 linetime_us;
64*4882a593Smuzhiyun u32 dbuf_block_size;
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /* used in computing the new watermarks state */
68*4882a593Smuzhiyun struct intel_wm_config {
69*4882a593Smuzhiyun unsigned int num_pipes_active;
70*4882a593Smuzhiyun bool sprites_enabled;
71*4882a593Smuzhiyun bool sprites_scaled;
72*4882a593Smuzhiyun };
73*4882a593Smuzhiyun
gen9_init_clock_gating(struct drm_i915_private * dev_priv)74*4882a593Smuzhiyun static void gen9_init_clock_gating(struct drm_i915_private *dev_priv)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun if (HAS_LLC(dev_priv)) {
77*4882a593Smuzhiyun /*
78*4882a593Smuzhiyun * WaCompressedResourceDisplayNewHashMode:skl,kbl
79*4882a593Smuzhiyun * Display WA #0390: skl,kbl
80*4882a593Smuzhiyun *
81*4882a593Smuzhiyun * Must match Sampler, Pixel Back End, and Media. See
82*4882a593Smuzhiyun * WaCompressedResourceSamplerPbeMediaNewHashMode.
83*4882a593Smuzhiyun */
84*4882a593Smuzhiyun I915_WRITE(CHICKEN_PAR1_1,
85*4882a593Smuzhiyun I915_READ(CHICKEN_PAR1_1) |
86*4882a593Smuzhiyun SKL_DE_COMPRESSED_HASH_MODE);
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun /* See Bspec note for PSR2_CTL bit 31, Wa#828:skl,bxt,kbl,cfl */
90*4882a593Smuzhiyun I915_WRITE(CHICKEN_PAR1_1,
91*4882a593Smuzhiyun I915_READ(CHICKEN_PAR1_1) | SKL_EDP_PSR_FIX_RDWRAP);
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun /* WaEnableChickenDCPR:skl,bxt,kbl,glk,cfl */
94*4882a593Smuzhiyun I915_WRITE(GEN8_CHICKEN_DCPR_1,
95*4882a593Smuzhiyun I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM);
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun /*
98*4882a593Smuzhiyun * WaFbcWakeMemOn:skl,bxt,kbl,glk,cfl
99*4882a593Smuzhiyun * Display WA #0859: skl,bxt,kbl,glk,cfl
100*4882a593Smuzhiyun */
101*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
102*4882a593Smuzhiyun DISP_FBC_MEMORY_WAKE);
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun
bxt_init_clock_gating(struct drm_i915_private * dev_priv)105*4882a593Smuzhiyun static void bxt_init_clock_gating(struct drm_i915_private *dev_priv)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun gen9_init_clock_gating(dev_priv);
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun /* WaDisableSDEUnitClockGating:bxt */
110*4882a593Smuzhiyun I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
111*4882a593Smuzhiyun GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun /*
114*4882a593Smuzhiyun * FIXME:
115*4882a593Smuzhiyun * GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ applies on 3x6 GT SKUs only.
116*4882a593Smuzhiyun */
117*4882a593Smuzhiyun I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
118*4882a593Smuzhiyun GEN8_HDCUNIT_CLOCK_GATE_DISABLE_HDCREQ);
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun /*
121*4882a593Smuzhiyun * Wa: Backlight PWM may stop in the asserted state, causing backlight
122*4882a593Smuzhiyun * to stay fully on.
123*4882a593Smuzhiyun */
124*4882a593Smuzhiyun I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
125*4882a593Smuzhiyun PWM1_GATING_DIS | PWM2_GATING_DIS);
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun /*
128*4882a593Smuzhiyun * Lower the display internal timeout.
129*4882a593Smuzhiyun * This is needed to avoid any hard hangs when DSI port PLL
130*4882a593Smuzhiyun * is off and a MMIO access is attempted by any privilege
131*4882a593Smuzhiyun * application, using batch buffers or any other means.
132*4882a593Smuzhiyun */
133*4882a593Smuzhiyun I915_WRITE(RM_TIMEOUT, MMIO_TIMEOUT_US(950));
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun /*
136*4882a593Smuzhiyun * WaFbcTurnOffFbcWatermark:bxt
137*4882a593Smuzhiyun * Display WA #0562: bxt
138*4882a593Smuzhiyun */
139*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
140*4882a593Smuzhiyun DISP_FBC_WM_DIS);
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun /*
143*4882a593Smuzhiyun * WaFbcHighMemBwCorruptionAvoidance:bxt
144*4882a593Smuzhiyun * Display WA #0883: bxt
145*4882a593Smuzhiyun */
146*4882a593Smuzhiyun I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
147*4882a593Smuzhiyun ILK_DPFC_DISABLE_DUMMY0);
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun
glk_init_clock_gating(struct drm_i915_private * dev_priv)150*4882a593Smuzhiyun static void glk_init_clock_gating(struct drm_i915_private *dev_priv)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun gen9_init_clock_gating(dev_priv);
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /*
155*4882a593Smuzhiyun * WaDisablePWMClockGating:glk
156*4882a593Smuzhiyun * Backlight PWM may stop in the asserted state, causing backlight
157*4882a593Smuzhiyun * to stay fully on.
158*4882a593Smuzhiyun */
159*4882a593Smuzhiyun I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
160*4882a593Smuzhiyun PWM1_GATING_DIS | PWM2_GATING_DIS);
161*4882a593Smuzhiyun }
162*4882a593Smuzhiyun
pnv_get_mem_freq(struct drm_i915_private * dev_priv)163*4882a593Smuzhiyun static void pnv_get_mem_freq(struct drm_i915_private *dev_priv)
164*4882a593Smuzhiyun {
165*4882a593Smuzhiyun u32 tmp;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun tmp = I915_READ(CLKCFG);
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun switch (tmp & CLKCFG_FSB_MASK) {
170*4882a593Smuzhiyun case CLKCFG_FSB_533:
171*4882a593Smuzhiyun dev_priv->fsb_freq = 533; /* 133*4 */
172*4882a593Smuzhiyun break;
173*4882a593Smuzhiyun case CLKCFG_FSB_800:
174*4882a593Smuzhiyun dev_priv->fsb_freq = 800; /* 200*4 */
175*4882a593Smuzhiyun break;
176*4882a593Smuzhiyun case CLKCFG_FSB_667:
177*4882a593Smuzhiyun dev_priv->fsb_freq = 667; /* 167*4 */
178*4882a593Smuzhiyun break;
179*4882a593Smuzhiyun case CLKCFG_FSB_400:
180*4882a593Smuzhiyun dev_priv->fsb_freq = 400; /* 100*4 */
181*4882a593Smuzhiyun break;
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun switch (tmp & CLKCFG_MEM_MASK) {
185*4882a593Smuzhiyun case CLKCFG_MEM_533:
186*4882a593Smuzhiyun dev_priv->mem_freq = 533;
187*4882a593Smuzhiyun break;
188*4882a593Smuzhiyun case CLKCFG_MEM_667:
189*4882a593Smuzhiyun dev_priv->mem_freq = 667;
190*4882a593Smuzhiyun break;
191*4882a593Smuzhiyun case CLKCFG_MEM_800:
192*4882a593Smuzhiyun dev_priv->mem_freq = 800;
193*4882a593Smuzhiyun break;
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun /* detect pineview DDR3 setting */
197*4882a593Smuzhiyun tmp = I915_READ(CSHRDDR3CTL);
198*4882a593Smuzhiyun dev_priv->is_ddr3 = (tmp & CSHRDDR3CTL_DDR3) ? 1 : 0;
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun
ilk_get_mem_freq(struct drm_i915_private * dev_priv)201*4882a593Smuzhiyun static void ilk_get_mem_freq(struct drm_i915_private *dev_priv)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun u16 ddrpll, csipll;
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun ddrpll = intel_uncore_read16(&dev_priv->uncore, DDRMPLL1);
206*4882a593Smuzhiyun csipll = intel_uncore_read16(&dev_priv->uncore, CSIPLL0);
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun switch (ddrpll & 0xff) {
209*4882a593Smuzhiyun case 0xc:
210*4882a593Smuzhiyun dev_priv->mem_freq = 800;
211*4882a593Smuzhiyun break;
212*4882a593Smuzhiyun case 0x10:
213*4882a593Smuzhiyun dev_priv->mem_freq = 1066;
214*4882a593Smuzhiyun break;
215*4882a593Smuzhiyun case 0x14:
216*4882a593Smuzhiyun dev_priv->mem_freq = 1333;
217*4882a593Smuzhiyun break;
218*4882a593Smuzhiyun case 0x18:
219*4882a593Smuzhiyun dev_priv->mem_freq = 1600;
220*4882a593Smuzhiyun break;
221*4882a593Smuzhiyun default:
222*4882a593Smuzhiyun drm_dbg(&dev_priv->drm, "unknown memory frequency 0x%02x\n",
223*4882a593Smuzhiyun ddrpll & 0xff);
224*4882a593Smuzhiyun dev_priv->mem_freq = 0;
225*4882a593Smuzhiyun break;
226*4882a593Smuzhiyun }
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun switch (csipll & 0x3ff) {
229*4882a593Smuzhiyun case 0x00c:
230*4882a593Smuzhiyun dev_priv->fsb_freq = 3200;
231*4882a593Smuzhiyun break;
232*4882a593Smuzhiyun case 0x00e:
233*4882a593Smuzhiyun dev_priv->fsb_freq = 3733;
234*4882a593Smuzhiyun break;
235*4882a593Smuzhiyun case 0x010:
236*4882a593Smuzhiyun dev_priv->fsb_freq = 4266;
237*4882a593Smuzhiyun break;
238*4882a593Smuzhiyun case 0x012:
239*4882a593Smuzhiyun dev_priv->fsb_freq = 4800;
240*4882a593Smuzhiyun break;
241*4882a593Smuzhiyun case 0x014:
242*4882a593Smuzhiyun dev_priv->fsb_freq = 5333;
243*4882a593Smuzhiyun break;
244*4882a593Smuzhiyun case 0x016:
245*4882a593Smuzhiyun dev_priv->fsb_freq = 5866;
246*4882a593Smuzhiyun break;
247*4882a593Smuzhiyun case 0x018:
248*4882a593Smuzhiyun dev_priv->fsb_freq = 6400;
249*4882a593Smuzhiyun break;
250*4882a593Smuzhiyun default:
251*4882a593Smuzhiyun drm_dbg(&dev_priv->drm, "unknown fsb frequency 0x%04x\n",
252*4882a593Smuzhiyun csipll & 0x3ff);
253*4882a593Smuzhiyun dev_priv->fsb_freq = 0;
254*4882a593Smuzhiyun break;
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun }
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun static const struct cxsr_latency cxsr_latency_table[] = {
259*4882a593Smuzhiyun {1, 0, 800, 400, 3382, 33382, 3983, 33983}, /* DDR2-400 SC */
260*4882a593Smuzhiyun {1, 0, 800, 667, 3354, 33354, 3807, 33807}, /* DDR2-667 SC */
261*4882a593Smuzhiyun {1, 0, 800, 800, 3347, 33347, 3763, 33763}, /* DDR2-800 SC */
262*4882a593Smuzhiyun {1, 1, 800, 667, 6420, 36420, 6873, 36873}, /* DDR3-667 SC */
263*4882a593Smuzhiyun {1, 1, 800, 800, 5902, 35902, 6318, 36318}, /* DDR3-800 SC */
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun {1, 0, 667, 400, 3400, 33400, 4021, 34021}, /* DDR2-400 SC */
266*4882a593Smuzhiyun {1, 0, 667, 667, 3372, 33372, 3845, 33845}, /* DDR2-667 SC */
267*4882a593Smuzhiyun {1, 0, 667, 800, 3386, 33386, 3822, 33822}, /* DDR2-800 SC */
268*4882a593Smuzhiyun {1, 1, 667, 667, 6438, 36438, 6911, 36911}, /* DDR3-667 SC */
269*4882a593Smuzhiyun {1, 1, 667, 800, 5941, 35941, 6377, 36377}, /* DDR3-800 SC */
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun {1, 0, 400, 400, 3472, 33472, 4173, 34173}, /* DDR2-400 SC */
272*4882a593Smuzhiyun {1, 0, 400, 667, 3443, 33443, 3996, 33996}, /* DDR2-667 SC */
273*4882a593Smuzhiyun {1, 0, 400, 800, 3430, 33430, 3946, 33946}, /* DDR2-800 SC */
274*4882a593Smuzhiyun {1, 1, 400, 667, 6509, 36509, 7062, 37062}, /* DDR3-667 SC */
275*4882a593Smuzhiyun {1, 1, 400, 800, 5985, 35985, 6501, 36501}, /* DDR3-800 SC */
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun {0, 0, 800, 400, 3438, 33438, 4065, 34065}, /* DDR2-400 SC */
278*4882a593Smuzhiyun {0, 0, 800, 667, 3410, 33410, 3889, 33889}, /* DDR2-667 SC */
279*4882a593Smuzhiyun {0, 0, 800, 800, 3403, 33403, 3845, 33845}, /* DDR2-800 SC */
280*4882a593Smuzhiyun {0, 1, 800, 667, 6476, 36476, 6955, 36955}, /* DDR3-667 SC */
281*4882a593Smuzhiyun {0, 1, 800, 800, 5958, 35958, 6400, 36400}, /* DDR3-800 SC */
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun {0, 0, 667, 400, 3456, 33456, 4103, 34106}, /* DDR2-400 SC */
284*4882a593Smuzhiyun {0, 0, 667, 667, 3428, 33428, 3927, 33927}, /* DDR2-667 SC */
285*4882a593Smuzhiyun {0, 0, 667, 800, 3443, 33443, 3905, 33905}, /* DDR2-800 SC */
286*4882a593Smuzhiyun {0, 1, 667, 667, 6494, 36494, 6993, 36993}, /* DDR3-667 SC */
287*4882a593Smuzhiyun {0, 1, 667, 800, 5998, 35998, 6460, 36460}, /* DDR3-800 SC */
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun {0, 0, 400, 400, 3528, 33528, 4255, 34255}, /* DDR2-400 SC */
290*4882a593Smuzhiyun {0, 0, 400, 667, 3500, 33500, 4079, 34079}, /* DDR2-667 SC */
291*4882a593Smuzhiyun {0, 0, 400, 800, 3487, 33487, 4029, 34029}, /* DDR2-800 SC */
292*4882a593Smuzhiyun {0, 1, 400, 667, 6566, 36566, 7145, 37145}, /* DDR3-667 SC */
293*4882a593Smuzhiyun {0, 1, 400, 800, 6042, 36042, 6584, 36584}, /* DDR3-800 SC */
294*4882a593Smuzhiyun };
295*4882a593Smuzhiyun
intel_get_cxsr_latency(bool is_desktop,bool is_ddr3,int fsb,int mem)296*4882a593Smuzhiyun static const struct cxsr_latency *intel_get_cxsr_latency(bool is_desktop,
297*4882a593Smuzhiyun bool is_ddr3,
298*4882a593Smuzhiyun int fsb,
299*4882a593Smuzhiyun int mem)
300*4882a593Smuzhiyun {
301*4882a593Smuzhiyun const struct cxsr_latency *latency;
302*4882a593Smuzhiyun int i;
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun if (fsb == 0 || mem == 0)
305*4882a593Smuzhiyun return NULL;
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(cxsr_latency_table); i++) {
308*4882a593Smuzhiyun latency = &cxsr_latency_table[i];
309*4882a593Smuzhiyun if (is_desktop == latency->is_desktop &&
310*4882a593Smuzhiyun is_ddr3 == latency->is_ddr3 &&
311*4882a593Smuzhiyun fsb == latency->fsb_freq && mem == latency->mem_freq)
312*4882a593Smuzhiyun return latency;
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n");
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun return NULL;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun
chv_set_memory_dvfs(struct drm_i915_private * dev_priv,bool enable)320*4882a593Smuzhiyun static void chv_set_memory_dvfs(struct drm_i915_private *dev_priv, bool enable)
321*4882a593Smuzhiyun {
322*4882a593Smuzhiyun u32 val;
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun vlv_punit_get(dev_priv);
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
327*4882a593Smuzhiyun if (enable)
328*4882a593Smuzhiyun val &= ~FORCE_DDR_HIGH_FREQ;
329*4882a593Smuzhiyun else
330*4882a593Smuzhiyun val |= FORCE_DDR_HIGH_FREQ;
331*4882a593Smuzhiyun val &= ~FORCE_DDR_LOW_FREQ;
332*4882a593Smuzhiyun val |= FORCE_DDR_FREQ_REQ_ACK;
333*4882a593Smuzhiyun vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val);
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) &
336*4882a593Smuzhiyun FORCE_DDR_FREQ_REQ_ACK) == 0, 3))
337*4882a593Smuzhiyun drm_err(&dev_priv->drm,
338*4882a593Smuzhiyun "timed out waiting for Punit DDR DVFS request\n");
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun vlv_punit_put(dev_priv);
341*4882a593Smuzhiyun }
342*4882a593Smuzhiyun
chv_set_memory_pm5(struct drm_i915_private * dev_priv,bool enable)343*4882a593Smuzhiyun static void chv_set_memory_pm5(struct drm_i915_private *dev_priv, bool enable)
344*4882a593Smuzhiyun {
345*4882a593Smuzhiyun u32 val;
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun vlv_punit_get(dev_priv);
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM);
350*4882a593Smuzhiyun if (enable)
351*4882a593Smuzhiyun val |= DSP_MAXFIFO_PM5_ENABLE;
352*4882a593Smuzhiyun else
353*4882a593Smuzhiyun val &= ~DSP_MAXFIFO_PM5_ENABLE;
354*4882a593Smuzhiyun vlv_punit_write(dev_priv, PUNIT_REG_DSPSSPM, val);
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun vlv_punit_put(dev_priv);
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun #define FW_WM(value, plane) \
360*4882a593Smuzhiyun (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK)
361*4882a593Smuzhiyun
_intel_set_memory_cxsr(struct drm_i915_private * dev_priv,bool enable)362*4882a593Smuzhiyun static bool _intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable)
363*4882a593Smuzhiyun {
364*4882a593Smuzhiyun bool was_enabled;
365*4882a593Smuzhiyun u32 val;
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
368*4882a593Smuzhiyun was_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
369*4882a593Smuzhiyun I915_WRITE(FW_BLC_SELF_VLV, enable ? FW_CSPWRDWNEN : 0);
370*4882a593Smuzhiyun POSTING_READ(FW_BLC_SELF_VLV);
371*4882a593Smuzhiyun } else if (IS_G4X(dev_priv) || IS_I965GM(dev_priv)) {
372*4882a593Smuzhiyun was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
373*4882a593Smuzhiyun I915_WRITE(FW_BLC_SELF, enable ? FW_BLC_SELF_EN : 0);
374*4882a593Smuzhiyun POSTING_READ(FW_BLC_SELF);
375*4882a593Smuzhiyun } else if (IS_PINEVIEW(dev_priv)) {
376*4882a593Smuzhiyun val = I915_READ(DSPFW3);
377*4882a593Smuzhiyun was_enabled = val & PINEVIEW_SELF_REFRESH_EN;
378*4882a593Smuzhiyun if (enable)
379*4882a593Smuzhiyun val |= PINEVIEW_SELF_REFRESH_EN;
380*4882a593Smuzhiyun else
381*4882a593Smuzhiyun val &= ~PINEVIEW_SELF_REFRESH_EN;
382*4882a593Smuzhiyun I915_WRITE(DSPFW3, val);
383*4882a593Smuzhiyun POSTING_READ(DSPFW3);
384*4882a593Smuzhiyun } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv)) {
385*4882a593Smuzhiyun was_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
386*4882a593Smuzhiyun val = enable ? _MASKED_BIT_ENABLE(FW_BLC_SELF_EN) :
387*4882a593Smuzhiyun _MASKED_BIT_DISABLE(FW_BLC_SELF_EN);
388*4882a593Smuzhiyun I915_WRITE(FW_BLC_SELF, val);
389*4882a593Smuzhiyun POSTING_READ(FW_BLC_SELF);
390*4882a593Smuzhiyun } else if (IS_I915GM(dev_priv)) {
391*4882a593Smuzhiyun /*
392*4882a593Smuzhiyun * FIXME can't find a bit like this for 915G, and
393*4882a593Smuzhiyun * and yet it does have the related watermark in
394*4882a593Smuzhiyun * FW_BLC_SELF. What's going on?
395*4882a593Smuzhiyun */
396*4882a593Smuzhiyun was_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
397*4882a593Smuzhiyun val = enable ? _MASKED_BIT_ENABLE(INSTPM_SELF_EN) :
398*4882a593Smuzhiyun _MASKED_BIT_DISABLE(INSTPM_SELF_EN);
399*4882a593Smuzhiyun I915_WRITE(INSTPM, val);
400*4882a593Smuzhiyun POSTING_READ(INSTPM);
401*4882a593Smuzhiyun } else {
402*4882a593Smuzhiyun return false;
403*4882a593Smuzhiyun }
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun trace_intel_memory_cxsr(dev_priv, was_enabled, enable);
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "memory self-refresh is %s (was %s)\n",
408*4882a593Smuzhiyun enableddisabled(enable),
409*4882a593Smuzhiyun enableddisabled(was_enabled));
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun return was_enabled;
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun /**
415*4882a593Smuzhiyun * intel_set_memory_cxsr - Configure CxSR state
416*4882a593Smuzhiyun * @dev_priv: i915 device
417*4882a593Smuzhiyun * @enable: Allow vs. disallow CxSR
418*4882a593Smuzhiyun *
419*4882a593Smuzhiyun * Allow or disallow the system to enter a special CxSR
420*4882a593Smuzhiyun * (C-state self refresh) state. What typically happens in CxSR mode
421*4882a593Smuzhiyun * is that several display FIFOs may get combined into a single larger
422*4882a593Smuzhiyun * FIFO for a particular plane (so called max FIFO mode) to allow the
423*4882a593Smuzhiyun * system to defer memory fetches longer, and the memory will enter
424*4882a593Smuzhiyun * self refresh.
425*4882a593Smuzhiyun *
426*4882a593Smuzhiyun * Note that enabling CxSR does not guarantee that the system enter
427*4882a593Smuzhiyun * this special mode, nor does it guarantee that the system stays
428*4882a593Smuzhiyun * in that mode once entered. So this just allows/disallows the system
429*4882a593Smuzhiyun * to autonomously utilize the CxSR mode. Other factors such as core
430*4882a593Smuzhiyun * C-states will affect when/if the system actually enters/exits the
431*4882a593Smuzhiyun * CxSR mode.
432*4882a593Smuzhiyun *
433*4882a593Smuzhiyun * Note that on VLV/CHV this actually only controls the max FIFO mode,
434*4882a593Smuzhiyun * and the system is free to enter/exit memory self refresh at any time
435*4882a593Smuzhiyun * even when the use of CxSR has been disallowed.
436*4882a593Smuzhiyun *
437*4882a593Smuzhiyun * While the system is actually in the CxSR/max FIFO mode, some plane
438*4882a593Smuzhiyun * control registers will not get latched on vblank. Thus in order to
439*4882a593Smuzhiyun * guarantee the system will respond to changes in the plane registers
440*4882a593Smuzhiyun * we must always disallow CxSR prior to making changes to those registers.
441*4882a593Smuzhiyun * Unfortunately the system will re-evaluate the CxSR conditions at
442*4882a593Smuzhiyun * frame start which happens after vblank start (which is when the plane
443*4882a593Smuzhiyun * registers would get latched), so we can't proceed with the plane update
444*4882a593Smuzhiyun * during the same frame where we disallowed CxSR.
445*4882a593Smuzhiyun *
446*4882a593Smuzhiyun * Certain platforms also have a deeper HPLL SR mode. Fortunately the
447*4882a593Smuzhiyun * HPLL SR mode depends on CxSR itself, so we don't have to hand hold
448*4882a593Smuzhiyun * the hardware w.r.t. HPLL SR when writing to plane registers.
449*4882a593Smuzhiyun * Disallowing just CxSR is sufficient.
450*4882a593Smuzhiyun */
intel_set_memory_cxsr(struct drm_i915_private * dev_priv,bool enable)451*4882a593Smuzhiyun bool intel_set_memory_cxsr(struct drm_i915_private *dev_priv, bool enable)
452*4882a593Smuzhiyun {
453*4882a593Smuzhiyun bool ret;
454*4882a593Smuzhiyun
455*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
456*4882a593Smuzhiyun ret = _intel_set_memory_cxsr(dev_priv, enable);
457*4882a593Smuzhiyun if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
458*4882a593Smuzhiyun dev_priv->wm.vlv.cxsr = enable;
459*4882a593Smuzhiyun else if (IS_G4X(dev_priv))
460*4882a593Smuzhiyun dev_priv->wm.g4x.cxsr = enable;
461*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun return ret;
464*4882a593Smuzhiyun }
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun /*
467*4882a593Smuzhiyun * Latency for FIFO fetches is dependent on several factors:
468*4882a593Smuzhiyun * - memory configuration (speed, channels)
469*4882a593Smuzhiyun * - chipset
470*4882a593Smuzhiyun * - current MCH state
471*4882a593Smuzhiyun * It can be fairly high in some situations, so here we assume a fairly
472*4882a593Smuzhiyun * pessimal value. It's a tradeoff between extra memory fetches (if we
473*4882a593Smuzhiyun * set this value too high, the FIFO will fetch frequently to stay full)
474*4882a593Smuzhiyun * and power consumption (set it too low to save power and we might see
475*4882a593Smuzhiyun * FIFO underruns and display "flicker").
476*4882a593Smuzhiyun *
477*4882a593Smuzhiyun * A value of 5us seems to be a good balance; safe for very low end
478*4882a593Smuzhiyun * platforms but not overly aggressive on lower latency configs.
479*4882a593Smuzhiyun */
480*4882a593Smuzhiyun static const int pessimal_latency_ns = 5000;
481*4882a593Smuzhiyun
482*4882a593Smuzhiyun #define VLV_FIFO_START(dsparb, dsparb2, lo_shift, hi_shift) \
483*4882a593Smuzhiyun ((((dsparb) >> (lo_shift)) & 0xff) | ((((dsparb2) >> (hi_shift)) & 0x1) << 8))
484*4882a593Smuzhiyun
vlv_get_fifo_size(struct intel_crtc_state * crtc_state)485*4882a593Smuzhiyun static void vlv_get_fifo_size(struct intel_crtc_state *crtc_state)
486*4882a593Smuzhiyun {
487*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
488*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
489*4882a593Smuzhiyun struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state;
490*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
491*4882a593Smuzhiyun int sprite0_start, sprite1_start;
492*4882a593Smuzhiyun u32 dsparb, dsparb2, dsparb3;
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun switch (pipe) {
495*4882a593Smuzhiyun case PIPE_A:
496*4882a593Smuzhiyun dsparb = I915_READ(DSPARB);
497*4882a593Smuzhiyun dsparb2 = I915_READ(DSPARB2);
498*4882a593Smuzhiyun sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 0, 0);
499*4882a593Smuzhiyun sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 8, 4);
500*4882a593Smuzhiyun break;
501*4882a593Smuzhiyun case PIPE_B:
502*4882a593Smuzhiyun dsparb = I915_READ(DSPARB);
503*4882a593Smuzhiyun dsparb2 = I915_READ(DSPARB2);
504*4882a593Smuzhiyun sprite0_start = VLV_FIFO_START(dsparb, dsparb2, 16, 8);
505*4882a593Smuzhiyun sprite1_start = VLV_FIFO_START(dsparb, dsparb2, 24, 12);
506*4882a593Smuzhiyun break;
507*4882a593Smuzhiyun case PIPE_C:
508*4882a593Smuzhiyun dsparb2 = I915_READ(DSPARB2);
509*4882a593Smuzhiyun dsparb3 = I915_READ(DSPARB3);
510*4882a593Smuzhiyun sprite0_start = VLV_FIFO_START(dsparb3, dsparb2, 0, 16);
511*4882a593Smuzhiyun sprite1_start = VLV_FIFO_START(dsparb3, dsparb2, 8, 20);
512*4882a593Smuzhiyun break;
513*4882a593Smuzhiyun default:
514*4882a593Smuzhiyun MISSING_CASE(pipe);
515*4882a593Smuzhiyun return;
516*4882a593Smuzhiyun }
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun fifo_state->plane[PLANE_PRIMARY] = sprite0_start;
519*4882a593Smuzhiyun fifo_state->plane[PLANE_SPRITE0] = sprite1_start - sprite0_start;
520*4882a593Smuzhiyun fifo_state->plane[PLANE_SPRITE1] = 511 - sprite1_start;
521*4882a593Smuzhiyun fifo_state->plane[PLANE_CURSOR] = 63;
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun
i9xx_get_fifo_size(struct drm_i915_private * dev_priv,enum i9xx_plane_id i9xx_plane)524*4882a593Smuzhiyun static int i9xx_get_fifo_size(struct drm_i915_private *dev_priv,
525*4882a593Smuzhiyun enum i9xx_plane_id i9xx_plane)
526*4882a593Smuzhiyun {
527*4882a593Smuzhiyun u32 dsparb = I915_READ(DSPARB);
528*4882a593Smuzhiyun int size;
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun size = dsparb & 0x7f;
531*4882a593Smuzhiyun if (i9xx_plane == PLANE_B)
532*4882a593Smuzhiyun size = ((dsparb >> DSPARB_CSTART_SHIFT) & 0x7f) - size;
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n",
535*4882a593Smuzhiyun dsparb, plane_name(i9xx_plane), size);
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun return size;
538*4882a593Smuzhiyun }
539*4882a593Smuzhiyun
i830_get_fifo_size(struct drm_i915_private * dev_priv,enum i9xx_plane_id i9xx_plane)540*4882a593Smuzhiyun static int i830_get_fifo_size(struct drm_i915_private *dev_priv,
541*4882a593Smuzhiyun enum i9xx_plane_id i9xx_plane)
542*4882a593Smuzhiyun {
543*4882a593Smuzhiyun u32 dsparb = I915_READ(DSPARB);
544*4882a593Smuzhiyun int size;
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun size = dsparb & 0x1ff;
547*4882a593Smuzhiyun if (i9xx_plane == PLANE_B)
548*4882a593Smuzhiyun size = ((dsparb >> DSPARB_BEND_SHIFT) & 0x1ff) - size;
549*4882a593Smuzhiyun size >>= 1; /* Convert to cachelines */
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n",
552*4882a593Smuzhiyun dsparb, plane_name(i9xx_plane), size);
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun return size;
555*4882a593Smuzhiyun }
556*4882a593Smuzhiyun
i845_get_fifo_size(struct drm_i915_private * dev_priv,enum i9xx_plane_id i9xx_plane)557*4882a593Smuzhiyun static int i845_get_fifo_size(struct drm_i915_private *dev_priv,
558*4882a593Smuzhiyun enum i9xx_plane_id i9xx_plane)
559*4882a593Smuzhiyun {
560*4882a593Smuzhiyun u32 dsparb = I915_READ(DSPARB);
561*4882a593Smuzhiyun int size;
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun size = dsparb & 0x7f;
564*4882a593Smuzhiyun size >>= 2; /* Convert to cachelines */
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "FIFO size - (0x%08x) %c: %d\n",
567*4882a593Smuzhiyun dsparb, plane_name(i9xx_plane), size);
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun return size;
570*4882a593Smuzhiyun }
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun /* Pineview has different values for various configs */
573*4882a593Smuzhiyun static const struct intel_watermark_params pnv_display_wm = {
574*4882a593Smuzhiyun .fifo_size = PINEVIEW_DISPLAY_FIFO,
575*4882a593Smuzhiyun .max_wm = PINEVIEW_MAX_WM,
576*4882a593Smuzhiyun .default_wm = PINEVIEW_DFT_WM,
577*4882a593Smuzhiyun .guard_size = PINEVIEW_GUARD_WM,
578*4882a593Smuzhiyun .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
579*4882a593Smuzhiyun };
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun static const struct intel_watermark_params pnv_display_hplloff_wm = {
582*4882a593Smuzhiyun .fifo_size = PINEVIEW_DISPLAY_FIFO,
583*4882a593Smuzhiyun .max_wm = PINEVIEW_MAX_WM,
584*4882a593Smuzhiyun .default_wm = PINEVIEW_DFT_HPLLOFF_WM,
585*4882a593Smuzhiyun .guard_size = PINEVIEW_GUARD_WM,
586*4882a593Smuzhiyun .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
587*4882a593Smuzhiyun };
588*4882a593Smuzhiyun
589*4882a593Smuzhiyun static const struct intel_watermark_params pnv_cursor_wm = {
590*4882a593Smuzhiyun .fifo_size = PINEVIEW_CURSOR_FIFO,
591*4882a593Smuzhiyun .max_wm = PINEVIEW_CURSOR_MAX_WM,
592*4882a593Smuzhiyun .default_wm = PINEVIEW_CURSOR_DFT_WM,
593*4882a593Smuzhiyun .guard_size = PINEVIEW_CURSOR_GUARD_WM,
594*4882a593Smuzhiyun .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
595*4882a593Smuzhiyun };
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun static const struct intel_watermark_params pnv_cursor_hplloff_wm = {
598*4882a593Smuzhiyun .fifo_size = PINEVIEW_CURSOR_FIFO,
599*4882a593Smuzhiyun .max_wm = PINEVIEW_CURSOR_MAX_WM,
600*4882a593Smuzhiyun .default_wm = PINEVIEW_CURSOR_DFT_WM,
601*4882a593Smuzhiyun .guard_size = PINEVIEW_CURSOR_GUARD_WM,
602*4882a593Smuzhiyun .cacheline_size = PINEVIEW_FIFO_LINE_SIZE,
603*4882a593Smuzhiyun };
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun static const struct intel_watermark_params i965_cursor_wm_info = {
606*4882a593Smuzhiyun .fifo_size = I965_CURSOR_FIFO,
607*4882a593Smuzhiyun .max_wm = I965_CURSOR_MAX_WM,
608*4882a593Smuzhiyun .default_wm = I965_CURSOR_DFT_WM,
609*4882a593Smuzhiyun .guard_size = 2,
610*4882a593Smuzhiyun .cacheline_size = I915_FIFO_LINE_SIZE,
611*4882a593Smuzhiyun };
612*4882a593Smuzhiyun
613*4882a593Smuzhiyun static const struct intel_watermark_params i945_wm_info = {
614*4882a593Smuzhiyun .fifo_size = I945_FIFO_SIZE,
615*4882a593Smuzhiyun .max_wm = I915_MAX_WM,
616*4882a593Smuzhiyun .default_wm = 1,
617*4882a593Smuzhiyun .guard_size = 2,
618*4882a593Smuzhiyun .cacheline_size = I915_FIFO_LINE_SIZE,
619*4882a593Smuzhiyun };
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun static const struct intel_watermark_params i915_wm_info = {
622*4882a593Smuzhiyun .fifo_size = I915_FIFO_SIZE,
623*4882a593Smuzhiyun .max_wm = I915_MAX_WM,
624*4882a593Smuzhiyun .default_wm = 1,
625*4882a593Smuzhiyun .guard_size = 2,
626*4882a593Smuzhiyun .cacheline_size = I915_FIFO_LINE_SIZE,
627*4882a593Smuzhiyun };
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun static const struct intel_watermark_params i830_a_wm_info = {
630*4882a593Smuzhiyun .fifo_size = I855GM_FIFO_SIZE,
631*4882a593Smuzhiyun .max_wm = I915_MAX_WM,
632*4882a593Smuzhiyun .default_wm = 1,
633*4882a593Smuzhiyun .guard_size = 2,
634*4882a593Smuzhiyun .cacheline_size = I830_FIFO_LINE_SIZE,
635*4882a593Smuzhiyun };
636*4882a593Smuzhiyun
637*4882a593Smuzhiyun static const struct intel_watermark_params i830_bc_wm_info = {
638*4882a593Smuzhiyun .fifo_size = I855GM_FIFO_SIZE,
639*4882a593Smuzhiyun .max_wm = I915_MAX_WM/2,
640*4882a593Smuzhiyun .default_wm = 1,
641*4882a593Smuzhiyun .guard_size = 2,
642*4882a593Smuzhiyun .cacheline_size = I830_FIFO_LINE_SIZE,
643*4882a593Smuzhiyun };
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun static const struct intel_watermark_params i845_wm_info = {
646*4882a593Smuzhiyun .fifo_size = I830_FIFO_SIZE,
647*4882a593Smuzhiyun .max_wm = I915_MAX_WM,
648*4882a593Smuzhiyun .default_wm = 1,
649*4882a593Smuzhiyun .guard_size = 2,
650*4882a593Smuzhiyun .cacheline_size = I830_FIFO_LINE_SIZE,
651*4882a593Smuzhiyun };
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun /**
654*4882a593Smuzhiyun * intel_wm_method1 - Method 1 / "small buffer" watermark formula
655*4882a593Smuzhiyun * @pixel_rate: Pipe pixel rate in kHz
656*4882a593Smuzhiyun * @cpp: Plane bytes per pixel
657*4882a593Smuzhiyun * @latency: Memory wakeup latency in 0.1us units
658*4882a593Smuzhiyun *
659*4882a593Smuzhiyun * Compute the watermark using the method 1 or "small buffer"
660*4882a593Smuzhiyun * formula. The caller may additonally add extra cachelines
661*4882a593Smuzhiyun * to account for TLB misses and clock crossings.
662*4882a593Smuzhiyun *
663*4882a593Smuzhiyun * This method is concerned with the short term drain rate
664*4882a593Smuzhiyun * of the FIFO, ie. it does not account for blanking periods
665*4882a593Smuzhiyun * which would effectively reduce the average drain rate across
666*4882a593Smuzhiyun * a longer period. The name "small" refers to the fact the
667*4882a593Smuzhiyun * FIFO is relatively small compared to the amount of data
668*4882a593Smuzhiyun * fetched.
669*4882a593Smuzhiyun *
670*4882a593Smuzhiyun * The FIFO level vs. time graph might look something like:
671*4882a593Smuzhiyun *
672*4882a593Smuzhiyun * |\ |\
673*4882a593Smuzhiyun * | \ | \
674*4882a593Smuzhiyun * __---__---__ (- plane active, _ blanking)
675*4882a593Smuzhiyun * -> time
676*4882a593Smuzhiyun *
677*4882a593Smuzhiyun * or perhaps like this:
678*4882a593Smuzhiyun *
679*4882a593Smuzhiyun * |\|\ |\|\
680*4882a593Smuzhiyun * __----__----__ (- plane active, _ blanking)
681*4882a593Smuzhiyun * -> time
682*4882a593Smuzhiyun *
683*4882a593Smuzhiyun * Returns:
684*4882a593Smuzhiyun * The watermark in bytes
685*4882a593Smuzhiyun */
intel_wm_method1(unsigned int pixel_rate,unsigned int cpp,unsigned int latency)686*4882a593Smuzhiyun static unsigned int intel_wm_method1(unsigned int pixel_rate,
687*4882a593Smuzhiyun unsigned int cpp,
688*4882a593Smuzhiyun unsigned int latency)
689*4882a593Smuzhiyun {
690*4882a593Smuzhiyun u64 ret;
691*4882a593Smuzhiyun
692*4882a593Smuzhiyun ret = mul_u32_u32(pixel_rate, cpp * latency);
693*4882a593Smuzhiyun ret = DIV_ROUND_UP_ULL(ret, 10000);
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun return ret;
696*4882a593Smuzhiyun }
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun /**
699*4882a593Smuzhiyun * intel_wm_method2 - Method 2 / "large buffer" watermark formula
700*4882a593Smuzhiyun * @pixel_rate: Pipe pixel rate in kHz
701*4882a593Smuzhiyun * @htotal: Pipe horizontal total
702*4882a593Smuzhiyun * @width: Plane width in pixels
703*4882a593Smuzhiyun * @cpp: Plane bytes per pixel
704*4882a593Smuzhiyun * @latency: Memory wakeup latency in 0.1us units
705*4882a593Smuzhiyun *
706*4882a593Smuzhiyun * Compute the watermark using the method 2 or "large buffer"
707*4882a593Smuzhiyun * formula. The caller may additonally add extra cachelines
708*4882a593Smuzhiyun * to account for TLB misses and clock crossings.
709*4882a593Smuzhiyun *
710*4882a593Smuzhiyun * This method is concerned with the long term drain rate
711*4882a593Smuzhiyun * of the FIFO, ie. it does account for blanking periods
712*4882a593Smuzhiyun * which effectively reduce the average drain rate across
713*4882a593Smuzhiyun * a longer period. The name "large" refers to the fact the
714*4882a593Smuzhiyun * FIFO is relatively large compared to the amount of data
715*4882a593Smuzhiyun * fetched.
716*4882a593Smuzhiyun *
717*4882a593Smuzhiyun * The FIFO level vs. time graph might look something like:
718*4882a593Smuzhiyun *
719*4882a593Smuzhiyun * |\___ |\___
720*4882a593Smuzhiyun * | \___ | \___
721*4882a593Smuzhiyun * | \ | \
722*4882a593Smuzhiyun * __ --__--__--__--__--__--__ (- plane active, _ blanking)
723*4882a593Smuzhiyun * -> time
724*4882a593Smuzhiyun *
725*4882a593Smuzhiyun * Returns:
726*4882a593Smuzhiyun * The watermark in bytes
727*4882a593Smuzhiyun */
intel_wm_method2(unsigned int pixel_rate,unsigned int htotal,unsigned int width,unsigned int cpp,unsigned int latency)728*4882a593Smuzhiyun static unsigned int intel_wm_method2(unsigned int pixel_rate,
729*4882a593Smuzhiyun unsigned int htotal,
730*4882a593Smuzhiyun unsigned int width,
731*4882a593Smuzhiyun unsigned int cpp,
732*4882a593Smuzhiyun unsigned int latency)
733*4882a593Smuzhiyun {
734*4882a593Smuzhiyun unsigned int ret;
735*4882a593Smuzhiyun
736*4882a593Smuzhiyun /*
737*4882a593Smuzhiyun * FIXME remove once all users are computing
738*4882a593Smuzhiyun * watermarks in the correct place.
739*4882a593Smuzhiyun */
740*4882a593Smuzhiyun if (WARN_ON_ONCE(htotal == 0))
741*4882a593Smuzhiyun htotal = 1;
742*4882a593Smuzhiyun
743*4882a593Smuzhiyun ret = (latency * pixel_rate) / (htotal * 10000);
744*4882a593Smuzhiyun ret = (ret + 1) * width * cpp;
745*4882a593Smuzhiyun
746*4882a593Smuzhiyun return ret;
747*4882a593Smuzhiyun }
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun /**
750*4882a593Smuzhiyun * intel_calculate_wm - calculate watermark level
751*4882a593Smuzhiyun * @pixel_rate: pixel clock
752*4882a593Smuzhiyun * @wm: chip FIFO params
753*4882a593Smuzhiyun * @fifo_size: size of the FIFO buffer
754*4882a593Smuzhiyun * @cpp: bytes per pixel
755*4882a593Smuzhiyun * @latency_ns: memory latency for the platform
756*4882a593Smuzhiyun *
757*4882a593Smuzhiyun * Calculate the watermark level (the level at which the display plane will
758*4882a593Smuzhiyun * start fetching from memory again). Each chip has a different display
759*4882a593Smuzhiyun * FIFO size and allocation, so the caller needs to figure that out and pass
760*4882a593Smuzhiyun * in the correct intel_watermark_params structure.
761*4882a593Smuzhiyun *
762*4882a593Smuzhiyun * As the pixel clock runs, the FIFO will be drained at a rate that depends
763*4882a593Smuzhiyun * on the pixel size. When it reaches the watermark level, it'll start
764*4882a593Smuzhiyun * fetching FIFO line sized based chunks from memory until the FIFO fills
765*4882a593Smuzhiyun * past the watermark point. If the FIFO drains completely, a FIFO underrun
766*4882a593Smuzhiyun * will occur, and a display engine hang could result.
767*4882a593Smuzhiyun */
intel_calculate_wm(int pixel_rate,const struct intel_watermark_params * wm,int fifo_size,int cpp,unsigned int latency_ns)768*4882a593Smuzhiyun static unsigned int intel_calculate_wm(int pixel_rate,
769*4882a593Smuzhiyun const struct intel_watermark_params *wm,
770*4882a593Smuzhiyun int fifo_size, int cpp,
771*4882a593Smuzhiyun unsigned int latency_ns)
772*4882a593Smuzhiyun {
773*4882a593Smuzhiyun int entries, wm_size;
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun /*
776*4882a593Smuzhiyun * Note: we need to make sure we don't overflow for various clock &
777*4882a593Smuzhiyun * latency values.
778*4882a593Smuzhiyun * clocks go from a few thousand to several hundred thousand.
779*4882a593Smuzhiyun * latency is usually a few thousand
780*4882a593Smuzhiyun */
781*4882a593Smuzhiyun entries = intel_wm_method1(pixel_rate, cpp,
782*4882a593Smuzhiyun latency_ns / 100);
783*4882a593Smuzhiyun entries = DIV_ROUND_UP(entries, wm->cacheline_size) +
784*4882a593Smuzhiyun wm->guard_size;
785*4882a593Smuzhiyun DRM_DEBUG_KMS("FIFO entries required for mode: %d\n", entries);
786*4882a593Smuzhiyun
787*4882a593Smuzhiyun wm_size = fifo_size - entries;
788*4882a593Smuzhiyun DRM_DEBUG_KMS("FIFO watermark level: %d\n", wm_size);
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun /* Don't promote wm_size to unsigned... */
791*4882a593Smuzhiyun if (wm_size > wm->max_wm)
792*4882a593Smuzhiyun wm_size = wm->max_wm;
793*4882a593Smuzhiyun if (wm_size <= 0)
794*4882a593Smuzhiyun wm_size = wm->default_wm;
795*4882a593Smuzhiyun
796*4882a593Smuzhiyun /*
797*4882a593Smuzhiyun * Bspec seems to indicate that the value shouldn't be lower than
798*4882a593Smuzhiyun * 'burst size + 1'. Certainly 830 is quite unhappy with low values.
799*4882a593Smuzhiyun * Lets go for 8 which is the burst size since certain platforms
800*4882a593Smuzhiyun * already use a hardcoded 8 (which is what the spec says should be
801*4882a593Smuzhiyun * done).
802*4882a593Smuzhiyun */
803*4882a593Smuzhiyun if (wm_size <= 8)
804*4882a593Smuzhiyun wm_size = 8;
805*4882a593Smuzhiyun
806*4882a593Smuzhiyun return wm_size;
807*4882a593Smuzhiyun }
808*4882a593Smuzhiyun
is_disabling(int old,int new,int threshold)809*4882a593Smuzhiyun static bool is_disabling(int old, int new, int threshold)
810*4882a593Smuzhiyun {
811*4882a593Smuzhiyun return old >= threshold && new < threshold;
812*4882a593Smuzhiyun }
813*4882a593Smuzhiyun
is_enabling(int old,int new,int threshold)814*4882a593Smuzhiyun static bool is_enabling(int old, int new, int threshold)
815*4882a593Smuzhiyun {
816*4882a593Smuzhiyun return old < threshold && new >= threshold;
817*4882a593Smuzhiyun }
818*4882a593Smuzhiyun
intel_wm_num_levels(struct drm_i915_private * dev_priv)819*4882a593Smuzhiyun static int intel_wm_num_levels(struct drm_i915_private *dev_priv)
820*4882a593Smuzhiyun {
821*4882a593Smuzhiyun return dev_priv->wm.max_level + 1;
822*4882a593Smuzhiyun }
823*4882a593Smuzhiyun
intel_wm_plane_visible(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)824*4882a593Smuzhiyun static bool intel_wm_plane_visible(const struct intel_crtc_state *crtc_state,
825*4882a593Smuzhiyun const struct intel_plane_state *plane_state)
826*4882a593Smuzhiyun {
827*4882a593Smuzhiyun struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
828*4882a593Smuzhiyun
829*4882a593Smuzhiyun /* FIXME check the 'enable' instead */
830*4882a593Smuzhiyun if (!crtc_state->hw.active)
831*4882a593Smuzhiyun return false;
832*4882a593Smuzhiyun
833*4882a593Smuzhiyun /*
834*4882a593Smuzhiyun * Treat cursor with fb as always visible since cursor updates
835*4882a593Smuzhiyun * can happen faster than the vrefresh rate, and the current
836*4882a593Smuzhiyun * watermark code doesn't handle that correctly. Cursor updates
837*4882a593Smuzhiyun * which set/clear the fb or change the cursor size are going
838*4882a593Smuzhiyun * to get throttled by intel_legacy_cursor_update() to work
839*4882a593Smuzhiyun * around this problem with the watermark code.
840*4882a593Smuzhiyun */
841*4882a593Smuzhiyun if (plane->id == PLANE_CURSOR)
842*4882a593Smuzhiyun return plane_state->hw.fb != NULL;
843*4882a593Smuzhiyun else
844*4882a593Smuzhiyun return plane_state->uapi.visible;
845*4882a593Smuzhiyun }
846*4882a593Smuzhiyun
intel_crtc_active(struct intel_crtc * crtc)847*4882a593Smuzhiyun static bool intel_crtc_active(struct intel_crtc *crtc)
848*4882a593Smuzhiyun {
849*4882a593Smuzhiyun /* Be paranoid as we can arrive here with only partial
850*4882a593Smuzhiyun * state retrieved from the hardware during setup.
851*4882a593Smuzhiyun *
852*4882a593Smuzhiyun * We can ditch the adjusted_mode.crtc_clock check as soon
853*4882a593Smuzhiyun * as Haswell has gained clock readout/fastboot support.
854*4882a593Smuzhiyun *
855*4882a593Smuzhiyun * We can ditch the crtc->primary->state->fb check as soon as we can
856*4882a593Smuzhiyun * properly reconstruct framebuffers.
857*4882a593Smuzhiyun *
858*4882a593Smuzhiyun * FIXME: The intel_crtc->active here should be switched to
859*4882a593Smuzhiyun * crtc->state->active once we have proper CRTC states wired up
860*4882a593Smuzhiyun * for atomic.
861*4882a593Smuzhiyun */
862*4882a593Smuzhiyun return crtc->active && crtc->base.primary->state->fb &&
863*4882a593Smuzhiyun crtc->config->hw.adjusted_mode.crtc_clock;
864*4882a593Smuzhiyun }
865*4882a593Smuzhiyun
single_enabled_crtc(struct drm_i915_private * dev_priv)866*4882a593Smuzhiyun static struct intel_crtc *single_enabled_crtc(struct drm_i915_private *dev_priv)
867*4882a593Smuzhiyun {
868*4882a593Smuzhiyun struct intel_crtc *crtc, *enabled = NULL;
869*4882a593Smuzhiyun
870*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
871*4882a593Smuzhiyun if (intel_crtc_active(crtc)) {
872*4882a593Smuzhiyun if (enabled)
873*4882a593Smuzhiyun return NULL;
874*4882a593Smuzhiyun enabled = crtc;
875*4882a593Smuzhiyun }
876*4882a593Smuzhiyun }
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun return enabled;
879*4882a593Smuzhiyun }
880*4882a593Smuzhiyun
pnv_update_wm(struct intel_crtc * unused_crtc)881*4882a593Smuzhiyun static void pnv_update_wm(struct intel_crtc *unused_crtc)
882*4882a593Smuzhiyun {
883*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev);
884*4882a593Smuzhiyun struct intel_crtc *crtc;
885*4882a593Smuzhiyun const struct cxsr_latency *latency;
886*4882a593Smuzhiyun u32 reg;
887*4882a593Smuzhiyun unsigned int wm;
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun latency = intel_get_cxsr_latency(!IS_MOBILE(dev_priv),
890*4882a593Smuzhiyun dev_priv->is_ddr3,
891*4882a593Smuzhiyun dev_priv->fsb_freq,
892*4882a593Smuzhiyun dev_priv->mem_freq);
893*4882a593Smuzhiyun if (!latency) {
894*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
895*4882a593Smuzhiyun "Unknown FSB/MEM found, disable CxSR\n");
896*4882a593Smuzhiyun intel_set_memory_cxsr(dev_priv, false);
897*4882a593Smuzhiyun return;
898*4882a593Smuzhiyun }
899*4882a593Smuzhiyun
900*4882a593Smuzhiyun crtc = single_enabled_crtc(dev_priv);
901*4882a593Smuzhiyun if (crtc) {
902*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode =
903*4882a593Smuzhiyun &crtc->config->hw.adjusted_mode;
904*4882a593Smuzhiyun const struct drm_framebuffer *fb =
905*4882a593Smuzhiyun crtc->base.primary->state->fb;
906*4882a593Smuzhiyun int cpp = fb->format->cpp[0];
907*4882a593Smuzhiyun int clock = adjusted_mode->crtc_clock;
908*4882a593Smuzhiyun
909*4882a593Smuzhiyun /* Display SR */
910*4882a593Smuzhiyun wm = intel_calculate_wm(clock, &pnv_display_wm,
911*4882a593Smuzhiyun pnv_display_wm.fifo_size,
912*4882a593Smuzhiyun cpp, latency->display_sr);
913*4882a593Smuzhiyun reg = I915_READ(DSPFW1);
914*4882a593Smuzhiyun reg &= ~DSPFW_SR_MASK;
915*4882a593Smuzhiyun reg |= FW_WM(wm, SR);
916*4882a593Smuzhiyun I915_WRITE(DSPFW1, reg);
917*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "DSPFW1 register is %x\n", reg);
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun /* cursor SR */
920*4882a593Smuzhiyun wm = intel_calculate_wm(clock, &pnv_cursor_wm,
921*4882a593Smuzhiyun pnv_display_wm.fifo_size,
922*4882a593Smuzhiyun 4, latency->cursor_sr);
923*4882a593Smuzhiyun reg = I915_READ(DSPFW3);
924*4882a593Smuzhiyun reg &= ~DSPFW_CURSOR_SR_MASK;
925*4882a593Smuzhiyun reg |= FW_WM(wm, CURSOR_SR);
926*4882a593Smuzhiyun I915_WRITE(DSPFW3, reg);
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun /* Display HPLL off SR */
929*4882a593Smuzhiyun wm = intel_calculate_wm(clock, &pnv_display_hplloff_wm,
930*4882a593Smuzhiyun pnv_display_hplloff_wm.fifo_size,
931*4882a593Smuzhiyun cpp, latency->display_hpll_disable);
932*4882a593Smuzhiyun reg = I915_READ(DSPFW3);
933*4882a593Smuzhiyun reg &= ~DSPFW_HPLL_SR_MASK;
934*4882a593Smuzhiyun reg |= FW_WM(wm, HPLL_SR);
935*4882a593Smuzhiyun I915_WRITE(DSPFW3, reg);
936*4882a593Smuzhiyun
937*4882a593Smuzhiyun /* cursor HPLL off SR */
938*4882a593Smuzhiyun wm = intel_calculate_wm(clock, &pnv_cursor_hplloff_wm,
939*4882a593Smuzhiyun pnv_display_hplloff_wm.fifo_size,
940*4882a593Smuzhiyun 4, latency->cursor_hpll_disable);
941*4882a593Smuzhiyun reg = I915_READ(DSPFW3);
942*4882a593Smuzhiyun reg &= ~DSPFW_HPLL_CURSOR_MASK;
943*4882a593Smuzhiyun reg |= FW_WM(wm, HPLL_CURSOR);
944*4882a593Smuzhiyun I915_WRITE(DSPFW3, reg);
945*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "DSPFW3 register is %x\n", reg);
946*4882a593Smuzhiyun
947*4882a593Smuzhiyun intel_set_memory_cxsr(dev_priv, true);
948*4882a593Smuzhiyun } else {
949*4882a593Smuzhiyun intel_set_memory_cxsr(dev_priv, false);
950*4882a593Smuzhiyun }
951*4882a593Smuzhiyun }
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun /*
954*4882a593Smuzhiyun * Documentation says:
955*4882a593Smuzhiyun * "If the line size is small, the TLB fetches can get in the way of the
956*4882a593Smuzhiyun * data fetches, causing some lag in the pixel data return which is not
957*4882a593Smuzhiyun * accounted for in the above formulas. The following adjustment only
958*4882a593Smuzhiyun * needs to be applied if eight whole lines fit in the buffer at once.
959*4882a593Smuzhiyun * The WM is adjusted upwards by the difference between the FIFO size
960*4882a593Smuzhiyun * and the size of 8 whole lines. This adjustment is always performed
961*4882a593Smuzhiyun * in the actual pixel depth regardless of whether FBC is enabled or not."
962*4882a593Smuzhiyun */
g4x_tlb_miss_wa(int fifo_size,int width,int cpp)963*4882a593Smuzhiyun static unsigned int g4x_tlb_miss_wa(int fifo_size, int width, int cpp)
964*4882a593Smuzhiyun {
965*4882a593Smuzhiyun int tlb_miss = fifo_size * 64 - width * cpp * 8;
966*4882a593Smuzhiyun
967*4882a593Smuzhiyun return max(0, tlb_miss);
968*4882a593Smuzhiyun }
969*4882a593Smuzhiyun
g4x_write_wm_values(struct drm_i915_private * dev_priv,const struct g4x_wm_values * wm)970*4882a593Smuzhiyun static void g4x_write_wm_values(struct drm_i915_private *dev_priv,
971*4882a593Smuzhiyun const struct g4x_wm_values *wm)
972*4882a593Smuzhiyun {
973*4882a593Smuzhiyun enum pipe pipe;
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun for_each_pipe(dev_priv, pipe)
976*4882a593Smuzhiyun trace_g4x_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm);
977*4882a593Smuzhiyun
978*4882a593Smuzhiyun I915_WRITE(DSPFW1,
979*4882a593Smuzhiyun FW_WM(wm->sr.plane, SR) |
980*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) |
981*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) |
982*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA));
983*4882a593Smuzhiyun I915_WRITE(DSPFW2,
984*4882a593Smuzhiyun (wm->fbc_en ? DSPFW_FBC_SR_EN : 0) |
985*4882a593Smuzhiyun FW_WM(wm->sr.fbc, FBC_SR) |
986*4882a593Smuzhiyun FW_WM(wm->hpll.fbc, FBC_HPLL_SR) |
987*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEB) |
988*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) |
989*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA));
990*4882a593Smuzhiyun I915_WRITE(DSPFW3,
991*4882a593Smuzhiyun (wm->hpll_en ? DSPFW_HPLL_SR_EN : 0) |
992*4882a593Smuzhiyun FW_WM(wm->sr.cursor, CURSOR_SR) |
993*4882a593Smuzhiyun FW_WM(wm->hpll.cursor, HPLL_CURSOR) |
994*4882a593Smuzhiyun FW_WM(wm->hpll.plane, HPLL_SR));
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun POSTING_READ(DSPFW1);
997*4882a593Smuzhiyun }
998*4882a593Smuzhiyun
999*4882a593Smuzhiyun #define FW_WM_VLV(value, plane) \
1000*4882a593Smuzhiyun (((value) << DSPFW_ ## plane ## _SHIFT) & DSPFW_ ## plane ## _MASK_VLV)
1001*4882a593Smuzhiyun
vlv_write_wm_values(struct drm_i915_private * dev_priv,const struct vlv_wm_values * wm)1002*4882a593Smuzhiyun static void vlv_write_wm_values(struct drm_i915_private *dev_priv,
1003*4882a593Smuzhiyun const struct vlv_wm_values *wm)
1004*4882a593Smuzhiyun {
1005*4882a593Smuzhiyun enum pipe pipe;
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun for_each_pipe(dev_priv, pipe) {
1008*4882a593Smuzhiyun trace_vlv_wm(intel_get_crtc_for_pipe(dev_priv, pipe), wm);
1009*4882a593Smuzhiyun
1010*4882a593Smuzhiyun I915_WRITE(VLV_DDL(pipe),
1011*4882a593Smuzhiyun (wm->ddl[pipe].plane[PLANE_CURSOR] << DDL_CURSOR_SHIFT) |
1012*4882a593Smuzhiyun (wm->ddl[pipe].plane[PLANE_SPRITE1] << DDL_SPRITE_SHIFT(1)) |
1013*4882a593Smuzhiyun (wm->ddl[pipe].plane[PLANE_SPRITE0] << DDL_SPRITE_SHIFT(0)) |
1014*4882a593Smuzhiyun (wm->ddl[pipe].plane[PLANE_PRIMARY] << DDL_PLANE_SHIFT));
1015*4882a593Smuzhiyun }
1016*4882a593Smuzhiyun
1017*4882a593Smuzhiyun /*
1018*4882a593Smuzhiyun * Zero the (unused) WM1 watermarks, and also clear all the
1019*4882a593Smuzhiyun * high order bits so that there are no out of bounds values
1020*4882a593Smuzhiyun * present in the registers during the reprogramming.
1021*4882a593Smuzhiyun */
1022*4882a593Smuzhiyun I915_WRITE(DSPHOWM, 0);
1023*4882a593Smuzhiyun I915_WRITE(DSPHOWM1, 0);
1024*4882a593Smuzhiyun I915_WRITE(DSPFW4, 0);
1025*4882a593Smuzhiyun I915_WRITE(DSPFW5, 0);
1026*4882a593Smuzhiyun I915_WRITE(DSPFW6, 0);
1027*4882a593Smuzhiyun
1028*4882a593Smuzhiyun I915_WRITE(DSPFW1,
1029*4882a593Smuzhiyun FW_WM(wm->sr.plane, SR) |
1030*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_CURSOR], CURSORB) |
1031*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_PRIMARY], PLANEB) |
1032*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_PRIMARY], PLANEA));
1033*4882a593Smuzhiyun I915_WRITE(DSPFW2,
1034*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE1], SPRITEB) |
1035*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_CURSOR], CURSORA) |
1036*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_A].plane[PLANE_SPRITE0], SPRITEA));
1037*4882a593Smuzhiyun I915_WRITE(DSPFW3,
1038*4882a593Smuzhiyun FW_WM(wm->sr.cursor, CURSOR_SR));
1039*4882a593Smuzhiyun
1040*4882a593Smuzhiyun if (IS_CHERRYVIEW(dev_priv)) {
1041*4882a593Smuzhiyun I915_WRITE(DSPFW7_CHV,
1042*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) |
1043*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC));
1044*4882a593Smuzhiyun I915_WRITE(DSPFW8_CHV,
1045*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE1], SPRITEF) |
1046*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_SPRITE0], SPRITEE));
1047*4882a593Smuzhiyun I915_WRITE(DSPFW9_CHV,
1048*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_C].plane[PLANE_PRIMARY], PLANEC) |
1049*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_C].plane[PLANE_CURSOR], CURSORC));
1050*4882a593Smuzhiyun I915_WRITE(DSPHOWM,
1051*4882a593Smuzhiyun FW_WM(wm->sr.plane >> 9, SR_HI) |
1052*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE1] >> 8, SPRITEF_HI) |
1053*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_C].plane[PLANE_SPRITE0] >> 8, SPRITEE_HI) |
1054*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_C].plane[PLANE_PRIMARY] >> 8, PLANEC_HI) |
1055*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) |
1056*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) |
1057*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) |
1058*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) |
1059*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) |
1060*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY] >> 8, PLANEA_HI));
1061*4882a593Smuzhiyun } else {
1062*4882a593Smuzhiyun I915_WRITE(DSPFW7,
1063*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE1], SPRITED) |
1064*4882a593Smuzhiyun FW_WM_VLV(wm->pipe[PIPE_B].plane[PLANE_SPRITE0], SPRITEC));
1065*4882a593Smuzhiyun I915_WRITE(DSPHOWM,
1066*4882a593Smuzhiyun FW_WM(wm->sr.plane >> 9, SR_HI) |
1067*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE1] >> 8, SPRITED_HI) |
1068*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_SPRITE0] >> 8, SPRITEC_HI) |
1069*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_B].plane[PLANE_PRIMARY] >> 8, PLANEB_HI) |
1070*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE1] >> 8, SPRITEB_HI) |
1071*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_SPRITE0] >> 8, SPRITEA_HI) |
1072*4882a593Smuzhiyun FW_WM(wm->pipe[PIPE_A].plane[PLANE_PRIMARY] >> 8, PLANEA_HI));
1073*4882a593Smuzhiyun }
1074*4882a593Smuzhiyun
1075*4882a593Smuzhiyun POSTING_READ(DSPFW1);
1076*4882a593Smuzhiyun }
1077*4882a593Smuzhiyun
1078*4882a593Smuzhiyun #undef FW_WM_VLV
1079*4882a593Smuzhiyun
g4x_setup_wm_latency(struct drm_i915_private * dev_priv)1080*4882a593Smuzhiyun static void g4x_setup_wm_latency(struct drm_i915_private *dev_priv)
1081*4882a593Smuzhiyun {
1082*4882a593Smuzhiyun /* all latencies in usec */
1083*4882a593Smuzhiyun dev_priv->wm.pri_latency[G4X_WM_LEVEL_NORMAL] = 5;
1084*4882a593Smuzhiyun dev_priv->wm.pri_latency[G4X_WM_LEVEL_SR] = 12;
1085*4882a593Smuzhiyun dev_priv->wm.pri_latency[G4X_WM_LEVEL_HPLL] = 35;
1086*4882a593Smuzhiyun
1087*4882a593Smuzhiyun dev_priv->wm.max_level = G4X_WM_LEVEL_HPLL;
1088*4882a593Smuzhiyun }
1089*4882a593Smuzhiyun
g4x_plane_fifo_size(enum plane_id plane_id,int level)1090*4882a593Smuzhiyun static int g4x_plane_fifo_size(enum plane_id plane_id, int level)
1091*4882a593Smuzhiyun {
1092*4882a593Smuzhiyun /*
1093*4882a593Smuzhiyun * DSPCNTR[13] supposedly controls whether the
1094*4882a593Smuzhiyun * primary plane can use the FIFO space otherwise
1095*4882a593Smuzhiyun * reserved for the sprite plane. It's not 100% clear
1096*4882a593Smuzhiyun * what the actual FIFO size is, but it looks like we
1097*4882a593Smuzhiyun * can happily set both primary and sprite watermarks
1098*4882a593Smuzhiyun * up to 127 cachelines. So that would seem to mean
1099*4882a593Smuzhiyun * that either DSPCNTR[13] doesn't do anything, or that
1100*4882a593Smuzhiyun * the total FIFO is >= 256 cachelines in size. Either
1101*4882a593Smuzhiyun * way, we don't seem to have to worry about this
1102*4882a593Smuzhiyun * repartitioning as the maximum watermark value the
1103*4882a593Smuzhiyun * register can hold for each plane is lower than the
1104*4882a593Smuzhiyun * minimum FIFO size.
1105*4882a593Smuzhiyun */
1106*4882a593Smuzhiyun switch (plane_id) {
1107*4882a593Smuzhiyun case PLANE_CURSOR:
1108*4882a593Smuzhiyun return 63;
1109*4882a593Smuzhiyun case PLANE_PRIMARY:
1110*4882a593Smuzhiyun return level == G4X_WM_LEVEL_NORMAL ? 127 : 511;
1111*4882a593Smuzhiyun case PLANE_SPRITE0:
1112*4882a593Smuzhiyun return level == G4X_WM_LEVEL_NORMAL ? 127 : 0;
1113*4882a593Smuzhiyun default:
1114*4882a593Smuzhiyun MISSING_CASE(plane_id);
1115*4882a593Smuzhiyun return 0;
1116*4882a593Smuzhiyun }
1117*4882a593Smuzhiyun }
1118*4882a593Smuzhiyun
g4x_fbc_fifo_size(int level)1119*4882a593Smuzhiyun static int g4x_fbc_fifo_size(int level)
1120*4882a593Smuzhiyun {
1121*4882a593Smuzhiyun switch (level) {
1122*4882a593Smuzhiyun case G4X_WM_LEVEL_SR:
1123*4882a593Smuzhiyun return 7;
1124*4882a593Smuzhiyun case G4X_WM_LEVEL_HPLL:
1125*4882a593Smuzhiyun return 15;
1126*4882a593Smuzhiyun default:
1127*4882a593Smuzhiyun MISSING_CASE(level);
1128*4882a593Smuzhiyun return 0;
1129*4882a593Smuzhiyun }
1130*4882a593Smuzhiyun }
1131*4882a593Smuzhiyun
g4x_compute_wm(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,int level)1132*4882a593Smuzhiyun static u16 g4x_compute_wm(const struct intel_crtc_state *crtc_state,
1133*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
1134*4882a593Smuzhiyun int level)
1135*4882a593Smuzhiyun {
1136*4882a593Smuzhiyun struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1137*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1138*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode =
1139*4882a593Smuzhiyun &crtc_state->hw.adjusted_mode;
1140*4882a593Smuzhiyun unsigned int latency = dev_priv->wm.pri_latency[level] * 10;
1141*4882a593Smuzhiyun unsigned int clock, htotal, cpp, width, wm;
1142*4882a593Smuzhiyun
1143*4882a593Smuzhiyun if (latency == 0)
1144*4882a593Smuzhiyun return USHRT_MAX;
1145*4882a593Smuzhiyun
1146*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state))
1147*4882a593Smuzhiyun return 0;
1148*4882a593Smuzhiyun
1149*4882a593Smuzhiyun cpp = plane_state->hw.fb->format->cpp[0];
1150*4882a593Smuzhiyun
1151*4882a593Smuzhiyun /*
1152*4882a593Smuzhiyun * Not 100% sure which way ELK should go here as the
1153*4882a593Smuzhiyun * spec only says CL/CTG should assume 32bpp and BW
1154*4882a593Smuzhiyun * doesn't need to. But as these things followed the
1155*4882a593Smuzhiyun * mobile vs. desktop lines on gen3 as well, let's
1156*4882a593Smuzhiyun * assume ELK doesn't need this.
1157*4882a593Smuzhiyun *
1158*4882a593Smuzhiyun * The spec also fails to list such a restriction for
1159*4882a593Smuzhiyun * the HPLL watermark, which seems a little strange.
1160*4882a593Smuzhiyun * Let's use 32bpp for the HPLL watermark as well.
1161*4882a593Smuzhiyun */
1162*4882a593Smuzhiyun if (IS_GM45(dev_priv) && plane->id == PLANE_PRIMARY &&
1163*4882a593Smuzhiyun level != G4X_WM_LEVEL_NORMAL)
1164*4882a593Smuzhiyun cpp = max(cpp, 4u);
1165*4882a593Smuzhiyun
1166*4882a593Smuzhiyun clock = adjusted_mode->crtc_clock;
1167*4882a593Smuzhiyun htotal = adjusted_mode->crtc_htotal;
1168*4882a593Smuzhiyun
1169*4882a593Smuzhiyun width = drm_rect_width(&plane_state->uapi.dst);
1170*4882a593Smuzhiyun
1171*4882a593Smuzhiyun if (plane->id == PLANE_CURSOR) {
1172*4882a593Smuzhiyun wm = intel_wm_method2(clock, htotal, width, cpp, latency);
1173*4882a593Smuzhiyun } else if (plane->id == PLANE_PRIMARY &&
1174*4882a593Smuzhiyun level == G4X_WM_LEVEL_NORMAL) {
1175*4882a593Smuzhiyun wm = intel_wm_method1(clock, cpp, latency);
1176*4882a593Smuzhiyun } else {
1177*4882a593Smuzhiyun unsigned int small, large;
1178*4882a593Smuzhiyun
1179*4882a593Smuzhiyun small = intel_wm_method1(clock, cpp, latency);
1180*4882a593Smuzhiyun large = intel_wm_method2(clock, htotal, width, cpp, latency);
1181*4882a593Smuzhiyun
1182*4882a593Smuzhiyun wm = min(small, large);
1183*4882a593Smuzhiyun }
1184*4882a593Smuzhiyun
1185*4882a593Smuzhiyun wm += g4x_tlb_miss_wa(g4x_plane_fifo_size(plane->id, level),
1186*4882a593Smuzhiyun width, cpp);
1187*4882a593Smuzhiyun
1188*4882a593Smuzhiyun wm = DIV_ROUND_UP(wm, 64) + 2;
1189*4882a593Smuzhiyun
1190*4882a593Smuzhiyun return min_t(unsigned int, wm, USHRT_MAX);
1191*4882a593Smuzhiyun }
1192*4882a593Smuzhiyun
g4x_raw_plane_wm_set(struct intel_crtc_state * crtc_state,int level,enum plane_id plane_id,u16 value)1193*4882a593Smuzhiyun static bool g4x_raw_plane_wm_set(struct intel_crtc_state *crtc_state,
1194*4882a593Smuzhiyun int level, enum plane_id plane_id, u16 value)
1195*4882a593Smuzhiyun {
1196*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1197*4882a593Smuzhiyun bool dirty = false;
1198*4882a593Smuzhiyun
1199*4882a593Smuzhiyun for (; level < intel_wm_num_levels(dev_priv); level++) {
1200*4882a593Smuzhiyun struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1201*4882a593Smuzhiyun
1202*4882a593Smuzhiyun dirty |= raw->plane[plane_id] != value;
1203*4882a593Smuzhiyun raw->plane[plane_id] = value;
1204*4882a593Smuzhiyun }
1205*4882a593Smuzhiyun
1206*4882a593Smuzhiyun return dirty;
1207*4882a593Smuzhiyun }
1208*4882a593Smuzhiyun
g4x_raw_fbc_wm_set(struct intel_crtc_state * crtc_state,int level,u16 value)1209*4882a593Smuzhiyun static bool g4x_raw_fbc_wm_set(struct intel_crtc_state *crtc_state,
1210*4882a593Smuzhiyun int level, u16 value)
1211*4882a593Smuzhiyun {
1212*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1213*4882a593Smuzhiyun bool dirty = false;
1214*4882a593Smuzhiyun
1215*4882a593Smuzhiyun /* NORMAL level doesn't have an FBC watermark */
1216*4882a593Smuzhiyun level = max(level, G4X_WM_LEVEL_SR);
1217*4882a593Smuzhiyun
1218*4882a593Smuzhiyun for (; level < intel_wm_num_levels(dev_priv); level++) {
1219*4882a593Smuzhiyun struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1220*4882a593Smuzhiyun
1221*4882a593Smuzhiyun dirty |= raw->fbc != value;
1222*4882a593Smuzhiyun raw->fbc = value;
1223*4882a593Smuzhiyun }
1224*4882a593Smuzhiyun
1225*4882a593Smuzhiyun return dirty;
1226*4882a593Smuzhiyun }
1227*4882a593Smuzhiyun
1228*4882a593Smuzhiyun static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state,
1229*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
1230*4882a593Smuzhiyun u32 pri_val);
1231*4882a593Smuzhiyun
g4x_raw_plane_wm_compute(struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)1232*4882a593Smuzhiyun static bool g4x_raw_plane_wm_compute(struct intel_crtc_state *crtc_state,
1233*4882a593Smuzhiyun const struct intel_plane_state *plane_state)
1234*4882a593Smuzhiyun {
1235*4882a593Smuzhiyun struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1236*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1237*4882a593Smuzhiyun int num_levels = intel_wm_num_levels(to_i915(plane->base.dev));
1238*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
1239*4882a593Smuzhiyun bool dirty = false;
1240*4882a593Smuzhiyun int level;
1241*4882a593Smuzhiyun
1242*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state)) {
1243*4882a593Smuzhiyun dirty |= g4x_raw_plane_wm_set(crtc_state, 0, plane_id, 0);
1244*4882a593Smuzhiyun if (plane_id == PLANE_PRIMARY)
1245*4882a593Smuzhiyun dirty |= g4x_raw_fbc_wm_set(crtc_state, 0, 0);
1246*4882a593Smuzhiyun goto out;
1247*4882a593Smuzhiyun }
1248*4882a593Smuzhiyun
1249*4882a593Smuzhiyun for (level = 0; level < num_levels; level++) {
1250*4882a593Smuzhiyun struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1251*4882a593Smuzhiyun int wm, max_wm;
1252*4882a593Smuzhiyun
1253*4882a593Smuzhiyun wm = g4x_compute_wm(crtc_state, plane_state, level);
1254*4882a593Smuzhiyun max_wm = g4x_plane_fifo_size(plane_id, level);
1255*4882a593Smuzhiyun
1256*4882a593Smuzhiyun if (wm > max_wm)
1257*4882a593Smuzhiyun break;
1258*4882a593Smuzhiyun
1259*4882a593Smuzhiyun dirty |= raw->plane[plane_id] != wm;
1260*4882a593Smuzhiyun raw->plane[plane_id] = wm;
1261*4882a593Smuzhiyun
1262*4882a593Smuzhiyun if (plane_id != PLANE_PRIMARY ||
1263*4882a593Smuzhiyun level == G4X_WM_LEVEL_NORMAL)
1264*4882a593Smuzhiyun continue;
1265*4882a593Smuzhiyun
1266*4882a593Smuzhiyun wm = ilk_compute_fbc_wm(crtc_state, plane_state,
1267*4882a593Smuzhiyun raw->plane[plane_id]);
1268*4882a593Smuzhiyun max_wm = g4x_fbc_fifo_size(level);
1269*4882a593Smuzhiyun
1270*4882a593Smuzhiyun /*
1271*4882a593Smuzhiyun * FBC wm is not mandatory as we
1272*4882a593Smuzhiyun * can always just disable its use.
1273*4882a593Smuzhiyun */
1274*4882a593Smuzhiyun if (wm > max_wm)
1275*4882a593Smuzhiyun wm = USHRT_MAX;
1276*4882a593Smuzhiyun
1277*4882a593Smuzhiyun dirty |= raw->fbc != wm;
1278*4882a593Smuzhiyun raw->fbc = wm;
1279*4882a593Smuzhiyun }
1280*4882a593Smuzhiyun
1281*4882a593Smuzhiyun /* mark watermarks as invalid */
1282*4882a593Smuzhiyun dirty |= g4x_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX);
1283*4882a593Smuzhiyun
1284*4882a593Smuzhiyun if (plane_id == PLANE_PRIMARY)
1285*4882a593Smuzhiyun dirty |= g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX);
1286*4882a593Smuzhiyun
1287*4882a593Smuzhiyun out:
1288*4882a593Smuzhiyun if (dirty) {
1289*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
1290*4882a593Smuzhiyun "%s watermarks: normal=%d, SR=%d, HPLL=%d\n",
1291*4882a593Smuzhiyun plane->base.name,
1292*4882a593Smuzhiyun crtc_state->wm.g4x.raw[G4X_WM_LEVEL_NORMAL].plane[plane_id],
1293*4882a593Smuzhiyun crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].plane[plane_id],
1294*4882a593Smuzhiyun crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].plane[plane_id]);
1295*4882a593Smuzhiyun
1296*4882a593Smuzhiyun if (plane_id == PLANE_PRIMARY)
1297*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
1298*4882a593Smuzhiyun "FBC watermarks: SR=%d, HPLL=%d\n",
1299*4882a593Smuzhiyun crtc_state->wm.g4x.raw[G4X_WM_LEVEL_SR].fbc,
1300*4882a593Smuzhiyun crtc_state->wm.g4x.raw[G4X_WM_LEVEL_HPLL].fbc);
1301*4882a593Smuzhiyun }
1302*4882a593Smuzhiyun
1303*4882a593Smuzhiyun return dirty;
1304*4882a593Smuzhiyun }
1305*4882a593Smuzhiyun
g4x_raw_plane_wm_is_valid(const struct intel_crtc_state * crtc_state,enum plane_id plane_id,int level)1306*4882a593Smuzhiyun static bool g4x_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state,
1307*4882a593Smuzhiyun enum plane_id plane_id, int level)
1308*4882a593Smuzhiyun {
1309*4882a593Smuzhiyun const struct g4x_pipe_wm *raw = &crtc_state->wm.g4x.raw[level];
1310*4882a593Smuzhiyun
1311*4882a593Smuzhiyun return raw->plane[plane_id] <= g4x_plane_fifo_size(plane_id, level);
1312*4882a593Smuzhiyun }
1313*4882a593Smuzhiyun
g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state * crtc_state,int level)1314*4882a593Smuzhiyun static bool g4x_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state,
1315*4882a593Smuzhiyun int level)
1316*4882a593Smuzhiyun {
1317*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1318*4882a593Smuzhiyun
1319*4882a593Smuzhiyun if (level > dev_priv->wm.max_level)
1320*4882a593Smuzhiyun return false;
1321*4882a593Smuzhiyun
1322*4882a593Smuzhiyun return g4x_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) &&
1323*4882a593Smuzhiyun g4x_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) &&
1324*4882a593Smuzhiyun g4x_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level);
1325*4882a593Smuzhiyun }
1326*4882a593Smuzhiyun
1327*4882a593Smuzhiyun /* mark all levels starting from 'level' as invalid */
g4x_invalidate_wms(struct intel_crtc * crtc,struct g4x_wm_state * wm_state,int level)1328*4882a593Smuzhiyun static void g4x_invalidate_wms(struct intel_crtc *crtc,
1329*4882a593Smuzhiyun struct g4x_wm_state *wm_state, int level)
1330*4882a593Smuzhiyun {
1331*4882a593Smuzhiyun if (level <= G4X_WM_LEVEL_NORMAL) {
1332*4882a593Smuzhiyun enum plane_id plane_id;
1333*4882a593Smuzhiyun
1334*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id)
1335*4882a593Smuzhiyun wm_state->wm.plane[plane_id] = USHRT_MAX;
1336*4882a593Smuzhiyun }
1337*4882a593Smuzhiyun
1338*4882a593Smuzhiyun if (level <= G4X_WM_LEVEL_SR) {
1339*4882a593Smuzhiyun wm_state->cxsr = false;
1340*4882a593Smuzhiyun wm_state->sr.cursor = USHRT_MAX;
1341*4882a593Smuzhiyun wm_state->sr.plane = USHRT_MAX;
1342*4882a593Smuzhiyun wm_state->sr.fbc = USHRT_MAX;
1343*4882a593Smuzhiyun }
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun if (level <= G4X_WM_LEVEL_HPLL) {
1346*4882a593Smuzhiyun wm_state->hpll_en = false;
1347*4882a593Smuzhiyun wm_state->hpll.cursor = USHRT_MAX;
1348*4882a593Smuzhiyun wm_state->hpll.plane = USHRT_MAX;
1349*4882a593Smuzhiyun wm_state->hpll.fbc = USHRT_MAX;
1350*4882a593Smuzhiyun }
1351*4882a593Smuzhiyun }
1352*4882a593Smuzhiyun
g4x_compute_fbc_en(const struct g4x_wm_state * wm_state,int level)1353*4882a593Smuzhiyun static bool g4x_compute_fbc_en(const struct g4x_wm_state *wm_state,
1354*4882a593Smuzhiyun int level)
1355*4882a593Smuzhiyun {
1356*4882a593Smuzhiyun if (level < G4X_WM_LEVEL_SR)
1357*4882a593Smuzhiyun return false;
1358*4882a593Smuzhiyun
1359*4882a593Smuzhiyun if (level >= G4X_WM_LEVEL_SR &&
1360*4882a593Smuzhiyun wm_state->sr.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_SR))
1361*4882a593Smuzhiyun return false;
1362*4882a593Smuzhiyun
1363*4882a593Smuzhiyun if (level >= G4X_WM_LEVEL_HPLL &&
1364*4882a593Smuzhiyun wm_state->hpll.fbc > g4x_fbc_fifo_size(G4X_WM_LEVEL_HPLL))
1365*4882a593Smuzhiyun return false;
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun return true;
1368*4882a593Smuzhiyun }
1369*4882a593Smuzhiyun
g4x_compute_pipe_wm(struct intel_crtc_state * crtc_state)1370*4882a593Smuzhiyun static int g4x_compute_pipe_wm(struct intel_crtc_state *crtc_state)
1371*4882a593Smuzhiyun {
1372*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1373*4882a593Smuzhiyun struct intel_atomic_state *state =
1374*4882a593Smuzhiyun to_intel_atomic_state(crtc_state->uapi.state);
1375*4882a593Smuzhiyun struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal;
1376*4882a593Smuzhiyun int num_active_planes = hweight8(crtc_state->active_planes &
1377*4882a593Smuzhiyun ~BIT(PLANE_CURSOR));
1378*4882a593Smuzhiyun const struct g4x_pipe_wm *raw;
1379*4882a593Smuzhiyun const struct intel_plane_state *old_plane_state;
1380*4882a593Smuzhiyun const struct intel_plane_state *new_plane_state;
1381*4882a593Smuzhiyun struct intel_plane *plane;
1382*4882a593Smuzhiyun enum plane_id plane_id;
1383*4882a593Smuzhiyun int i, level;
1384*4882a593Smuzhiyun unsigned int dirty = 0;
1385*4882a593Smuzhiyun
1386*4882a593Smuzhiyun for_each_oldnew_intel_plane_in_state(state, plane,
1387*4882a593Smuzhiyun old_plane_state,
1388*4882a593Smuzhiyun new_plane_state, i) {
1389*4882a593Smuzhiyun if (new_plane_state->hw.crtc != &crtc->base &&
1390*4882a593Smuzhiyun old_plane_state->hw.crtc != &crtc->base)
1391*4882a593Smuzhiyun continue;
1392*4882a593Smuzhiyun
1393*4882a593Smuzhiyun if (g4x_raw_plane_wm_compute(crtc_state, new_plane_state))
1394*4882a593Smuzhiyun dirty |= BIT(plane->id);
1395*4882a593Smuzhiyun }
1396*4882a593Smuzhiyun
1397*4882a593Smuzhiyun if (!dirty)
1398*4882a593Smuzhiyun return 0;
1399*4882a593Smuzhiyun
1400*4882a593Smuzhiyun level = G4X_WM_LEVEL_NORMAL;
1401*4882a593Smuzhiyun if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1402*4882a593Smuzhiyun goto out;
1403*4882a593Smuzhiyun
1404*4882a593Smuzhiyun raw = &crtc_state->wm.g4x.raw[level];
1405*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id)
1406*4882a593Smuzhiyun wm_state->wm.plane[plane_id] = raw->plane[plane_id];
1407*4882a593Smuzhiyun
1408*4882a593Smuzhiyun level = G4X_WM_LEVEL_SR;
1409*4882a593Smuzhiyun if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1410*4882a593Smuzhiyun goto out;
1411*4882a593Smuzhiyun
1412*4882a593Smuzhiyun raw = &crtc_state->wm.g4x.raw[level];
1413*4882a593Smuzhiyun wm_state->sr.plane = raw->plane[PLANE_PRIMARY];
1414*4882a593Smuzhiyun wm_state->sr.cursor = raw->plane[PLANE_CURSOR];
1415*4882a593Smuzhiyun wm_state->sr.fbc = raw->fbc;
1416*4882a593Smuzhiyun
1417*4882a593Smuzhiyun wm_state->cxsr = num_active_planes == BIT(PLANE_PRIMARY);
1418*4882a593Smuzhiyun
1419*4882a593Smuzhiyun level = G4X_WM_LEVEL_HPLL;
1420*4882a593Smuzhiyun if (!g4x_raw_crtc_wm_is_valid(crtc_state, level))
1421*4882a593Smuzhiyun goto out;
1422*4882a593Smuzhiyun
1423*4882a593Smuzhiyun raw = &crtc_state->wm.g4x.raw[level];
1424*4882a593Smuzhiyun wm_state->hpll.plane = raw->plane[PLANE_PRIMARY];
1425*4882a593Smuzhiyun wm_state->hpll.cursor = raw->plane[PLANE_CURSOR];
1426*4882a593Smuzhiyun wm_state->hpll.fbc = raw->fbc;
1427*4882a593Smuzhiyun
1428*4882a593Smuzhiyun wm_state->hpll_en = wm_state->cxsr;
1429*4882a593Smuzhiyun
1430*4882a593Smuzhiyun level++;
1431*4882a593Smuzhiyun
1432*4882a593Smuzhiyun out:
1433*4882a593Smuzhiyun if (level == G4X_WM_LEVEL_NORMAL)
1434*4882a593Smuzhiyun return -EINVAL;
1435*4882a593Smuzhiyun
1436*4882a593Smuzhiyun /* invalidate the higher levels */
1437*4882a593Smuzhiyun g4x_invalidate_wms(crtc, wm_state, level);
1438*4882a593Smuzhiyun
1439*4882a593Smuzhiyun /*
1440*4882a593Smuzhiyun * Determine if the FBC watermark(s) can be used. IF
1441*4882a593Smuzhiyun * this isn't the case we prefer to disable the FBC
1442*4882a593Smuzhiyun * watermark(s) rather than disable the SR/HPLL
1443*4882a593Smuzhiyun * level(s) entirely. 'level-1' is the highest valid
1444*4882a593Smuzhiyun * level here.
1445*4882a593Smuzhiyun */
1446*4882a593Smuzhiyun wm_state->fbc_en = g4x_compute_fbc_en(wm_state, level - 1);
1447*4882a593Smuzhiyun
1448*4882a593Smuzhiyun return 0;
1449*4882a593Smuzhiyun }
1450*4882a593Smuzhiyun
g4x_compute_intermediate_wm(struct intel_crtc_state * new_crtc_state)1451*4882a593Smuzhiyun static int g4x_compute_intermediate_wm(struct intel_crtc_state *new_crtc_state)
1452*4882a593Smuzhiyun {
1453*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
1454*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1455*4882a593Smuzhiyun struct g4x_wm_state *intermediate = &new_crtc_state->wm.g4x.intermediate;
1456*4882a593Smuzhiyun const struct g4x_wm_state *optimal = &new_crtc_state->wm.g4x.optimal;
1457*4882a593Smuzhiyun struct intel_atomic_state *intel_state =
1458*4882a593Smuzhiyun to_intel_atomic_state(new_crtc_state->uapi.state);
1459*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state =
1460*4882a593Smuzhiyun intel_atomic_get_old_crtc_state(intel_state, crtc);
1461*4882a593Smuzhiyun const struct g4x_wm_state *active = &old_crtc_state->wm.g4x.optimal;
1462*4882a593Smuzhiyun enum plane_id plane_id;
1463*4882a593Smuzhiyun
1464*4882a593Smuzhiyun if (!new_crtc_state->hw.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) {
1465*4882a593Smuzhiyun *intermediate = *optimal;
1466*4882a593Smuzhiyun
1467*4882a593Smuzhiyun intermediate->cxsr = false;
1468*4882a593Smuzhiyun intermediate->hpll_en = false;
1469*4882a593Smuzhiyun goto out;
1470*4882a593Smuzhiyun }
1471*4882a593Smuzhiyun
1472*4882a593Smuzhiyun intermediate->cxsr = optimal->cxsr && active->cxsr &&
1473*4882a593Smuzhiyun !new_crtc_state->disable_cxsr;
1474*4882a593Smuzhiyun intermediate->hpll_en = optimal->hpll_en && active->hpll_en &&
1475*4882a593Smuzhiyun !new_crtc_state->disable_cxsr;
1476*4882a593Smuzhiyun intermediate->fbc_en = optimal->fbc_en && active->fbc_en;
1477*4882a593Smuzhiyun
1478*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
1479*4882a593Smuzhiyun intermediate->wm.plane[plane_id] =
1480*4882a593Smuzhiyun max(optimal->wm.plane[plane_id],
1481*4882a593Smuzhiyun active->wm.plane[plane_id]);
1482*4882a593Smuzhiyun
1483*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, intermediate->wm.plane[plane_id] >
1484*4882a593Smuzhiyun g4x_plane_fifo_size(plane_id, G4X_WM_LEVEL_NORMAL));
1485*4882a593Smuzhiyun }
1486*4882a593Smuzhiyun
1487*4882a593Smuzhiyun intermediate->sr.plane = max(optimal->sr.plane,
1488*4882a593Smuzhiyun active->sr.plane);
1489*4882a593Smuzhiyun intermediate->sr.cursor = max(optimal->sr.cursor,
1490*4882a593Smuzhiyun active->sr.cursor);
1491*4882a593Smuzhiyun intermediate->sr.fbc = max(optimal->sr.fbc,
1492*4882a593Smuzhiyun active->sr.fbc);
1493*4882a593Smuzhiyun
1494*4882a593Smuzhiyun intermediate->hpll.plane = max(optimal->hpll.plane,
1495*4882a593Smuzhiyun active->hpll.plane);
1496*4882a593Smuzhiyun intermediate->hpll.cursor = max(optimal->hpll.cursor,
1497*4882a593Smuzhiyun active->hpll.cursor);
1498*4882a593Smuzhiyun intermediate->hpll.fbc = max(optimal->hpll.fbc,
1499*4882a593Smuzhiyun active->hpll.fbc);
1500*4882a593Smuzhiyun
1501*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm,
1502*4882a593Smuzhiyun (intermediate->sr.plane >
1503*4882a593Smuzhiyun g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_SR) ||
1504*4882a593Smuzhiyun intermediate->sr.cursor >
1505*4882a593Smuzhiyun g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_SR)) &&
1506*4882a593Smuzhiyun intermediate->cxsr);
1507*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm,
1508*4882a593Smuzhiyun (intermediate->sr.plane >
1509*4882a593Smuzhiyun g4x_plane_fifo_size(PLANE_PRIMARY, G4X_WM_LEVEL_HPLL) ||
1510*4882a593Smuzhiyun intermediate->sr.cursor >
1511*4882a593Smuzhiyun g4x_plane_fifo_size(PLANE_CURSOR, G4X_WM_LEVEL_HPLL)) &&
1512*4882a593Smuzhiyun intermediate->hpll_en);
1513*4882a593Smuzhiyun
1514*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm,
1515*4882a593Smuzhiyun intermediate->sr.fbc > g4x_fbc_fifo_size(1) &&
1516*4882a593Smuzhiyun intermediate->fbc_en && intermediate->cxsr);
1517*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm,
1518*4882a593Smuzhiyun intermediate->hpll.fbc > g4x_fbc_fifo_size(2) &&
1519*4882a593Smuzhiyun intermediate->fbc_en && intermediate->hpll_en);
1520*4882a593Smuzhiyun
1521*4882a593Smuzhiyun out:
1522*4882a593Smuzhiyun /*
1523*4882a593Smuzhiyun * If our intermediate WM are identical to the final WM, then we can
1524*4882a593Smuzhiyun * omit the post-vblank programming; only update if it's different.
1525*4882a593Smuzhiyun */
1526*4882a593Smuzhiyun if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0)
1527*4882a593Smuzhiyun new_crtc_state->wm.need_postvbl_update = true;
1528*4882a593Smuzhiyun
1529*4882a593Smuzhiyun return 0;
1530*4882a593Smuzhiyun }
1531*4882a593Smuzhiyun
g4x_merge_wm(struct drm_i915_private * dev_priv,struct g4x_wm_values * wm)1532*4882a593Smuzhiyun static void g4x_merge_wm(struct drm_i915_private *dev_priv,
1533*4882a593Smuzhiyun struct g4x_wm_values *wm)
1534*4882a593Smuzhiyun {
1535*4882a593Smuzhiyun struct intel_crtc *crtc;
1536*4882a593Smuzhiyun int num_active_pipes = 0;
1537*4882a593Smuzhiyun
1538*4882a593Smuzhiyun wm->cxsr = true;
1539*4882a593Smuzhiyun wm->hpll_en = true;
1540*4882a593Smuzhiyun wm->fbc_en = true;
1541*4882a593Smuzhiyun
1542*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
1543*4882a593Smuzhiyun const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x;
1544*4882a593Smuzhiyun
1545*4882a593Smuzhiyun if (!crtc->active)
1546*4882a593Smuzhiyun continue;
1547*4882a593Smuzhiyun
1548*4882a593Smuzhiyun if (!wm_state->cxsr)
1549*4882a593Smuzhiyun wm->cxsr = false;
1550*4882a593Smuzhiyun if (!wm_state->hpll_en)
1551*4882a593Smuzhiyun wm->hpll_en = false;
1552*4882a593Smuzhiyun if (!wm_state->fbc_en)
1553*4882a593Smuzhiyun wm->fbc_en = false;
1554*4882a593Smuzhiyun
1555*4882a593Smuzhiyun num_active_pipes++;
1556*4882a593Smuzhiyun }
1557*4882a593Smuzhiyun
1558*4882a593Smuzhiyun if (num_active_pipes != 1) {
1559*4882a593Smuzhiyun wm->cxsr = false;
1560*4882a593Smuzhiyun wm->hpll_en = false;
1561*4882a593Smuzhiyun wm->fbc_en = false;
1562*4882a593Smuzhiyun }
1563*4882a593Smuzhiyun
1564*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
1565*4882a593Smuzhiyun const struct g4x_wm_state *wm_state = &crtc->wm.active.g4x;
1566*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
1567*4882a593Smuzhiyun
1568*4882a593Smuzhiyun wm->pipe[pipe] = wm_state->wm;
1569*4882a593Smuzhiyun if (crtc->active && wm->cxsr)
1570*4882a593Smuzhiyun wm->sr = wm_state->sr;
1571*4882a593Smuzhiyun if (crtc->active && wm->hpll_en)
1572*4882a593Smuzhiyun wm->hpll = wm_state->hpll;
1573*4882a593Smuzhiyun }
1574*4882a593Smuzhiyun }
1575*4882a593Smuzhiyun
g4x_program_watermarks(struct drm_i915_private * dev_priv)1576*4882a593Smuzhiyun static void g4x_program_watermarks(struct drm_i915_private *dev_priv)
1577*4882a593Smuzhiyun {
1578*4882a593Smuzhiyun struct g4x_wm_values *old_wm = &dev_priv->wm.g4x;
1579*4882a593Smuzhiyun struct g4x_wm_values new_wm = {};
1580*4882a593Smuzhiyun
1581*4882a593Smuzhiyun g4x_merge_wm(dev_priv, &new_wm);
1582*4882a593Smuzhiyun
1583*4882a593Smuzhiyun if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0)
1584*4882a593Smuzhiyun return;
1585*4882a593Smuzhiyun
1586*4882a593Smuzhiyun if (is_disabling(old_wm->cxsr, new_wm.cxsr, true))
1587*4882a593Smuzhiyun _intel_set_memory_cxsr(dev_priv, false);
1588*4882a593Smuzhiyun
1589*4882a593Smuzhiyun g4x_write_wm_values(dev_priv, &new_wm);
1590*4882a593Smuzhiyun
1591*4882a593Smuzhiyun if (is_enabling(old_wm->cxsr, new_wm.cxsr, true))
1592*4882a593Smuzhiyun _intel_set_memory_cxsr(dev_priv, true);
1593*4882a593Smuzhiyun
1594*4882a593Smuzhiyun *old_wm = new_wm;
1595*4882a593Smuzhiyun }
1596*4882a593Smuzhiyun
g4x_initial_watermarks(struct intel_atomic_state * state,struct intel_crtc * crtc)1597*4882a593Smuzhiyun static void g4x_initial_watermarks(struct intel_atomic_state *state,
1598*4882a593Smuzhiyun struct intel_crtc *crtc)
1599*4882a593Smuzhiyun {
1600*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1601*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state =
1602*4882a593Smuzhiyun intel_atomic_get_new_crtc_state(state, crtc);
1603*4882a593Smuzhiyun
1604*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
1605*4882a593Smuzhiyun crtc->wm.active.g4x = crtc_state->wm.g4x.intermediate;
1606*4882a593Smuzhiyun g4x_program_watermarks(dev_priv);
1607*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
1608*4882a593Smuzhiyun }
1609*4882a593Smuzhiyun
g4x_optimize_watermarks(struct intel_atomic_state * state,struct intel_crtc * crtc)1610*4882a593Smuzhiyun static void g4x_optimize_watermarks(struct intel_atomic_state *state,
1611*4882a593Smuzhiyun struct intel_crtc *crtc)
1612*4882a593Smuzhiyun {
1613*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1614*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state =
1615*4882a593Smuzhiyun intel_atomic_get_new_crtc_state(state, crtc);
1616*4882a593Smuzhiyun
1617*4882a593Smuzhiyun if (!crtc_state->wm.need_postvbl_update)
1618*4882a593Smuzhiyun return;
1619*4882a593Smuzhiyun
1620*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
1621*4882a593Smuzhiyun crtc->wm.active.g4x = crtc_state->wm.g4x.optimal;
1622*4882a593Smuzhiyun g4x_program_watermarks(dev_priv);
1623*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
1624*4882a593Smuzhiyun }
1625*4882a593Smuzhiyun
1626*4882a593Smuzhiyun /* latency must be in 0.1us units. */
vlv_wm_method2(unsigned int pixel_rate,unsigned int htotal,unsigned int width,unsigned int cpp,unsigned int latency)1627*4882a593Smuzhiyun static unsigned int vlv_wm_method2(unsigned int pixel_rate,
1628*4882a593Smuzhiyun unsigned int htotal,
1629*4882a593Smuzhiyun unsigned int width,
1630*4882a593Smuzhiyun unsigned int cpp,
1631*4882a593Smuzhiyun unsigned int latency)
1632*4882a593Smuzhiyun {
1633*4882a593Smuzhiyun unsigned int ret;
1634*4882a593Smuzhiyun
1635*4882a593Smuzhiyun ret = intel_wm_method2(pixel_rate, htotal,
1636*4882a593Smuzhiyun width, cpp, latency);
1637*4882a593Smuzhiyun ret = DIV_ROUND_UP(ret, 64);
1638*4882a593Smuzhiyun
1639*4882a593Smuzhiyun return ret;
1640*4882a593Smuzhiyun }
1641*4882a593Smuzhiyun
vlv_setup_wm_latency(struct drm_i915_private * dev_priv)1642*4882a593Smuzhiyun static void vlv_setup_wm_latency(struct drm_i915_private *dev_priv)
1643*4882a593Smuzhiyun {
1644*4882a593Smuzhiyun /* all latencies in usec */
1645*4882a593Smuzhiyun dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM2] = 3;
1646*4882a593Smuzhiyun
1647*4882a593Smuzhiyun dev_priv->wm.max_level = VLV_WM_LEVEL_PM2;
1648*4882a593Smuzhiyun
1649*4882a593Smuzhiyun if (IS_CHERRYVIEW(dev_priv)) {
1650*4882a593Smuzhiyun dev_priv->wm.pri_latency[VLV_WM_LEVEL_PM5] = 12;
1651*4882a593Smuzhiyun dev_priv->wm.pri_latency[VLV_WM_LEVEL_DDR_DVFS] = 33;
1652*4882a593Smuzhiyun
1653*4882a593Smuzhiyun dev_priv->wm.max_level = VLV_WM_LEVEL_DDR_DVFS;
1654*4882a593Smuzhiyun }
1655*4882a593Smuzhiyun }
1656*4882a593Smuzhiyun
vlv_compute_wm_level(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,int level)1657*4882a593Smuzhiyun static u16 vlv_compute_wm_level(const struct intel_crtc_state *crtc_state,
1658*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
1659*4882a593Smuzhiyun int level)
1660*4882a593Smuzhiyun {
1661*4882a593Smuzhiyun struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1662*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
1663*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode =
1664*4882a593Smuzhiyun &crtc_state->hw.adjusted_mode;
1665*4882a593Smuzhiyun unsigned int clock, htotal, cpp, width, wm;
1666*4882a593Smuzhiyun
1667*4882a593Smuzhiyun if (dev_priv->wm.pri_latency[level] == 0)
1668*4882a593Smuzhiyun return USHRT_MAX;
1669*4882a593Smuzhiyun
1670*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state))
1671*4882a593Smuzhiyun return 0;
1672*4882a593Smuzhiyun
1673*4882a593Smuzhiyun cpp = plane_state->hw.fb->format->cpp[0];
1674*4882a593Smuzhiyun clock = adjusted_mode->crtc_clock;
1675*4882a593Smuzhiyun htotal = adjusted_mode->crtc_htotal;
1676*4882a593Smuzhiyun width = crtc_state->pipe_src_w;
1677*4882a593Smuzhiyun
1678*4882a593Smuzhiyun if (plane->id == PLANE_CURSOR) {
1679*4882a593Smuzhiyun /*
1680*4882a593Smuzhiyun * FIXME the formula gives values that are
1681*4882a593Smuzhiyun * too big for the cursor FIFO, and hence we
1682*4882a593Smuzhiyun * would never be able to use cursors. For
1683*4882a593Smuzhiyun * now just hardcode the watermark.
1684*4882a593Smuzhiyun */
1685*4882a593Smuzhiyun wm = 63;
1686*4882a593Smuzhiyun } else {
1687*4882a593Smuzhiyun wm = vlv_wm_method2(clock, htotal, width, cpp,
1688*4882a593Smuzhiyun dev_priv->wm.pri_latency[level] * 10);
1689*4882a593Smuzhiyun }
1690*4882a593Smuzhiyun
1691*4882a593Smuzhiyun return min_t(unsigned int, wm, USHRT_MAX);
1692*4882a593Smuzhiyun }
1693*4882a593Smuzhiyun
vlv_need_sprite0_fifo_workaround(unsigned int active_planes)1694*4882a593Smuzhiyun static bool vlv_need_sprite0_fifo_workaround(unsigned int active_planes)
1695*4882a593Smuzhiyun {
1696*4882a593Smuzhiyun return (active_planes & (BIT(PLANE_SPRITE0) |
1697*4882a593Smuzhiyun BIT(PLANE_SPRITE1))) == BIT(PLANE_SPRITE1);
1698*4882a593Smuzhiyun }
1699*4882a593Smuzhiyun
vlv_compute_fifo(struct intel_crtc_state * crtc_state)1700*4882a593Smuzhiyun static int vlv_compute_fifo(struct intel_crtc_state *crtc_state)
1701*4882a593Smuzhiyun {
1702*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1703*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1704*4882a593Smuzhiyun const struct g4x_pipe_wm *raw =
1705*4882a593Smuzhiyun &crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2];
1706*4882a593Smuzhiyun struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state;
1707*4882a593Smuzhiyun unsigned int active_planes = crtc_state->active_planes & ~BIT(PLANE_CURSOR);
1708*4882a593Smuzhiyun int num_active_planes = hweight8(active_planes);
1709*4882a593Smuzhiyun const int fifo_size = 511;
1710*4882a593Smuzhiyun int fifo_extra, fifo_left = fifo_size;
1711*4882a593Smuzhiyun int sprite0_fifo_extra = 0;
1712*4882a593Smuzhiyun unsigned int total_rate;
1713*4882a593Smuzhiyun enum plane_id plane_id;
1714*4882a593Smuzhiyun
1715*4882a593Smuzhiyun /*
1716*4882a593Smuzhiyun * When enabling sprite0 after sprite1 has already been enabled
1717*4882a593Smuzhiyun * we tend to get an underrun unless sprite0 already has some
1718*4882a593Smuzhiyun * FIFO space allcoated. Hence we always allocate at least one
1719*4882a593Smuzhiyun * cacheline for sprite0 whenever sprite1 is enabled.
1720*4882a593Smuzhiyun *
1721*4882a593Smuzhiyun * All other plane enable sequences appear immune to this problem.
1722*4882a593Smuzhiyun */
1723*4882a593Smuzhiyun if (vlv_need_sprite0_fifo_workaround(active_planes))
1724*4882a593Smuzhiyun sprite0_fifo_extra = 1;
1725*4882a593Smuzhiyun
1726*4882a593Smuzhiyun total_rate = raw->plane[PLANE_PRIMARY] +
1727*4882a593Smuzhiyun raw->plane[PLANE_SPRITE0] +
1728*4882a593Smuzhiyun raw->plane[PLANE_SPRITE1] +
1729*4882a593Smuzhiyun sprite0_fifo_extra;
1730*4882a593Smuzhiyun
1731*4882a593Smuzhiyun if (total_rate > fifo_size)
1732*4882a593Smuzhiyun return -EINVAL;
1733*4882a593Smuzhiyun
1734*4882a593Smuzhiyun if (total_rate == 0)
1735*4882a593Smuzhiyun total_rate = 1;
1736*4882a593Smuzhiyun
1737*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
1738*4882a593Smuzhiyun unsigned int rate;
1739*4882a593Smuzhiyun
1740*4882a593Smuzhiyun if ((active_planes & BIT(plane_id)) == 0) {
1741*4882a593Smuzhiyun fifo_state->plane[plane_id] = 0;
1742*4882a593Smuzhiyun continue;
1743*4882a593Smuzhiyun }
1744*4882a593Smuzhiyun
1745*4882a593Smuzhiyun rate = raw->plane[plane_id];
1746*4882a593Smuzhiyun fifo_state->plane[plane_id] = fifo_size * rate / total_rate;
1747*4882a593Smuzhiyun fifo_left -= fifo_state->plane[plane_id];
1748*4882a593Smuzhiyun }
1749*4882a593Smuzhiyun
1750*4882a593Smuzhiyun fifo_state->plane[PLANE_SPRITE0] += sprite0_fifo_extra;
1751*4882a593Smuzhiyun fifo_left -= sprite0_fifo_extra;
1752*4882a593Smuzhiyun
1753*4882a593Smuzhiyun fifo_state->plane[PLANE_CURSOR] = 63;
1754*4882a593Smuzhiyun
1755*4882a593Smuzhiyun fifo_extra = DIV_ROUND_UP(fifo_left, num_active_planes ?: 1);
1756*4882a593Smuzhiyun
1757*4882a593Smuzhiyun /* spread the remainder evenly */
1758*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
1759*4882a593Smuzhiyun int plane_extra;
1760*4882a593Smuzhiyun
1761*4882a593Smuzhiyun if (fifo_left == 0)
1762*4882a593Smuzhiyun break;
1763*4882a593Smuzhiyun
1764*4882a593Smuzhiyun if ((active_planes & BIT(plane_id)) == 0)
1765*4882a593Smuzhiyun continue;
1766*4882a593Smuzhiyun
1767*4882a593Smuzhiyun plane_extra = min(fifo_extra, fifo_left);
1768*4882a593Smuzhiyun fifo_state->plane[plane_id] += plane_extra;
1769*4882a593Smuzhiyun fifo_left -= plane_extra;
1770*4882a593Smuzhiyun }
1771*4882a593Smuzhiyun
1772*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, active_planes != 0 && fifo_left != 0);
1773*4882a593Smuzhiyun
1774*4882a593Smuzhiyun /* give it all to the first plane if none are active */
1775*4882a593Smuzhiyun if (active_planes == 0) {
1776*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, fifo_left != fifo_size);
1777*4882a593Smuzhiyun fifo_state->plane[PLANE_PRIMARY] = fifo_left;
1778*4882a593Smuzhiyun }
1779*4882a593Smuzhiyun
1780*4882a593Smuzhiyun return 0;
1781*4882a593Smuzhiyun }
1782*4882a593Smuzhiyun
1783*4882a593Smuzhiyun /* mark all levels starting from 'level' as invalid */
vlv_invalidate_wms(struct intel_crtc * crtc,struct vlv_wm_state * wm_state,int level)1784*4882a593Smuzhiyun static void vlv_invalidate_wms(struct intel_crtc *crtc,
1785*4882a593Smuzhiyun struct vlv_wm_state *wm_state, int level)
1786*4882a593Smuzhiyun {
1787*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1788*4882a593Smuzhiyun
1789*4882a593Smuzhiyun for (; level < intel_wm_num_levels(dev_priv); level++) {
1790*4882a593Smuzhiyun enum plane_id plane_id;
1791*4882a593Smuzhiyun
1792*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id)
1793*4882a593Smuzhiyun wm_state->wm[level].plane[plane_id] = USHRT_MAX;
1794*4882a593Smuzhiyun
1795*4882a593Smuzhiyun wm_state->sr[level].cursor = USHRT_MAX;
1796*4882a593Smuzhiyun wm_state->sr[level].plane = USHRT_MAX;
1797*4882a593Smuzhiyun }
1798*4882a593Smuzhiyun }
1799*4882a593Smuzhiyun
vlv_invert_wm_value(u16 wm,u16 fifo_size)1800*4882a593Smuzhiyun static u16 vlv_invert_wm_value(u16 wm, u16 fifo_size)
1801*4882a593Smuzhiyun {
1802*4882a593Smuzhiyun if (wm > fifo_size)
1803*4882a593Smuzhiyun return USHRT_MAX;
1804*4882a593Smuzhiyun else
1805*4882a593Smuzhiyun return fifo_size - wm;
1806*4882a593Smuzhiyun }
1807*4882a593Smuzhiyun
1808*4882a593Smuzhiyun /*
1809*4882a593Smuzhiyun * Starting from 'level' set all higher
1810*4882a593Smuzhiyun * levels to 'value' in the "raw" watermarks.
1811*4882a593Smuzhiyun */
vlv_raw_plane_wm_set(struct intel_crtc_state * crtc_state,int level,enum plane_id plane_id,u16 value)1812*4882a593Smuzhiyun static bool vlv_raw_plane_wm_set(struct intel_crtc_state *crtc_state,
1813*4882a593Smuzhiyun int level, enum plane_id plane_id, u16 value)
1814*4882a593Smuzhiyun {
1815*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1816*4882a593Smuzhiyun int num_levels = intel_wm_num_levels(dev_priv);
1817*4882a593Smuzhiyun bool dirty = false;
1818*4882a593Smuzhiyun
1819*4882a593Smuzhiyun for (; level < num_levels; level++) {
1820*4882a593Smuzhiyun struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
1821*4882a593Smuzhiyun
1822*4882a593Smuzhiyun dirty |= raw->plane[plane_id] != value;
1823*4882a593Smuzhiyun raw->plane[plane_id] = value;
1824*4882a593Smuzhiyun }
1825*4882a593Smuzhiyun
1826*4882a593Smuzhiyun return dirty;
1827*4882a593Smuzhiyun }
1828*4882a593Smuzhiyun
vlv_raw_plane_wm_compute(struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)1829*4882a593Smuzhiyun static bool vlv_raw_plane_wm_compute(struct intel_crtc_state *crtc_state,
1830*4882a593Smuzhiyun const struct intel_plane_state *plane_state)
1831*4882a593Smuzhiyun {
1832*4882a593Smuzhiyun struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
1833*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1834*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
1835*4882a593Smuzhiyun int num_levels = intel_wm_num_levels(to_i915(plane->base.dev));
1836*4882a593Smuzhiyun int level;
1837*4882a593Smuzhiyun bool dirty = false;
1838*4882a593Smuzhiyun
1839*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state)) {
1840*4882a593Smuzhiyun dirty |= vlv_raw_plane_wm_set(crtc_state, 0, plane_id, 0);
1841*4882a593Smuzhiyun goto out;
1842*4882a593Smuzhiyun }
1843*4882a593Smuzhiyun
1844*4882a593Smuzhiyun for (level = 0; level < num_levels; level++) {
1845*4882a593Smuzhiyun struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
1846*4882a593Smuzhiyun int wm = vlv_compute_wm_level(crtc_state, plane_state, level);
1847*4882a593Smuzhiyun int max_wm = plane_id == PLANE_CURSOR ? 63 : 511;
1848*4882a593Smuzhiyun
1849*4882a593Smuzhiyun if (wm > max_wm)
1850*4882a593Smuzhiyun break;
1851*4882a593Smuzhiyun
1852*4882a593Smuzhiyun dirty |= raw->plane[plane_id] != wm;
1853*4882a593Smuzhiyun raw->plane[plane_id] = wm;
1854*4882a593Smuzhiyun }
1855*4882a593Smuzhiyun
1856*4882a593Smuzhiyun /* mark all higher levels as invalid */
1857*4882a593Smuzhiyun dirty |= vlv_raw_plane_wm_set(crtc_state, level, plane_id, USHRT_MAX);
1858*4882a593Smuzhiyun
1859*4882a593Smuzhiyun out:
1860*4882a593Smuzhiyun if (dirty)
1861*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
1862*4882a593Smuzhiyun "%s watermarks: PM2=%d, PM5=%d, DDR DVFS=%d\n",
1863*4882a593Smuzhiyun plane->base.name,
1864*4882a593Smuzhiyun crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM2].plane[plane_id],
1865*4882a593Smuzhiyun crtc_state->wm.vlv.raw[VLV_WM_LEVEL_PM5].plane[plane_id],
1866*4882a593Smuzhiyun crtc_state->wm.vlv.raw[VLV_WM_LEVEL_DDR_DVFS].plane[plane_id]);
1867*4882a593Smuzhiyun
1868*4882a593Smuzhiyun return dirty;
1869*4882a593Smuzhiyun }
1870*4882a593Smuzhiyun
vlv_raw_plane_wm_is_valid(const struct intel_crtc_state * crtc_state,enum plane_id plane_id,int level)1871*4882a593Smuzhiyun static bool vlv_raw_plane_wm_is_valid(const struct intel_crtc_state *crtc_state,
1872*4882a593Smuzhiyun enum plane_id plane_id, int level)
1873*4882a593Smuzhiyun {
1874*4882a593Smuzhiyun const struct g4x_pipe_wm *raw =
1875*4882a593Smuzhiyun &crtc_state->wm.vlv.raw[level];
1876*4882a593Smuzhiyun const struct vlv_fifo_state *fifo_state =
1877*4882a593Smuzhiyun &crtc_state->wm.vlv.fifo_state;
1878*4882a593Smuzhiyun
1879*4882a593Smuzhiyun return raw->plane[plane_id] <= fifo_state->plane[plane_id];
1880*4882a593Smuzhiyun }
1881*4882a593Smuzhiyun
vlv_raw_crtc_wm_is_valid(const struct intel_crtc_state * crtc_state,int level)1882*4882a593Smuzhiyun static bool vlv_raw_crtc_wm_is_valid(const struct intel_crtc_state *crtc_state, int level)
1883*4882a593Smuzhiyun {
1884*4882a593Smuzhiyun return vlv_raw_plane_wm_is_valid(crtc_state, PLANE_PRIMARY, level) &&
1885*4882a593Smuzhiyun vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE0, level) &&
1886*4882a593Smuzhiyun vlv_raw_plane_wm_is_valid(crtc_state, PLANE_SPRITE1, level) &&
1887*4882a593Smuzhiyun vlv_raw_plane_wm_is_valid(crtc_state, PLANE_CURSOR, level);
1888*4882a593Smuzhiyun }
1889*4882a593Smuzhiyun
vlv_compute_pipe_wm(struct intel_crtc_state * crtc_state)1890*4882a593Smuzhiyun static int vlv_compute_pipe_wm(struct intel_crtc_state *crtc_state)
1891*4882a593Smuzhiyun {
1892*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1893*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1894*4882a593Smuzhiyun struct intel_atomic_state *state =
1895*4882a593Smuzhiyun to_intel_atomic_state(crtc_state->uapi.state);
1896*4882a593Smuzhiyun struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal;
1897*4882a593Smuzhiyun const struct vlv_fifo_state *fifo_state =
1898*4882a593Smuzhiyun &crtc_state->wm.vlv.fifo_state;
1899*4882a593Smuzhiyun int num_active_planes = hweight8(crtc_state->active_planes &
1900*4882a593Smuzhiyun ~BIT(PLANE_CURSOR));
1901*4882a593Smuzhiyun bool needs_modeset = drm_atomic_crtc_needs_modeset(&crtc_state->uapi);
1902*4882a593Smuzhiyun const struct intel_plane_state *old_plane_state;
1903*4882a593Smuzhiyun const struct intel_plane_state *new_plane_state;
1904*4882a593Smuzhiyun struct intel_plane *plane;
1905*4882a593Smuzhiyun enum plane_id plane_id;
1906*4882a593Smuzhiyun int level, ret, i;
1907*4882a593Smuzhiyun unsigned int dirty = 0;
1908*4882a593Smuzhiyun
1909*4882a593Smuzhiyun for_each_oldnew_intel_plane_in_state(state, plane,
1910*4882a593Smuzhiyun old_plane_state,
1911*4882a593Smuzhiyun new_plane_state, i) {
1912*4882a593Smuzhiyun if (new_plane_state->hw.crtc != &crtc->base &&
1913*4882a593Smuzhiyun old_plane_state->hw.crtc != &crtc->base)
1914*4882a593Smuzhiyun continue;
1915*4882a593Smuzhiyun
1916*4882a593Smuzhiyun if (vlv_raw_plane_wm_compute(crtc_state, new_plane_state))
1917*4882a593Smuzhiyun dirty |= BIT(plane->id);
1918*4882a593Smuzhiyun }
1919*4882a593Smuzhiyun
1920*4882a593Smuzhiyun /*
1921*4882a593Smuzhiyun * DSPARB registers may have been reset due to the
1922*4882a593Smuzhiyun * power well being turned off. Make sure we restore
1923*4882a593Smuzhiyun * them to a consistent state even if no primary/sprite
1924*4882a593Smuzhiyun * planes are initially active.
1925*4882a593Smuzhiyun */
1926*4882a593Smuzhiyun if (needs_modeset)
1927*4882a593Smuzhiyun crtc_state->fifo_changed = true;
1928*4882a593Smuzhiyun
1929*4882a593Smuzhiyun if (!dirty)
1930*4882a593Smuzhiyun return 0;
1931*4882a593Smuzhiyun
1932*4882a593Smuzhiyun /* cursor changes don't warrant a FIFO recompute */
1933*4882a593Smuzhiyun if (dirty & ~BIT(PLANE_CURSOR)) {
1934*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state =
1935*4882a593Smuzhiyun intel_atomic_get_old_crtc_state(state, crtc);
1936*4882a593Smuzhiyun const struct vlv_fifo_state *old_fifo_state =
1937*4882a593Smuzhiyun &old_crtc_state->wm.vlv.fifo_state;
1938*4882a593Smuzhiyun
1939*4882a593Smuzhiyun ret = vlv_compute_fifo(crtc_state);
1940*4882a593Smuzhiyun if (ret)
1941*4882a593Smuzhiyun return ret;
1942*4882a593Smuzhiyun
1943*4882a593Smuzhiyun if (needs_modeset ||
1944*4882a593Smuzhiyun memcmp(old_fifo_state, fifo_state,
1945*4882a593Smuzhiyun sizeof(*fifo_state)) != 0)
1946*4882a593Smuzhiyun crtc_state->fifo_changed = true;
1947*4882a593Smuzhiyun }
1948*4882a593Smuzhiyun
1949*4882a593Smuzhiyun /* initially allow all levels */
1950*4882a593Smuzhiyun wm_state->num_levels = intel_wm_num_levels(dev_priv);
1951*4882a593Smuzhiyun /*
1952*4882a593Smuzhiyun * Note that enabling cxsr with no primary/sprite planes
1953*4882a593Smuzhiyun * enabled can wedge the pipe. Hence we only allow cxsr
1954*4882a593Smuzhiyun * with exactly one enabled primary/sprite plane.
1955*4882a593Smuzhiyun */
1956*4882a593Smuzhiyun wm_state->cxsr = crtc->pipe != PIPE_C && num_active_planes == 1;
1957*4882a593Smuzhiyun
1958*4882a593Smuzhiyun for (level = 0; level < wm_state->num_levels; level++) {
1959*4882a593Smuzhiyun const struct g4x_pipe_wm *raw = &crtc_state->wm.vlv.raw[level];
1960*4882a593Smuzhiyun const int sr_fifo_size = INTEL_NUM_PIPES(dev_priv) * 512 - 1;
1961*4882a593Smuzhiyun
1962*4882a593Smuzhiyun if (!vlv_raw_crtc_wm_is_valid(crtc_state, level))
1963*4882a593Smuzhiyun break;
1964*4882a593Smuzhiyun
1965*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
1966*4882a593Smuzhiyun wm_state->wm[level].plane[plane_id] =
1967*4882a593Smuzhiyun vlv_invert_wm_value(raw->plane[plane_id],
1968*4882a593Smuzhiyun fifo_state->plane[plane_id]);
1969*4882a593Smuzhiyun }
1970*4882a593Smuzhiyun
1971*4882a593Smuzhiyun wm_state->sr[level].plane =
1972*4882a593Smuzhiyun vlv_invert_wm_value(max3(raw->plane[PLANE_PRIMARY],
1973*4882a593Smuzhiyun raw->plane[PLANE_SPRITE0],
1974*4882a593Smuzhiyun raw->plane[PLANE_SPRITE1]),
1975*4882a593Smuzhiyun sr_fifo_size);
1976*4882a593Smuzhiyun
1977*4882a593Smuzhiyun wm_state->sr[level].cursor =
1978*4882a593Smuzhiyun vlv_invert_wm_value(raw->plane[PLANE_CURSOR],
1979*4882a593Smuzhiyun 63);
1980*4882a593Smuzhiyun }
1981*4882a593Smuzhiyun
1982*4882a593Smuzhiyun if (level == 0)
1983*4882a593Smuzhiyun return -EINVAL;
1984*4882a593Smuzhiyun
1985*4882a593Smuzhiyun /* limit to only levels we can actually handle */
1986*4882a593Smuzhiyun wm_state->num_levels = level;
1987*4882a593Smuzhiyun
1988*4882a593Smuzhiyun /* invalidate the higher levels */
1989*4882a593Smuzhiyun vlv_invalidate_wms(crtc, wm_state, level);
1990*4882a593Smuzhiyun
1991*4882a593Smuzhiyun return 0;
1992*4882a593Smuzhiyun }
1993*4882a593Smuzhiyun
1994*4882a593Smuzhiyun #define VLV_FIFO(plane, value) \
1995*4882a593Smuzhiyun (((value) << DSPARB_ ## plane ## _SHIFT_VLV) & DSPARB_ ## plane ## _MASK_VLV)
1996*4882a593Smuzhiyun
vlv_atomic_update_fifo(struct intel_atomic_state * state,struct intel_crtc * crtc)1997*4882a593Smuzhiyun static void vlv_atomic_update_fifo(struct intel_atomic_state *state,
1998*4882a593Smuzhiyun struct intel_crtc *crtc)
1999*4882a593Smuzhiyun {
2000*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2001*4882a593Smuzhiyun struct intel_uncore *uncore = &dev_priv->uncore;
2002*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state =
2003*4882a593Smuzhiyun intel_atomic_get_new_crtc_state(state, crtc);
2004*4882a593Smuzhiyun const struct vlv_fifo_state *fifo_state =
2005*4882a593Smuzhiyun &crtc_state->wm.vlv.fifo_state;
2006*4882a593Smuzhiyun int sprite0_start, sprite1_start, fifo_size;
2007*4882a593Smuzhiyun u32 dsparb, dsparb2, dsparb3;
2008*4882a593Smuzhiyun
2009*4882a593Smuzhiyun if (!crtc_state->fifo_changed)
2010*4882a593Smuzhiyun return;
2011*4882a593Smuzhiyun
2012*4882a593Smuzhiyun sprite0_start = fifo_state->plane[PLANE_PRIMARY];
2013*4882a593Smuzhiyun sprite1_start = fifo_state->plane[PLANE_SPRITE0] + sprite0_start;
2014*4882a593Smuzhiyun fifo_size = fifo_state->plane[PLANE_SPRITE1] + sprite1_start;
2015*4882a593Smuzhiyun
2016*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, fifo_state->plane[PLANE_CURSOR] != 63);
2017*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, fifo_size != 511);
2018*4882a593Smuzhiyun
2019*4882a593Smuzhiyun trace_vlv_fifo_size(crtc, sprite0_start, sprite1_start, fifo_size);
2020*4882a593Smuzhiyun
2021*4882a593Smuzhiyun /*
2022*4882a593Smuzhiyun * uncore.lock serves a double purpose here. It allows us to
2023*4882a593Smuzhiyun * use the less expensive I915_{READ,WRITE}_FW() functions, and
2024*4882a593Smuzhiyun * it protects the DSPARB registers from getting clobbered by
2025*4882a593Smuzhiyun * parallel updates from multiple pipes.
2026*4882a593Smuzhiyun *
2027*4882a593Smuzhiyun * intel_pipe_update_start() has already disabled interrupts
2028*4882a593Smuzhiyun * for us, so a plain spin_lock() is sufficient here.
2029*4882a593Smuzhiyun */
2030*4882a593Smuzhiyun spin_lock(&uncore->lock);
2031*4882a593Smuzhiyun
2032*4882a593Smuzhiyun switch (crtc->pipe) {
2033*4882a593Smuzhiyun case PIPE_A:
2034*4882a593Smuzhiyun dsparb = intel_uncore_read_fw(uncore, DSPARB);
2035*4882a593Smuzhiyun dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
2036*4882a593Smuzhiyun
2037*4882a593Smuzhiyun dsparb &= ~(VLV_FIFO(SPRITEA, 0xff) |
2038*4882a593Smuzhiyun VLV_FIFO(SPRITEB, 0xff));
2039*4882a593Smuzhiyun dsparb |= (VLV_FIFO(SPRITEA, sprite0_start) |
2040*4882a593Smuzhiyun VLV_FIFO(SPRITEB, sprite1_start));
2041*4882a593Smuzhiyun
2042*4882a593Smuzhiyun dsparb2 &= ~(VLV_FIFO(SPRITEA_HI, 0x1) |
2043*4882a593Smuzhiyun VLV_FIFO(SPRITEB_HI, 0x1));
2044*4882a593Smuzhiyun dsparb2 |= (VLV_FIFO(SPRITEA_HI, sprite0_start >> 8) |
2045*4882a593Smuzhiyun VLV_FIFO(SPRITEB_HI, sprite1_start >> 8));
2046*4882a593Smuzhiyun
2047*4882a593Smuzhiyun intel_uncore_write_fw(uncore, DSPARB, dsparb);
2048*4882a593Smuzhiyun intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
2049*4882a593Smuzhiyun break;
2050*4882a593Smuzhiyun case PIPE_B:
2051*4882a593Smuzhiyun dsparb = intel_uncore_read_fw(uncore, DSPARB);
2052*4882a593Smuzhiyun dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
2053*4882a593Smuzhiyun
2054*4882a593Smuzhiyun dsparb &= ~(VLV_FIFO(SPRITEC, 0xff) |
2055*4882a593Smuzhiyun VLV_FIFO(SPRITED, 0xff));
2056*4882a593Smuzhiyun dsparb |= (VLV_FIFO(SPRITEC, sprite0_start) |
2057*4882a593Smuzhiyun VLV_FIFO(SPRITED, sprite1_start));
2058*4882a593Smuzhiyun
2059*4882a593Smuzhiyun dsparb2 &= ~(VLV_FIFO(SPRITEC_HI, 0xff) |
2060*4882a593Smuzhiyun VLV_FIFO(SPRITED_HI, 0xff));
2061*4882a593Smuzhiyun dsparb2 |= (VLV_FIFO(SPRITEC_HI, sprite0_start >> 8) |
2062*4882a593Smuzhiyun VLV_FIFO(SPRITED_HI, sprite1_start >> 8));
2063*4882a593Smuzhiyun
2064*4882a593Smuzhiyun intel_uncore_write_fw(uncore, DSPARB, dsparb);
2065*4882a593Smuzhiyun intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
2066*4882a593Smuzhiyun break;
2067*4882a593Smuzhiyun case PIPE_C:
2068*4882a593Smuzhiyun dsparb3 = intel_uncore_read_fw(uncore, DSPARB3);
2069*4882a593Smuzhiyun dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
2070*4882a593Smuzhiyun
2071*4882a593Smuzhiyun dsparb3 &= ~(VLV_FIFO(SPRITEE, 0xff) |
2072*4882a593Smuzhiyun VLV_FIFO(SPRITEF, 0xff));
2073*4882a593Smuzhiyun dsparb3 |= (VLV_FIFO(SPRITEE, sprite0_start) |
2074*4882a593Smuzhiyun VLV_FIFO(SPRITEF, sprite1_start));
2075*4882a593Smuzhiyun
2076*4882a593Smuzhiyun dsparb2 &= ~(VLV_FIFO(SPRITEE_HI, 0xff) |
2077*4882a593Smuzhiyun VLV_FIFO(SPRITEF_HI, 0xff));
2078*4882a593Smuzhiyun dsparb2 |= (VLV_FIFO(SPRITEE_HI, sprite0_start >> 8) |
2079*4882a593Smuzhiyun VLV_FIFO(SPRITEF_HI, sprite1_start >> 8));
2080*4882a593Smuzhiyun
2081*4882a593Smuzhiyun intel_uncore_write_fw(uncore, DSPARB3, dsparb3);
2082*4882a593Smuzhiyun intel_uncore_write_fw(uncore, DSPARB2, dsparb2);
2083*4882a593Smuzhiyun break;
2084*4882a593Smuzhiyun default:
2085*4882a593Smuzhiyun break;
2086*4882a593Smuzhiyun }
2087*4882a593Smuzhiyun
2088*4882a593Smuzhiyun intel_uncore_posting_read_fw(uncore, DSPARB);
2089*4882a593Smuzhiyun
2090*4882a593Smuzhiyun spin_unlock(&uncore->lock);
2091*4882a593Smuzhiyun }
2092*4882a593Smuzhiyun
2093*4882a593Smuzhiyun #undef VLV_FIFO
2094*4882a593Smuzhiyun
vlv_compute_intermediate_wm(struct intel_crtc_state * new_crtc_state)2095*4882a593Smuzhiyun static int vlv_compute_intermediate_wm(struct intel_crtc_state *new_crtc_state)
2096*4882a593Smuzhiyun {
2097*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
2098*4882a593Smuzhiyun struct vlv_wm_state *intermediate = &new_crtc_state->wm.vlv.intermediate;
2099*4882a593Smuzhiyun const struct vlv_wm_state *optimal = &new_crtc_state->wm.vlv.optimal;
2100*4882a593Smuzhiyun struct intel_atomic_state *intel_state =
2101*4882a593Smuzhiyun to_intel_atomic_state(new_crtc_state->uapi.state);
2102*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state =
2103*4882a593Smuzhiyun intel_atomic_get_old_crtc_state(intel_state, crtc);
2104*4882a593Smuzhiyun const struct vlv_wm_state *active = &old_crtc_state->wm.vlv.optimal;
2105*4882a593Smuzhiyun int level;
2106*4882a593Smuzhiyun
2107*4882a593Smuzhiyun if (!new_crtc_state->hw.active || drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi)) {
2108*4882a593Smuzhiyun *intermediate = *optimal;
2109*4882a593Smuzhiyun
2110*4882a593Smuzhiyun intermediate->cxsr = false;
2111*4882a593Smuzhiyun goto out;
2112*4882a593Smuzhiyun }
2113*4882a593Smuzhiyun
2114*4882a593Smuzhiyun intermediate->num_levels = min(optimal->num_levels, active->num_levels);
2115*4882a593Smuzhiyun intermediate->cxsr = optimal->cxsr && active->cxsr &&
2116*4882a593Smuzhiyun !new_crtc_state->disable_cxsr;
2117*4882a593Smuzhiyun
2118*4882a593Smuzhiyun for (level = 0; level < intermediate->num_levels; level++) {
2119*4882a593Smuzhiyun enum plane_id plane_id;
2120*4882a593Smuzhiyun
2121*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
2122*4882a593Smuzhiyun intermediate->wm[level].plane[plane_id] =
2123*4882a593Smuzhiyun min(optimal->wm[level].plane[plane_id],
2124*4882a593Smuzhiyun active->wm[level].plane[plane_id]);
2125*4882a593Smuzhiyun }
2126*4882a593Smuzhiyun
2127*4882a593Smuzhiyun intermediate->sr[level].plane = min(optimal->sr[level].plane,
2128*4882a593Smuzhiyun active->sr[level].plane);
2129*4882a593Smuzhiyun intermediate->sr[level].cursor = min(optimal->sr[level].cursor,
2130*4882a593Smuzhiyun active->sr[level].cursor);
2131*4882a593Smuzhiyun }
2132*4882a593Smuzhiyun
2133*4882a593Smuzhiyun vlv_invalidate_wms(crtc, intermediate, level);
2134*4882a593Smuzhiyun
2135*4882a593Smuzhiyun out:
2136*4882a593Smuzhiyun /*
2137*4882a593Smuzhiyun * If our intermediate WM are identical to the final WM, then we can
2138*4882a593Smuzhiyun * omit the post-vblank programming; only update if it's different.
2139*4882a593Smuzhiyun */
2140*4882a593Smuzhiyun if (memcmp(intermediate, optimal, sizeof(*intermediate)) != 0)
2141*4882a593Smuzhiyun new_crtc_state->wm.need_postvbl_update = true;
2142*4882a593Smuzhiyun
2143*4882a593Smuzhiyun return 0;
2144*4882a593Smuzhiyun }
2145*4882a593Smuzhiyun
vlv_merge_wm(struct drm_i915_private * dev_priv,struct vlv_wm_values * wm)2146*4882a593Smuzhiyun static void vlv_merge_wm(struct drm_i915_private *dev_priv,
2147*4882a593Smuzhiyun struct vlv_wm_values *wm)
2148*4882a593Smuzhiyun {
2149*4882a593Smuzhiyun struct intel_crtc *crtc;
2150*4882a593Smuzhiyun int num_active_pipes = 0;
2151*4882a593Smuzhiyun
2152*4882a593Smuzhiyun wm->level = dev_priv->wm.max_level;
2153*4882a593Smuzhiyun wm->cxsr = true;
2154*4882a593Smuzhiyun
2155*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
2156*4882a593Smuzhiyun const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv;
2157*4882a593Smuzhiyun
2158*4882a593Smuzhiyun if (!crtc->active)
2159*4882a593Smuzhiyun continue;
2160*4882a593Smuzhiyun
2161*4882a593Smuzhiyun if (!wm_state->cxsr)
2162*4882a593Smuzhiyun wm->cxsr = false;
2163*4882a593Smuzhiyun
2164*4882a593Smuzhiyun num_active_pipes++;
2165*4882a593Smuzhiyun wm->level = min_t(int, wm->level, wm_state->num_levels - 1);
2166*4882a593Smuzhiyun }
2167*4882a593Smuzhiyun
2168*4882a593Smuzhiyun if (num_active_pipes != 1)
2169*4882a593Smuzhiyun wm->cxsr = false;
2170*4882a593Smuzhiyun
2171*4882a593Smuzhiyun if (num_active_pipes > 1)
2172*4882a593Smuzhiyun wm->level = VLV_WM_LEVEL_PM2;
2173*4882a593Smuzhiyun
2174*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
2175*4882a593Smuzhiyun const struct vlv_wm_state *wm_state = &crtc->wm.active.vlv;
2176*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
2177*4882a593Smuzhiyun
2178*4882a593Smuzhiyun wm->pipe[pipe] = wm_state->wm[wm->level];
2179*4882a593Smuzhiyun if (crtc->active && wm->cxsr)
2180*4882a593Smuzhiyun wm->sr = wm_state->sr[wm->level];
2181*4882a593Smuzhiyun
2182*4882a593Smuzhiyun wm->ddl[pipe].plane[PLANE_PRIMARY] = DDL_PRECISION_HIGH | 2;
2183*4882a593Smuzhiyun wm->ddl[pipe].plane[PLANE_SPRITE0] = DDL_PRECISION_HIGH | 2;
2184*4882a593Smuzhiyun wm->ddl[pipe].plane[PLANE_SPRITE1] = DDL_PRECISION_HIGH | 2;
2185*4882a593Smuzhiyun wm->ddl[pipe].plane[PLANE_CURSOR] = DDL_PRECISION_HIGH | 2;
2186*4882a593Smuzhiyun }
2187*4882a593Smuzhiyun }
2188*4882a593Smuzhiyun
vlv_program_watermarks(struct drm_i915_private * dev_priv)2189*4882a593Smuzhiyun static void vlv_program_watermarks(struct drm_i915_private *dev_priv)
2190*4882a593Smuzhiyun {
2191*4882a593Smuzhiyun struct vlv_wm_values *old_wm = &dev_priv->wm.vlv;
2192*4882a593Smuzhiyun struct vlv_wm_values new_wm = {};
2193*4882a593Smuzhiyun
2194*4882a593Smuzhiyun vlv_merge_wm(dev_priv, &new_wm);
2195*4882a593Smuzhiyun
2196*4882a593Smuzhiyun if (memcmp(old_wm, &new_wm, sizeof(new_wm)) == 0)
2197*4882a593Smuzhiyun return;
2198*4882a593Smuzhiyun
2199*4882a593Smuzhiyun if (is_disabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_DDR_DVFS))
2200*4882a593Smuzhiyun chv_set_memory_dvfs(dev_priv, false);
2201*4882a593Smuzhiyun
2202*4882a593Smuzhiyun if (is_disabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_PM5))
2203*4882a593Smuzhiyun chv_set_memory_pm5(dev_priv, false);
2204*4882a593Smuzhiyun
2205*4882a593Smuzhiyun if (is_disabling(old_wm->cxsr, new_wm.cxsr, true))
2206*4882a593Smuzhiyun _intel_set_memory_cxsr(dev_priv, false);
2207*4882a593Smuzhiyun
2208*4882a593Smuzhiyun vlv_write_wm_values(dev_priv, &new_wm);
2209*4882a593Smuzhiyun
2210*4882a593Smuzhiyun if (is_enabling(old_wm->cxsr, new_wm.cxsr, true))
2211*4882a593Smuzhiyun _intel_set_memory_cxsr(dev_priv, true);
2212*4882a593Smuzhiyun
2213*4882a593Smuzhiyun if (is_enabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_PM5))
2214*4882a593Smuzhiyun chv_set_memory_pm5(dev_priv, true);
2215*4882a593Smuzhiyun
2216*4882a593Smuzhiyun if (is_enabling(old_wm->level, new_wm.level, VLV_WM_LEVEL_DDR_DVFS))
2217*4882a593Smuzhiyun chv_set_memory_dvfs(dev_priv, true);
2218*4882a593Smuzhiyun
2219*4882a593Smuzhiyun *old_wm = new_wm;
2220*4882a593Smuzhiyun }
2221*4882a593Smuzhiyun
vlv_initial_watermarks(struct intel_atomic_state * state,struct intel_crtc * crtc)2222*4882a593Smuzhiyun static void vlv_initial_watermarks(struct intel_atomic_state *state,
2223*4882a593Smuzhiyun struct intel_crtc *crtc)
2224*4882a593Smuzhiyun {
2225*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2226*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state =
2227*4882a593Smuzhiyun intel_atomic_get_new_crtc_state(state, crtc);
2228*4882a593Smuzhiyun
2229*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
2230*4882a593Smuzhiyun crtc->wm.active.vlv = crtc_state->wm.vlv.intermediate;
2231*4882a593Smuzhiyun vlv_program_watermarks(dev_priv);
2232*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
2233*4882a593Smuzhiyun }
2234*4882a593Smuzhiyun
vlv_optimize_watermarks(struct intel_atomic_state * state,struct intel_crtc * crtc)2235*4882a593Smuzhiyun static void vlv_optimize_watermarks(struct intel_atomic_state *state,
2236*4882a593Smuzhiyun struct intel_crtc *crtc)
2237*4882a593Smuzhiyun {
2238*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2239*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state =
2240*4882a593Smuzhiyun intel_atomic_get_new_crtc_state(state, crtc);
2241*4882a593Smuzhiyun
2242*4882a593Smuzhiyun if (!crtc_state->wm.need_postvbl_update)
2243*4882a593Smuzhiyun return;
2244*4882a593Smuzhiyun
2245*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
2246*4882a593Smuzhiyun crtc->wm.active.vlv = crtc_state->wm.vlv.optimal;
2247*4882a593Smuzhiyun vlv_program_watermarks(dev_priv);
2248*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
2249*4882a593Smuzhiyun }
2250*4882a593Smuzhiyun
i965_update_wm(struct intel_crtc * unused_crtc)2251*4882a593Smuzhiyun static void i965_update_wm(struct intel_crtc *unused_crtc)
2252*4882a593Smuzhiyun {
2253*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev);
2254*4882a593Smuzhiyun struct intel_crtc *crtc;
2255*4882a593Smuzhiyun int srwm = 1;
2256*4882a593Smuzhiyun int cursor_sr = 16;
2257*4882a593Smuzhiyun bool cxsr_enabled;
2258*4882a593Smuzhiyun
2259*4882a593Smuzhiyun /* Calc sr entries for one plane configs */
2260*4882a593Smuzhiyun crtc = single_enabled_crtc(dev_priv);
2261*4882a593Smuzhiyun if (crtc) {
2262*4882a593Smuzhiyun /* self-refresh has much higher latency */
2263*4882a593Smuzhiyun static const int sr_latency_ns = 12000;
2264*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode =
2265*4882a593Smuzhiyun &crtc->config->hw.adjusted_mode;
2266*4882a593Smuzhiyun const struct drm_framebuffer *fb =
2267*4882a593Smuzhiyun crtc->base.primary->state->fb;
2268*4882a593Smuzhiyun int clock = adjusted_mode->crtc_clock;
2269*4882a593Smuzhiyun int htotal = adjusted_mode->crtc_htotal;
2270*4882a593Smuzhiyun int hdisplay = crtc->config->pipe_src_w;
2271*4882a593Smuzhiyun int cpp = fb->format->cpp[0];
2272*4882a593Smuzhiyun int entries;
2273*4882a593Smuzhiyun
2274*4882a593Smuzhiyun entries = intel_wm_method2(clock, htotal,
2275*4882a593Smuzhiyun hdisplay, cpp, sr_latency_ns / 100);
2276*4882a593Smuzhiyun entries = DIV_ROUND_UP(entries, I915_FIFO_LINE_SIZE);
2277*4882a593Smuzhiyun srwm = I965_FIFO_SIZE - entries;
2278*4882a593Smuzhiyun if (srwm < 0)
2279*4882a593Smuzhiyun srwm = 1;
2280*4882a593Smuzhiyun srwm &= 0x1ff;
2281*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
2282*4882a593Smuzhiyun "self-refresh entries: %d, wm: %d\n",
2283*4882a593Smuzhiyun entries, srwm);
2284*4882a593Smuzhiyun
2285*4882a593Smuzhiyun entries = intel_wm_method2(clock, htotal,
2286*4882a593Smuzhiyun crtc->base.cursor->state->crtc_w, 4,
2287*4882a593Smuzhiyun sr_latency_ns / 100);
2288*4882a593Smuzhiyun entries = DIV_ROUND_UP(entries,
2289*4882a593Smuzhiyun i965_cursor_wm_info.cacheline_size) +
2290*4882a593Smuzhiyun i965_cursor_wm_info.guard_size;
2291*4882a593Smuzhiyun
2292*4882a593Smuzhiyun cursor_sr = i965_cursor_wm_info.fifo_size - entries;
2293*4882a593Smuzhiyun if (cursor_sr > i965_cursor_wm_info.max_wm)
2294*4882a593Smuzhiyun cursor_sr = i965_cursor_wm_info.max_wm;
2295*4882a593Smuzhiyun
2296*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
2297*4882a593Smuzhiyun "self-refresh watermark: display plane %d "
2298*4882a593Smuzhiyun "cursor %d\n", srwm, cursor_sr);
2299*4882a593Smuzhiyun
2300*4882a593Smuzhiyun cxsr_enabled = true;
2301*4882a593Smuzhiyun } else {
2302*4882a593Smuzhiyun cxsr_enabled = false;
2303*4882a593Smuzhiyun /* Turn off self refresh if both pipes are enabled */
2304*4882a593Smuzhiyun intel_set_memory_cxsr(dev_priv, false);
2305*4882a593Smuzhiyun }
2306*4882a593Smuzhiyun
2307*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
2308*4882a593Smuzhiyun "Setting FIFO watermarks - A: 8, B: 8, C: 8, SR %d\n",
2309*4882a593Smuzhiyun srwm);
2310*4882a593Smuzhiyun
2311*4882a593Smuzhiyun /* 965 has limitations... */
2312*4882a593Smuzhiyun I915_WRITE(DSPFW1, FW_WM(srwm, SR) |
2313*4882a593Smuzhiyun FW_WM(8, CURSORB) |
2314*4882a593Smuzhiyun FW_WM(8, PLANEB) |
2315*4882a593Smuzhiyun FW_WM(8, PLANEA));
2316*4882a593Smuzhiyun I915_WRITE(DSPFW2, FW_WM(8, CURSORA) |
2317*4882a593Smuzhiyun FW_WM(8, PLANEC_OLD));
2318*4882a593Smuzhiyun /* update cursor SR watermark */
2319*4882a593Smuzhiyun I915_WRITE(DSPFW3, FW_WM(cursor_sr, CURSOR_SR));
2320*4882a593Smuzhiyun
2321*4882a593Smuzhiyun if (cxsr_enabled)
2322*4882a593Smuzhiyun intel_set_memory_cxsr(dev_priv, true);
2323*4882a593Smuzhiyun }
2324*4882a593Smuzhiyun
2325*4882a593Smuzhiyun #undef FW_WM
2326*4882a593Smuzhiyun
i9xx_update_wm(struct intel_crtc * unused_crtc)2327*4882a593Smuzhiyun static void i9xx_update_wm(struct intel_crtc *unused_crtc)
2328*4882a593Smuzhiyun {
2329*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev);
2330*4882a593Smuzhiyun const struct intel_watermark_params *wm_info;
2331*4882a593Smuzhiyun u32 fwater_lo;
2332*4882a593Smuzhiyun u32 fwater_hi;
2333*4882a593Smuzhiyun int cwm, srwm = 1;
2334*4882a593Smuzhiyun int fifo_size;
2335*4882a593Smuzhiyun int planea_wm, planeb_wm;
2336*4882a593Smuzhiyun struct intel_crtc *crtc, *enabled = NULL;
2337*4882a593Smuzhiyun
2338*4882a593Smuzhiyun if (IS_I945GM(dev_priv))
2339*4882a593Smuzhiyun wm_info = &i945_wm_info;
2340*4882a593Smuzhiyun else if (!IS_GEN(dev_priv, 2))
2341*4882a593Smuzhiyun wm_info = &i915_wm_info;
2342*4882a593Smuzhiyun else
2343*4882a593Smuzhiyun wm_info = &i830_a_wm_info;
2344*4882a593Smuzhiyun
2345*4882a593Smuzhiyun fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_A);
2346*4882a593Smuzhiyun crtc = intel_get_crtc_for_plane(dev_priv, PLANE_A);
2347*4882a593Smuzhiyun if (intel_crtc_active(crtc)) {
2348*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode =
2349*4882a593Smuzhiyun &crtc->config->hw.adjusted_mode;
2350*4882a593Smuzhiyun const struct drm_framebuffer *fb =
2351*4882a593Smuzhiyun crtc->base.primary->state->fb;
2352*4882a593Smuzhiyun int cpp;
2353*4882a593Smuzhiyun
2354*4882a593Smuzhiyun if (IS_GEN(dev_priv, 2))
2355*4882a593Smuzhiyun cpp = 4;
2356*4882a593Smuzhiyun else
2357*4882a593Smuzhiyun cpp = fb->format->cpp[0];
2358*4882a593Smuzhiyun
2359*4882a593Smuzhiyun planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
2360*4882a593Smuzhiyun wm_info, fifo_size, cpp,
2361*4882a593Smuzhiyun pessimal_latency_ns);
2362*4882a593Smuzhiyun enabled = crtc;
2363*4882a593Smuzhiyun } else {
2364*4882a593Smuzhiyun planea_wm = fifo_size - wm_info->guard_size;
2365*4882a593Smuzhiyun if (planea_wm > (long)wm_info->max_wm)
2366*4882a593Smuzhiyun planea_wm = wm_info->max_wm;
2367*4882a593Smuzhiyun }
2368*4882a593Smuzhiyun
2369*4882a593Smuzhiyun if (IS_GEN(dev_priv, 2))
2370*4882a593Smuzhiyun wm_info = &i830_bc_wm_info;
2371*4882a593Smuzhiyun
2372*4882a593Smuzhiyun fifo_size = dev_priv->display.get_fifo_size(dev_priv, PLANE_B);
2373*4882a593Smuzhiyun crtc = intel_get_crtc_for_plane(dev_priv, PLANE_B);
2374*4882a593Smuzhiyun if (intel_crtc_active(crtc)) {
2375*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode =
2376*4882a593Smuzhiyun &crtc->config->hw.adjusted_mode;
2377*4882a593Smuzhiyun const struct drm_framebuffer *fb =
2378*4882a593Smuzhiyun crtc->base.primary->state->fb;
2379*4882a593Smuzhiyun int cpp;
2380*4882a593Smuzhiyun
2381*4882a593Smuzhiyun if (IS_GEN(dev_priv, 2))
2382*4882a593Smuzhiyun cpp = 4;
2383*4882a593Smuzhiyun else
2384*4882a593Smuzhiyun cpp = fb->format->cpp[0];
2385*4882a593Smuzhiyun
2386*4882a593Smuzhiyun planeb_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
2387*4882a593Smuzhiyun wm_info, fifo_size, cpp,
2388*4882a593Smuzhiyun pessimal_latency_ns);
2389*4882a593Smuzhiyun if (enabled == NULL)
2390*4882a593Smuzhiyun enabled = crtc;
2391*4882a593Smuzhiyun else
2392*4882a593Smuzhiyun enabled = NULL;
2393*4882a593Smuzhiyun } else {
2394*4882a593Smuzhiyun planeb_wm = fifo_size - wm_info->guard_size;
2395*4882a593Smuzhiyun if (planeb_wm > (long)wm_info->max_wm)
2396*4882a593Smuzhiyun planeb_wm = wm_info->max_wm;
2397*4882a593Smuzhiyun }
2398*4882a593Smuzhiyun
2399*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
2400*4882a593Smuzhiyun "FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
2401*4882a593Smuzhiyun
2402*4882a593Smuzhiyun if (IS_I915GM(dev_priv) && enabled) {
2403*4882a593Smuzhiyun struct drm_i915_gem_object *obj;
2404*4882a593Smuzhiyun
2405*4882a593Smuzhiyun obj = intel_fb_obj(enabled->base.primary->state->fb);
2406*4882a593Smuzhiyun
2407*4882a593Smuzhiyun /* self-refresh seems busted with untiled */
2408*4882a593Smuzhiyun if (!i915_gem_object_is_tiled(obj))
2409*4882a593Smuzhiyun enabled = NULL;
2410*4882a593Smuzhiyun }
2411*4882a593Smuzhiyun
2412*4882a593Smuzhiyun /*
2413*4882a593Smuzhiyun * Overlay gets an aggressive default since video jitter is bad.
2414*4882a593Smuzhiyun */
2415*4882a593Smuzhiyun cwm = 2;
2416*4882a593Smuzhiyun
2417*4882a593Smuzhiyun /* Play safe and disable self-refresh before adjusting watermarks. */
2418*4882a593Smuzhiyun intel_set_memory_cxsr(dev_priv, false);
2419*4882a593Smuzhiyun
2420*4882a593Smuzhiyun /* Calc sr entries for one plane configs */
2421*4882a593Smuzhiyun if (HAS_FW_BLC(dev_priv) && enabled) {
2422*4882a593Smuzhiyun /* self-refresh has much higher latency */
2423*4882a593Smuzhiyun static const int sr_latency_ns = 6000;
2424*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode =
2425*4882a593Smuzhiyun &enabled->config->hw.adjusted_mode;
2426*4882a593Smuzhiyun const struct drm_framebuffer *fb =
2427*4882a593Smuzhiyun enabled->base.primary->state->fb;
2428*4882a593Smuzhiyun int clock = adjusted_mode->crtc_clock;
2429*4882a593Smuzhiyun int htotal = adjusted_mode->crtc_htotal;
2430*4882a593Smuzhiyun int hdisplay = enabled->config->pipe_src_w;
2431*4882a593Smuzhiyun int cpp;
2432*4882a593Smuzhiyun int entries;
2433*4882a593Smuzhiyun
2434*4882a593Smuzhiyun if (IS_I915GM(dev_priv) || IS_I945GM(dev_priv))
2435*4882a593Smuzhiyun cpp = 4;
2436*4882a593Smuzhiyun else
2437*4882a593Smuzhiyun cpp = fb->format->cpp[0];
2438*4882a593Smuzhiyun
2439*4882a593Smuzhiyun entries = intel_wm_method2(clock, htotal, hdisplay, cpp,
2440*4882a593Smuzhiyun sr_latency_ns / 100);
2441*4882a593Smuzhiyun entries = DIV_ROUND_UP(entries, wm_info->cacheline_size);
2442*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
2443*4882a593Smuzhiyun "self-refresh entries: %d\n", entries);
2444*4882a593Smuzhiyun srwm = wm_info->fifo_size - entries;
2445*4882a593Smuzhiyun if (srwm < 0)
2446*4882a593Smuzhiyun srwm = 1;
2447*4882a593Smuzhiyun
2448*4882a593Smuzhiyun if (IS_I945G(dev_priv) || IS_I945GM(dev_priv))
2449*4882a593Smuzhiyun I915_WRITE(FW_BLC_SELF,
2450*4882a593Smuzhiyun FW_BLC_SELF_FIFO_MASK | (srwm & 0xff));
2451*4882a593Smuzhiyun else
2452*4882a593Smuzhiyun I915_WRITE(FW_BLC_SELF, srwm & 0x3f);
2453*4882a593Smuzhiyun }
2454*4882a593Smuzhiyun
2455*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
2456*4882a593Smuzhiyun "Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n",
2457*4882a593Smuzhiyun planea_wm, planeb_wm, cwm, srwm);
2458*4882a593Smuzhiyun
2459*4882a593Smuzhiyun fwater_lo = ((planeb_wm & 0x3f) << 16) | (planea_wm & 0x3f);
2460*4882a593Smuzhiyun fwater_hi = (cwm & 0x1f);
2461*4882a593Smuzhiyun
2462*4882a593Smuzhiyun /* Set request length to 8 cachelines per fetch */
2463*4882a593Smuzhiyun fwater_lo = fwater_lo | (1 << 24) | (1 << 8);
2464*4882a593Smuzhiyun fwater_hi = fwater_hi | (1 << 8);
2465*4882a593Smuzhiyun
2466*4882a593Smuzhiyun I915_WRITE(FW_BLC, fwater_lo);
2467*4882a593Smuzhiyun I915_WRITE(FW_BLC2, fwater_hi);
2468*4882a593Smuzhiyun
2469*4882a593Smuzhiyun if (enabled)
2470*4882a593Smuzhiyun intel_set_memory_cxsr(dev_priv, true);
2471*4882a593Smuzhiyun }
2472*4882a593Smuzhiyun
i845_update_wm(struct intel_crtc * unused_crtc)2473*4882a593Smuzhiyun static void i845_update_wm(struct intel_crtc *unused_crtc)
2474*4882a593Smuzhiyun {
2475*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(unused_crtc->base.dev);
2476*4882a593Smuzhiyun struct intel_crtc *crtc;
2477*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode;
2478*4882a593Smuzhiyun u32 fwater_lo;
2479*4882a593Smuzhiyun int planea_wm;
2480*4882a593Smuzhiyun
2481*4882a593Smuzhiyun crtc = single_enabled_crtc(dev_priv);
2482*4882a593Smuzhiyun if (crtc == NULL)
2483*4882a593Smuzhiyun return;
2484*4882a593Smuzhiyun
2485*4882a593Smuzhiyun adjusted_mode = &crtc->config->hw.adjusted_mode;
2486*4882a593Smuzhiyun planea_wm = intel_calculate_wm(adjusted_mode->crtc_clock,
2487*4882a593Smuzhiyun &i845_wm_info,
2488*4882a593Smuzhiyun dev_priv->display.get_fifo_size(dev_priv, PLANE_A),
2489*4882a593Smuzhiyun 4, pessimal_latency_ns);
2490*4882a593Smuzhiyun fwater_lo = I915_READ(FW_BLC) & ~0xfff;
2491*4882a593Smuzhiyun fwater_lo |= (3<<8) | planea_wm;
2492*4882a593Smuzhiyun
2493*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
2494*4882a593Smuzhiyun "Setting FIFO watermarks - A: %d\n", planea_wm);
2495*4882a593Smuzhiyun
2496*4882a593Smuzhiyun I915_WRITE(FW_BLC, fwater_lo);
2497*4882a593Smuzhiyun }
2498*4882a593Smuzhiyun
2499*4882a593Smuzhiyun /* latency must be in 0.1us units. */
ilk_wm_method1(unsigned int pixel_rate,unsigned int cpp,unsigned int latency)2500*4882a593Smuzhiyun static unsigned int ilk_wm_method1(unsigned int pixel_rate,
2501*4882a593Smuzhiyun unsigned int cpp,
2502*4882a593Smuzhiyun unsigned int latency)
2503*4882a593Smuzhiyun {
2504*4882a593Smuzhiyun unsigned int ret;
2505*4882a593Smuzhiyun
2506*4882a593Smuzhiyun ret = intel_wm_method1(pixel_rate, cpp, latency);
2507*4882a593Smuzhiyun ret = DIV_ROUND_UP(ret, 64) + 2;
2508*4882a593Smuzhiyun
2509*4882a593Smuzhiyun return ret;
2510*4882a593Smuzhiyun }
2511*4882a593Smuzhiyun
2512*4882a593Smuzhiyun /* latency must be in 0.1us units. */
ilk_wm_method2(unsigned int pixel_rate,unsigned int htotal,unsigned int width,unsigned int cpp,unsigned int latency)2513*4882a593Smuzhiyun static unsigned int ilk_wm_method2(unsigned int pixel_rate,
2514*4882a593Smuzhiyun unsigned int htotal,
2515*4882a593Smuzhiyun unsigned int width,
2516*4882a593Smuzhiyun unsigned int cpp,
2517*4882a593Smuzhiyun unsigned int latency)
2518*4882a593Smuzhiyun {
2519*4882a593Smuzhiyun unsigned int ret;
2520*4882a593Smuzhiyun
2521*4882a593Smuzhiyun ret = intel_wm_method2(pixel_rate, htotal,
2522*4882a593Smuzhiyun width, cpp, latency);
2523*4882a593Smuzhiyun ret = DIV_ROUND_UP(ret, 64) + 2;
2524*4882a593Smuzhiyun
2525*4882a593Smuzhiyun return ret;
2526*4882a593Smuzhiyun }
2527*4882a593Smuzhiyun
ilk_wm_fbc(u32 pri_val,u32 horiz_pixels,u8 cpp)2528*4882a593Smuzhiyun static u32 ilk_wm_fbc(u32 pri_val, u32 horiz_pixels, u8 cpp)
2529*4882a593Smuzhiyun {
2530*4882a593Smuzhiyun /*
2531*4882a593Smuzhiyun * Neither of these should be possible since this function shouldn't be
2532*4882a593Smuzhiyun * called if the CRTC is off or the plane is invisible. But let's be
2533*4882a593Smuzhiyun * extra paranoid to avoid a potential divide-by-zero if we screw up
2534*4882a593Smuzhiyun * elsewhere in the driver.
2535*4882a593Smuzhiyun */
2536*4882a593Smuzhiyun if (WARN_ON(!cpp))
2537*4882a593Smuzhiyun return 0;
2538*4882a593Smuzhiyun if (WARN_ON(!horiz_pixels))
2539*4882a593Smuzhiyun return 0;
2540*4882a593Smuzhiyun
2541*4882a593Smuzhiyun return DIV_ROUND_UP(pri_val * 64, horiz_pixels * cpp) + 2;
2542*4882a593Smuzhiyun }
2543*4882a593Smuzhiyun
2544*4882a593Smuzhiyun struct ilk_wm_maximums {
2545*4882a593Smuzhiyun u16 pri;
2546*4882a593Smuzhiyun u16 spr;
2547*4882a593Smuzhiyun u16 cur;
2548*4882a593Smuzhiyun u16 fbc;
2549*4882a593Smuzhiyun };
2550*4882a593Smuzhiyun
2551*4882a593Smuzhiyun /*
2552*4882a593Smuzhiyun * For both WM_PIPE and WM_LP.
2553*4882a593Smuzhiyun * mem_value must be in 0.1us units.
2554*4882a593Smuzhiyun */
ilk_compute_pri_wm(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,u32 mem_value,bool is_lp)2555*4882a593Smuzhiyun static u32 ilk_compute_pri_wm(const struct intel_crtc_state *crtc_state,
2556*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
2557*4882a593Smuzhiyun u32 mem_value, bool is_lp)
2558*4882a593Smuzhiyun {
2559*4882a593Smuzhiyun u32 method1, method2;
2560*4882a593Smuzhiyun int cpp;
2561*4882a593Smuzhiyun
2562*4882a593Smuzhiyun if (mem_value == 0)
2563*4882a593Smuzhiyun return U32_MAX;
2564*4882a593Smuzhiyun
2565*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state))
2566*4882a593Smuzhiyun return 0;
2567*4882a593Smuzhiyun
2568*4882a593Smuzhiyun cpp = plane_state->hw.fb->format->cpp[0];
2569*4882a593Smuzhiyun
2570*4882a593Smuzhiyun method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value);
2571*4882a593Smuzhiyun
2572*4882a593Smuzhiyun if (!is_lp)
2573*4882a593Smuzhiyun return method1;
2574*4882a593Smuzhiyun
2575*4882a593Smuzhiyun method2 = ilk_wm_method2(crtc_state->pixel_rate,
2576*4882a593Smuzhiyun crtc_state->hw.adjusted_mode.crtc_htotal,
2577*4882a593Smuzhiyun drm_rect_width(&plane_state->uapi.dst),
2578*4882a593Smuzhiyun cpp, mem_value);
2579*4882a593Smuzhiyun
2580*4882a593Smuzhiyun return min(method1, method2);
2581*4882a593Smuzhiyun }
2582*4882a593Smuzhiyun
2583*4882a593Smuzhiyun /*
2584*4882a593Smuzhiyun * For both WM_PIPE and WM_LP.
2585*4882a593Smuzhiyun * mem_value must be in 0.1us units.
2586*4882a593Smuzhiyun */
ilk_compute_spr_wm(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,u32 mem_value)2587*4882a593Smuzhiyun static u32 ilk_compute_spr_wm(const struct intel_crtc_state *crtc_state,
2588*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
2589*4882a593Smuzhiyun u32 mem_value)
2590*4882a593Smuzhiyun {
2591*4882a593Smuzhiyun u32 method1, method2;
2592*4882a593Smuzhiyun int cpp;
2593*4882a593Smuzhiyun
2594*4882a593Smuzhiyun if (mem_value == 0)
2595*4882a593Smuzhiyun return U32_MAX;
2596*4882a593Smuzhiyun
2597*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state))
2598*4882a593Smuzhiyun return 0;
2599*4882a593Smuzhiyun
2600*4882a593Smuzhiyun cpp = plane_state->hw.fb->format->cpp[0];
2601*4882a593Smuzhiyun
2602*4882a593Smuzhiyun method1 = ilk_wm_method1(crtc_state->pixel_rate, cpp, mem_value);
2603*4882a593Smuzhiyun method2 = ilk_wm_method2(crtc_state->pixel_rate,
2604*4882a593Smuzhiyun crtc_state->hw.adjusted_mode.crtc_htotal,
2605*4882a593Smuzhiyun drm_rect_width(&plane_state->uapi.dst),
2606*4882a593Smuzhiyun cpp, mem_value);
2607*4882a593Smuzhiyun return min(method1, method2);
2608*4882a593Smuzhiyun }
2609*4882a593Smuzhiyun
2610*4882a593Smuzhiyun /*
2611*4882a593Smuzhiyun * For both WM_PIPE and WM_LP.
2612*4882a593Smuzhiyun * mem_value must be in 0.1us units.
2613*4882a593Smuzhiyun */
ilk_compute_cur_wm(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,u32 mem_value)2614*4882a593Smuzhiyun static u32 ilk_compute_cur_wm(const struct intel_crtc_state *crtc_state,
2615*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
2616*4882a593Smuzhiyun u32 mem_value)
2617*4882a593Smuzhiyun {
2618*4882a593Smuzhiyun int cpp;
2619*4882a593Smuzhiyun
2620*4882a593Smuzhiyun if (mem_value == 0)
2621*4882a593Smuzhiyun return U32_MAX;
2622*4882a593Smuzhiyun
2623*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state))
2624*4882a593Smuzhiyun return 0;
2625*4882a593Smuzhiyun
2626*4882a593Smuzhiyun cpp = plane_state->hw.fb->format->cpp[0];
2627*4882a593Smuzhiyun
2628*4882a593Smuzhiyun return ilk_wm_method2(crtc_state->pixel_rate,
2629*4882a593Smuzhiyun crtc_state->hw.adjusted_mode.crtc_htotal,
2630*4882a593Smuzhiyun drm_rect_width(&plane_state->uapi.dst),
2631*4882a593Smuzhiyun cpp, mem_value);
2632*4882a593Smuzhiyun }
2633*4882a593Smuzhiyun
2634*4882a593Smuzhiyun /* Only for WM_LP. */
ilk_compute_fbc_wm(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,u32 pri_val)2635*4882a593Smuzhiyun static u32 ilk_compute_fbc_wm(const struct intel_crtc_state *crtc_state,
2636*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
2637*4882a593Smuzhiyun u32 pri_val)
2638*4882a593Smuzhiyun {
2639*4882a593Smuzhiyun int cpp;
2640*4882a593Smuzhiyun
2641*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state))
2642*4882a593Smuzhiyun return 0;
2643*4882a593Smuzhiyun
2644*4882a593Smuzhiyun cpp = plane_state->hw.fb->format->cpp[0];
2645*4882a593Smuzhiyun
2646*4882a593Smuzhiyun return ilk_wm_fbc(pri_val, drm_rect_width(&plane_state->uapi.dst),
2647*4882a593Smuzhiyun cpp);
2648*4882a593Smuzhiyun }
2649*4882a593Smuzhiyun
2650*4882a593Smuzhiyun static unsigned int
ilk_display_fifo_size(const struct drm_i915_private * dev_priv)2651*4882a593Smuzhiyun ilk_display_fifo_size(const struct drm_i915_private *dev_priv)
2652*4882a593Smuzhiyun {
2653*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 8)
2654*4882a593Smuzhiyun return 3072;
2655*4882a593Smuzhiyun else if (INTEL_GEN(dev_priv) >= 7)
2656*4882a593Smuzhiyun return 768;
2657*4882a593Smuzhiyun else
2658*4882a593Smuzhiyun return 512;
2659*4882a593Smuzhiyun }
2660*4882a593Smuzhiyun
2661*4882a593Smuzhiyun static unsigned int
ilk_plane_wm_reg_max(const struct drm_i915_private * dev_priv,int level,bool is_sprite)2662*4882a593Smuzhiyun ilk_plane_wm_reg_max(const struct drm_i915_private *dev_priv,
2663*4882a593Smuzhiyun int level, bool is_sprite)
2664*4882a593Smuzhiyun {
2665*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 8)
2666*4882a593Smuzhiyun /* BDW primary/sprite plane watermarks */
2667*4882a593Smuzhiyun return level == 0 ? 255 : 2047;
2668*4882a593Smuzhiyun else if (INTEL_GEN(dev_priv) >= 7)
2669*4882a593Smuzhiyun /* IVB/HSW primary/sprite plane watermarks */
2670*4882a593Smuzhiyun return level == 0 ? 127 : 1023;
2671*4882a593Smuzhiyun else if (!is_sprite)
2672*4882a593Smuzhiyun /* ILK/SNB primary plane watermarks */
2673*4882a593Smuzhiyun return level == 0 ? 127 : 511;
2674*4882a593Smuzhiyun else
2675*4882a593Smuzhiyun /* ILK/SNB sprite plane watermarks */
2676*4882a593Smuzhiyun return level == 0 ? 63 : 255;
2677*4882a593Smuzhiyun }
2678*4882a593Smuzhiyun
2679*4882a593Smuzhiyun static unsigned int
ilk_cursor_wm_reg_max(const struct drm_i915_private * dev_priv,int level)2680*4882a593Smuzhiyun ilk_cursor_wm_reg_max(const struct drm_i915_private *dev_priv, int level)
2681*4882a593Smuzhiyun {
2682*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 7)
2683*4882a593Smuzhiyun return level == 0 ? 63 : 255;
2684*4882a593Smuzhiyun else
2685*4882a593Smuzhiyun return level == 0 ? 31 : 63;
2686*4882a593Smuzhiyun }
2687*4882a593Smuzhiyun
ilk_fbc_wm_reg_max(const struct drm_i915_private * dev_priv)2688*4882a593Smuzhiyun static unsigned int ilk_fbc_wm_reg_max(const struct drm_i915_private *dev_priv)
2689*4882a593Smuzhiyun {
2690*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 8)
2691*4882a593Smuzhiyun return 31;
2692*4882a593Smuzhiyun else
2693*4882a593Smuzhiyun return 15;
2694*4882a593Smuzhiyun }
2695*4882a593Smuzhiyun
2696*4882a593Smuzhiyun /* Calculate the maximum primary/sprite plane watermark */
ilk_plane_wm_max(const struct drm_i915_private * dev_priv,int level,const struct intel_wm_config * config,enum intel_ddb_partitioning ddb_partitioning,bool is_sprite)2697*4882a593Smuzhiyun static unsigned int ilk_plane_wm_max(const struct drm_i915_private *dev_priv,
2698*4882a593Smuzhiyun int level,
2699*4882a593Smuzhiyun const struct intel_wm_config *config,
2700*4882a593Smuzhiyun enum intel_ddb_partitioning ddb_partitioning,
2701*4882a593Smuzhiyun bool is_sprite)
2702*4882a593Smuzhiyun {
2703*4882a593Smuzhiyun unsigned int fifo_size = ilk_display_fifo_size(dev_priv);
2704*4882a593Smuzhiyun
2705*4882a593Smuzhiyun /* if sprites aren't enabled, sprites get nothing */
2706*4882a593Smuzhiyun if (is_sprite && !config->sprites_enabled)
2707*4882a593Smuzhiyun return 0;
2708*4882a593Smuzhiyun
2709*4882a593Smuzhiyun /* HSW allows LP1+ watermarks even with multiple pipes */
2710*4882a593Smuzhiyun if (level == 0 || config->num_pipes_active > 1) {
2711*4882a593Smuzhiyun fifo_size /= INTEL_NUM_PIPES(dev_priv);
2712*4882a593Smuzhiyun
2713*4882a593Smuzhiyun /*
2714*4882a593Smuzhiyun * For some reason the non self refresh
2715*4882a593Smuzhiyun * FIFO size is only half of the self
2716*4882a593Smuzhiyun * refresh FIFO size on ILK/SNB.
2717*4882a593Smuzhiyun */
2718*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) <= 6)
2719*4882a593Smuzhiyun fifo_size /= 2;
2720*4882a593Smuzhiyun }
2721*4882a593Smuzhiyun
2722*4882a593Smuzhiyun if (config->sprites_enabled) {
2723*4882a593Smuzhiyun /* level 0 is always calculated with 1:1 split */
2724*4882a593Smuzhiyun if (level > 0 && ddb_partitioning == INTEL_DDB_PART_5_6) {
2725*4882a593Smuzhiyun if (is_sprite)
2726*4882a593Smuzhiyun fifo_size *= 5;
2727*4882a593Smuzhiyun fifo_size /= 6;
2728*4882a593Smuzhiyun } else {
2729*4882a593Smuzhiyun fifo_size /= 2;
2730*4882a593Smuzhiyun }
2731*4882a593Smuzhiyun }
2732*4882a593Smuzhiyun
2733*4882a593Smuzhiyun /* clamp to max that the registers can hold */
2734*4882a593Smuzhiyun return min(fifo_size, ilk_plane_wm_reg_max(dev_priv, level, is_sprite));
2735*4882a593Smuzhiyun }
2736*4882a593Smuzhiyun
2737*4882a593Smuzhiyun /* Calculate the maximum cursor plane watermark */
ilk_cursor_wm_max(const struct drm_i915_private * dev_priv,int level,const struct intel_wm_config * config)2738*4882a593Smuzhiyun static unsigned int ilk_cursor_wm_max(const struct drm_i915_private *dev_priv,
2739*4882a593Smuzhiyun int level,
2740*4882a593Smuzhiyun const struct intel_wm_config *config)
2741*4882a593Smuzhiyun {
2742*4882a593Smuzhiyun /* HSW LP1+ watermarks w/ multiple pipes */
2743*4882a593Smuzhiyun if (level > 0 && config->num_pipes_active > 1)
2744*4882a593Smuzhiyun return 64;
2745*4882a593Smuzhiyun
2746*4882a593Smuzhiyun /* otherwise just report max that registers can hold */
2747*4882a593Smuzhiyun return ilk_cursor_wm_reg_max(dev_priv, level);
2748*4882a593Smuzhiyun }
2749*4882a593Smuzhiyun
ilk_compute_wm_maximums(const struct drm_i915_private * dev_priv,int level,const struct intel_wm_config * config,enum intel_ddb_partitioning ddb_partitioning,struct ilk_wm_maximums * max)2750*4882a593Smuzhiyun static void ilk_compute_wm_maximums(const struct drm_i915_private *dev_priv,
2751*4882a593Smuzhiyun int level,
2752*4882a593Smuzhiyun const struct intel_wm_config *config,
2753*4882a593Smuzhiyun enum intel_ddb_partitioning ddb_partitioning,
2754*4882a593Smuzhiyun struct ilk_wm_maximums *max)
2755*4882a593Smuzhiyun {
2756*4882a593Smuzhiyun max->pri = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, false);
2757*4882a593Smuzhiyun max->spr = ilk_plane_wm_max(dev_priv, level, config, ddb_partitioning, true);
2758*4882a593Smuzhiyun max->cur = ilk_cursor_wm_max(dev_priv, level, config);
2759*4882a593Smuzhiyun max->fbc = ilk_fbc_wm_reg_max(dev_priv);
2760*4882a593Smuzhiyun }
2761*4882a593Smuzhiyun
ilk_compute_wm_reg_maximums(const struct drm_i915_private * dev_priv,int level,struct ilk_wm_maximums * max)2762*4882a593Smuzhiyun static void ilk_compute_wm_reg_maximums(const struct drm_i915_private *dev_priv,
2763*4882a593Smuzhiyun int level,
2764*4882a593Smuzhiyun struct ilk_wm_maximums *max)
2765*4882a593Smuzhiyun {
2766*4882a593Smuzhiyun max->pri = ilk_plane_wm_reg_max(dev_priv, level, false);
2767*4882a593Smuzhiyun max->spr = ilk_plane_wm_reg_max(dev_priv, level, true);
2768*4882a593Smuzhiyun max->cur = ilk_cursor_wm_reg_max(dev_priv, level);
2769*4882a593Smuzhiyun max->fbc = ilk_fbc_wm_reg_max(dev_priv);
2770*4882a593Smuzhiyun }
2771*4882a593Smuzhiyun
ilk_validate_wm_level(int level,const struct ilk_wm_maximums * max,struct intel_wm_level * result)2772*4882a593Smuzhiyun static bool ilk_validate_wm_level(int level,
2773*4882a593Smuzhiyun const struct ilk_wm_maximums *max,
2774*4882a593Smuzhiyun struct intel_wm_level *result)
2775*4882a593Smuzhiyun {
2776*4882a593Smuzhiyun bool ret;
2777*4882a593Smuzhiyun
2778*4882a593Smuzhiyun /* already determined to be invalid? */
2779*4882a593Smuzhiyun if (!result->enable)
2780*4882a593Smuzhiyun return false;
2781*4882a593Smuzhiyun
2782*4882a593Smuzhiyun result->enable = result->pri_val <= max->pri &&
2783*4882a593Smuzhiyun result->spr_val <= max->spr &&
2784*4882a593Smuzhiyun result->cur_val <= max->cur;
2785*4882a593Smuzhiyun
2786*4882a593Smuzhiyun ret = result->enable;
2787*4882a593Smuzhiyun
2788*4882a593Smuzhiyun /*
2789*4882a593Smuzhiyun * HACK until we can pre-compute everything,
2790*4882a593Smuzhiyun * and thus fail gracefully if LP0 watermarks
2791*4882a593Smuzhiyun * are exceeded...
2792*4882a593Smuzhiyun */
2793*4882a593Smuzhiyun if (level == 0 && !result->enable) {
2794*4882a593Smuzhiyun if (result->pri_val > max->pri)
2795*4882a593Smuzhiyun DRM_DEBUG_KMS("Primary WM%d too large %u (max %u)\n",
2796*4882a593Smuzhiyun level, result->pri_val, max->pri);
2797*4882a593Smuzhiyun if (result->spr_val > max->spr)
2798*4882a593Smuzhiyun DRM_DEBUG_KMS("Sprite WM%d too large %u (max %u)\n",
2799*4882a593Smuzhiyun level, result->spr_val, max->spr);
2800*4882a593Smuzhiyun if (result->cur_val > max->cur)
2801*4882a593Smuzhiyun DRM_DEBUG_KMS("Cursor WM%d too large %u (max %u)\n",
2802*4882a593Smuzhiyun level, result->cur_val, max->cur);
2803*4882a593Smuzhiyun
2804*4882a593Smuzhiyun result->pri_val = min_t(u32, result->pri_val, max->pri);
2805*4882a593Smuzhiyun result->spr_val = min_t(u32, result->spr_val, max->spr);
2806*4882a593Smuzhiyun result->cur_val = min_t(u32, result->cur_val, max->cur);
2807*4882a593Smuzhiyun result->enable = true;
2808*4882a593Smuzhiyun }
2809*4882a593Smuzhiyun
2810*4882a593Smuzhiyun return ret;
2811*4882a593Smuzhiyun }
2812*4882a593Smuzhiyun
ilk_compute_wm_level(const struct drm_i915_private * dev_priv,const struct intel_crtc * crtc,int level,struct intel_crtc_state * crtc_state,const struct intel_plane_state * pristate,const struct intel_plane_state * sprstate,const struct intel_plane_state * curstate,struct intel_wm_level * result)2813*4882a593Smuzhiyun static void ilk_compute_wm_level(const struct drm_i915_private *dev_priv,
2814*4882a593Smuzhiyun const struct intel_crtc *crtc,
2815*4882a593Smuzhiyun int level,
2816*4882a593Smuzhiyun struct intel_crtc_state *crtc_state,
2817*4882a593Smuzhiyun const struct intel_plane_state *pristate,
2818*4882a593Smuzhiyun const struct intel_plane_state *sprstate,
2819*4882a593Smuzhiyun const struct intel_plane_state *curstate,
2820*4882a593Smuzhiyun struct intel_wm_level *result)
2821*4882a593Smuzhiyun {
2822*4882a593Smuzhiyun u16 pri_latency = dev_priv->wm.pri_latency[level];
2823*4882a593Smuzhiyun u16 spr_latency = dev_priv->wm.spr_latency[level];
2824*4882a593Smuzhiyun u16 cur_latency = dev_priv->wm.cur_latency[level];
2825*4882a593Smuzhiyun
2826*4882a593Smuzhiyun /* WM1+ latency values stored in 0.5us units */
2827*4882a593Smuzhiyun if (level > 0) {
2828*4882a593Smuzhiyun pri_latency *= 5;
2829*4882a593Smuzhiyun spr_latency *= 5;
2830*4882a593Smuzhiyun cur_latency *= 5;
2831*4882a593Smuzhiyun }
2832*4882a593Smuzhiyun
2833*4882a593Smuzhiyun if (pristate) {
2834*4882a593Smuzhiyun result->pri_val = ilk_compute_pri_wm(crtc_state, pristate,
2835*4882a593Smuzhiyun pri_latency, level);
2836*4882a593Smuzhiyun result->fbc_val = ilk_compute_fbc_wm(crtc_state, pristate, result->pri_val);
2837*4882a593Smuzhiyun }
2838*4882a593Smuzhiyun
2839*4882a593Smuzhiyun if (sprstate)
2840*4882a593Smuzhiyun result->spr_val = ilk_compute_spr_wm(crtc_state, sprstate, spr_latency);
2841*4882a593Smuzhiyun
2842*4882a593Smuzhiyun if (curstate)
2843*4882a593Smuzhiyun result->cur_val = ilk_compute_cur_wm(crtc_state, curstate, cur_latency);
2844*4882a593Smuzhiyun
2845*4882a593Smuzhiyun result->enable = true;
2846*4882a593Smuzhiyun }
2847*4882a593Smuzhiyun
intel_read_wm_latency(struct drm_i915_private * dev_priv,u16 wm[])2848*4882a593Smuzhiyun static void intel_read_wm_latency(struct drm_i915_private *dev_priv,
2849*4882a593Smuzhiyun u16 wm[])
2850*4882a593Smuzhiyun {
2851*4882a593Smuzhiyun struct intel_uncore *uncore = &dev_priv->uncore;
2852*4882a593Smuzhiyun
2853*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 9) {
2854*4882a593Smuzhiyun u32 val;
2855*4882a593Smuzhiyun int ret, i;
2856*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
2857*4882a593Smuzhiyun
2858*4882a593Smuzhiyun /* read the first set of memory latencies[0:3] */
2859*4882a593Smuzhiyun val = 0; /* data0 to be programmed to 0 for first set */
2860*4882a593Smuzhiyun ret = sandybridge_pcode_read(dev_priv,
2861*4882a593Smuzhiyun GEN9_PCODE_READ_MEM_LATENCY,
2862*4882a593Smuzhiyun &val, NULL);
2863*4882a593Smuzhiyun
2864*4882a593Smuzhiyun if (ret) {
2865*4882a593Smuzhiyun drm_err(&dev_priv->drm,
2866*4882a593Smuzhiyun "SKL Mailbox read error = %d\n", ret);
2867*4882a593Smuzhiyun return;
2868*4882a593Smuzhiyun }
2869*4882a593Smuzhiyun
2870*4882a593Smuzhiyun wm[0] = val & GEN9_MEM_LATENCY_LEVEL_MASK;
2871*4882a593Smuzhiyun wm[1] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
2872*4882a593Smuzhiyun GEN9_MEM_LATENCY_LEVEL_MASK;
2873*4882a593Smuzhiyun wm[2] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
2874*4882a593Smuzhiyun GEN9_MEM_LATENCY_LEVEL_MASK;
2875*4882a593Smuzhiyun wm[3] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
2876*4882a593Smuzhiyun GEN9_MEM_LATENCY_LEVEL_MASK;
2877*4882a593Smuzhiyun
2878*4882a593Smuzhiyun /* read the second set of memory latencies[4:7] */
2879*4882a593Smuzhiyun val = 1; /* data0 to be programmed to 1 for second set */
2880*4882a593Smuzhiyun ret = sandybridge_pcode_read(dev_priv,
2881*4882a593Smuzhiyun GEN9_PCODE_READ_MEM_LATENCY,
2882*4882a593Smuzhiyun &val, NULL);
2883*4882a593Smuzhiyun if (ret) {
2884*4882a593Smuzhiyun drm_err(&dev_priv->drm,
2885*4882a593Smuzhiyun "SKL Mailbox read error = %d\n", ret);
2886*4882a593Smuzhiyun return;
2887*4882a593Smuzhiyun }
2888*4882a593Smuzhiyun
2889*4882a593Smuzhiyun wm[4] = val & GEN9_MEM_LATENCY_LEVEL_MASK;
2890*4882a593Smuzhiyun wm[5] = (val >> GEN9_MEM_LATENCY_LEVEL_1_5_SHIFT) &
2891*4882a593Smuzhiyun GEN9_MEM_LATENCY_LEVEL_MASK;
2892*4882a593Smuzhiyun wm[6] = (val >> GEN9_MEM_LATENCY_LEVEL_2_6_SHIFT) &
2893*4882a593Smuzhiyun GEN9_MEM_LATENCY_LEVEL_MASK;
2894*4882a593Smuzhiyun wm[7] = (val >> GEN9_MEM_LATENCY_LEVEL_3_7_SHIFT) &
2895*4882a593Smuzhiyun GEN9_MEM_LATENCY_LEVEL_MASK;
2896*4882a593Smuzhiyun
2897*4882a593Smuzhiyun /*
2898*4882a593Smuzhiyun * If a level n (n > 1) has a 0us latency, all levels m (m >= n)
2899*4882a593Smuzhiyun * need to be disabled. We make sure to sanitize the values out
2900*4882a593Smuzhiyun * of the punit to satisfy this requirement.
2901*4882a593Smuzhiyun */
2902*4882a593Smuzhiyun for (level = 1; level <= max_level; level++) {
2903*4882a593Smuzhiyun if (wm[level] == 0) {
2904*4882a593Smuzhiyun for (i = level + 1; i <= max_level; i++)
2905*4882a593Smuzhiyun wm[i] = 0;
2906*4882a593Smuzhiyun break;
2907*4882a593Smuzhiyun }
2908*4882a593Smuzhiyun }
2909*4882a593Smuzhiyun
2910*4882a593Smuzhiyun /*
2911*4882a593Smuzhiyun * WaWmMemoryReadLatency:skl+,glk
2912*4882a593Smuzhiyun *
2913*4882a593Smuzhiyun * punit doesn't take into account the read latency so we need
2914*4882a593Smuzhiyun * to add 2us to the various latency levels we retrieve from the
2915*4882a593Smuzhiyun * punit when level 0 response data us 0us.
2916*4882a593Smuzhiyun */
2917*4882a593Smuzhiyun if (wm[0] == 0) {
2918*4882a593Smuzhiyun wm[0] += 2;
2919*4882a593Smuzhiyun for (level = 1; level <= max_level; level++) {
2920*4882a593Smuzhiyun if (wm[level] == 0)
2921*4882a593Smuzhiyun break;
2922*4882a593Smuzhiyun wm[level] += 2;
2923*4882a593Smuzhiyun }
2924*4882a593Smuzhiyun }
2925*4882a593Smuzhiyun
2926*4882a593Smuzhiyun /*
2927*4882a593Smuzhiyun * WA Level-0 adjustment for 16GB DIMMs: SKL+
2928*4882a593Smuzhiyun * If we could not get dimm info enable this WA to prevent from
2929*4882a593Smuzhiyun * any underrun. If not able to get Dimm info assume 16GB dimm
2930*4882a593Smuzhiyun * to avoid any underrun.
2931*4882a593Smuzhiyun */
2932*4882a593Smuzhiyun if (dev_priv->dram_info.is_16gb_dimm)
2933*4882a593Smuzhiyun wm[0] += 1;
2934*4882a593Smuzhiyun
2935*4882a593Smuzhiyun } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
2936*4882a593Smuzhiyun u64 sskpd = intel_uncore_read64(uncore, MCH_SSKPD);
2937*4882a593Smuzhiyun
2938*4882a593Smuzhiyun wm[0] = (sskpd >> 56) & 0xFF;
2939*4882a593Smuzhiyun if (wm[0] == 0)
2940*4882a593Smuzhiyun wm[0] = sskpd & 0xF;
2941*4882a593Smuzhiyun wm[1] = (sskpd >> 4) & 0xFF;
2942*4882a593Smuzhiyun wm[2] = (sskpd >> 12) & 0xFF;
2943*4882a593Smuzhiyun wm[3] = (sskpd >> 20) & 0x1FF;
2944*4882a593Smuzhiyun wm[4] = (sskpd >> 32) & 0x1FF;
2945*4882a593Smuzhiyun } else if (INTEL_GEN(dev_priv) >= 6) {
2946*4882a593Smuzhiyun u32 sskpd = intel_uncore_read(uncore, MCH_SSKPD);
2947*4882a593Smuzhiyun
2948*4882a593Smuzhiyun wm[0] = (sskpd >> SSKPD_WM0_SHIFT) & SSKPD_WM_MASK;
2949*4882a593Smuzhiyun wm[1] = (sskpd >> SSKPD_WM1_SHIFT) & SSKPD_WM_MASK;
2950*4882a593Smuzhiyun wm[2] = (sskpd >> SSKPD_WM2_SHIFT) & SSKPD_WM_MASK;
2951*4882a593Smuzhiyun wm[3] = (sskpd >> SSKPD_WM3_SHIFT) & SSKPD_WM_MASK;
2952*4882a593Smuzhiyun } else if (INTEL_GEN(dev_priv) >= 5) {
2953*4882a593Smuzhiyun u32 mltr = intel_uncore_read(uncore, MLTR_ILK);
2954*4882a593Smuzhiyun
2955*4882a593Smuzhiyun /* ILK primary LP0 latency is 700 ns */
2956*4882a593Smuzhiyun wm[0] = 7;
2957*4882a593Smuzhiyun wm[1] = (mltr >> MLTR_WM1_SHIFT) & ILK_SRLT_MASK;
2958*4882a593Smuzhiyun wm[2] = (mltr >> MLTR_WM2_SHIFT) & ILK_SRLT_MASK;
2959*4882a593Smuzhiyun } else {
2960*4882a593Smuzhiyun MISSING_CASE(INTEL_DEVID(dev_priv));
2961*4882a593Smuzhiyun }
2962*4882a593Smuzhiyun }
2963*4882a593Smuzhiyun
intel_fixup_spr_wm_latency(struct drm_i915_private * dev_priv,u16 wm[5])2964*4882a593Smuzhiyun static void intel_fixup_spr_wm_latency(struct drm_i915_private *dev_priv,
2965*4882a593Smuzhiyun u16 wm[5])
2966*4882a593Smuzhiyun {
2967*4882a593Smuzhiyun /* ILK sprite LP0 latency is 1300 ns */
2968*4882a593Smuzhiyun if (IS_GEN(dev_priv, 5))
2969*4882a593Smuzhiyun wm[0] = 13;
2970*4882a593Smuzhiyun }
2971*4882a593Smuzhiyun
intel_fixup_cur_wm_latency(struct drm_i915_private * dev_priv,u16 wm[5])2972*4882a593Smuzhiyun static void intel_fixup_cur_wm_latency(struct drm_i915_private *dev_priv,
2973*4882a593Smuzhiyun u16 wm[5])
2974*4882a593Smuzhiyun {
2975*4882a593Smuzhiyun /* ILK cursor LP0 latency is 1300 ns */
2976*4882a593Smuzhiyun if (IS_GEN(dev_priv, 5))
2977*4882a593Smuzhiyun wm[0] = 13;
2978*4882a593Smuzhiyun }
2979*4882a593Smuzhiyun
ilk_wm_max_level(const struct drm_i915_private * dev_priv)2980*4882a593Smuzhiyun int ilk_wm_max_level(const struct drm_i915_private *dev_priv)
2981*4882a593Smuzhiyun {
2982*4882a593Smuzhiyun /* how many WM levels are we expecting */
2983*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 9)
2984*4882a593Smuzhiyun return 7;
2985*4882a593Smuzhiyun else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
2986*4882a593Smuzhiyun return 4;
2987*4882a593Smuzhiyun else if (INTEL_GEN(dev_priv) >= 6)
2988*4882a593Smuzhiyun return 3;
2989*4882a593Smuzhiyun else
2990*4882a593Smuzhiyun return 2;
2991*4882a593Smuzhiyun }
2992*4882a593Smuzhiyun
intel_print_wm_latency(struct drm_i915_private * dev_priv,const char * name,const u16 wm[])2993*4882a593Smuzhiyun static void intel_print_wm_latency(struct drm_i915_private *dev_priv,
2994*4882a593Smuzhiyun const char *name,
2995*4882a593Smuzhiyun const u16 wm[])
2996*4882a593Smuzhiyun {
2997*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
2998*4882a593Smuzhiyun
2999*4882a593Smuzhiyun for (level = 0; level <= max_level; level++) {
3000*4882a593Smuzhiyun unsigned int latency = wm[level];
3001*4882a593Smuzhiyun
3002*4882a593Smuzhiyun if (latency == 0) {
3003*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
3004*4882a593Smuzhiyun "%s WM%d latency not provided\n",
3005*4882a593Smuzhiyun name, level);
3006*4882a593Smuzhiyun continue;
3007*4882a593Smuzhiyun }
3008*4882a593Smuzhiyun
3009*4882a593Smuzhiyun /*
3010*4882a593Smuzhiyun * - latencies are in us on gen9.
3011*4882a593Smuzhiyun * - before then, WM1+ latency values are in 0.5us units
3012*4882a593Smuzhiyun */
3013*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 9)
3014*4882a593Smuzhiyun latency *= 10;
3015*4882a593Smuzhiyun else if (level > 0)
3016*4882a593Smuzhiyun latency *= 5;
3017*4882a593Smuzhiyun
3018*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
3019*4882a593Smuzhiyun "%s WM%d latency %u (%u.%u usec)\n", name, level,
3020*4882a593Smuzhiyun wm[level], latency / 10, latency % 10);
3021*4882a593Smuzhiyun }
3022*4882a593Smuzhiyun }
3023*4882a593Smuzhiyun
ilk_increase_wm_latency(struct drm_i915_private * dev_priv,u16 wm[5],u16 min)3024*4882a593Smuzhiyun static bool ilk_increase_wm_latency(struct drm_i915_private *dev_priv,
3025*4882a593Smuzhiyun u16 wm[5], u16 min)
3026*4882a593Smuzhiyun {
3027*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
3028*4882a593Smuzhiyun
3029*4882a593Smuzhiyun if (wm[0] >= min)
3030*4882a593Smuzhiyun return false;
3031*4882a593Smuzhiyun
3032*4882a593Smuzhiyun wm[0] = max(wm[0], min);
3033*4882a593Smuzhiyun for (level = 1; level <= max_level; level++)
3034*4882a593Smuzhiyun wm[level] = max_t(u16, wm[level], DIV_ROUND_UP(min, 5));
3035*4882a593Smuzhiyun
3036*4882a593Smuzhiyun return true;
3037*4882a593Smuzhiyun }
3038*4882a593Smuzhiyun
snb_wm_latency_quirk(struct drm_i915_private * dev_priv)3039*4882a593Smuzhiyun static void snb_wm_latency_quirk(struct drm_i915_private *dev_priv)
3040*4882a593Smuzhiyun {
3041*4882a593Smuzhiyun bool changed;
3042*4882a593Smuzhiyun
3043*4882a593Smuzhiyun /*
3044*4882a593Smuzhiyun * The BIOS provided WM memory latency values are often
3045*4882a593Smuzhiyun * inadequate for high resolution displays. Adjust them.
3046*4882a593Smuzhiyun */
3047*4882a593Smuzhiyun changed = ilk_increase_wm_latency(dev_priv, dev_priv->wm.pri_latency, 12);
3048*4882a593Smuzhiyun changed |= ilk_increase_wm_latency(dev_priv, dev_priv->wm.spr_latency, 12);
3049*4882a593Smuzhiyun changed |= ilk_increase_wm_latency(dev_priv, dev_priv->wm.cur_latency, 12);
3050*4882a593Smuzhiyun
3051*4882a593Smuzhiyun if (!changed)
3052*4882a593Smuzhiyun return;
3053*4882a593Smuzhiyun
3054*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
3055*4882a593Smuzhiyun "WM latency values increased to avoid potential underruns\n");
3056*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
3057*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
3058*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
3059*4882a593Smuzhiyun }
3060*4882a593Smuzhiyun
snb_wm_lp3_irq_quirk(struct drm_i915_private * dev_priv)3061*4882a593Smuzhiyun static void snb_wm_lp3_irq_quirk(struct drm_i915_private *dev_priv)
3062*4882a593Smuzhiyun {
3063*4882a593Smuzhiyun /*
3064*4882a593Smuzhiyun * On some SNB machines (Thinkpad X220 Tablet at least)
3065*4882a593Smuzhiyun * LP3 usage can cause vblank interrupts to be lost.
3066*4882a593Smuzhiyun * The DEIIR bit will go high but it looks like the CPU
3067*4882a593Smuzhiyun * never gets interrupted.
3068*4882a593Smuzhiyun *
3069*4882a593Smuzhiyun * It's not clear whether other interrupt source could
3070*4882a593Smuzhiyun * be affected or if this is somehow limited to vblank
3071*4882a593Smuzhiyun * interrupts only. To play it safe we disable LP3
3072*4882a593Smuzhiyun * watermarks entirely.
3073*4882a593Smuzhiyun */
3074*4882a593Smuzhiyun if (dev_priv->wm.pri_latency[3] == 0 &&
3075*4882a593Smuzhiyun dev_priv->wm.spr_latency[3] == 0 &&
3076*4882a593Smuzhiyun dev_priv->wm.cur_latency[3] == 0)
3077*4882a593Smuzhiyun return;
3078*4882a593Smuzhiyun
3079*4882a593Smuzhiyun dev_priv->wm.pri_latency[3] = 0;
3080*4882a593Smuzhiyun dev_priv->wm.spr_latency[3] = 0;
3081*4882a593Smuzhiyun dev_priv->wm.cur_latency[3] = 0;
3082*4882a593Smuzhiyun
3083*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
3084*4882a593Smuzhiyun "LP3 watermarks disabled due to potential for lost interrupts\n");
3085*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
3086*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
3087*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
3088*4882a593Smuzhiyun }
3089*4882a593Smuzhiyun
ilk_setup_wm_latency(struct drm_i915_private * dev_priv)3090*4882a593Smuzhiyun static void ilk_setup_wm_latency(struct drm_i915_private *dev_priv)
3091*4882a593Smuzhiyun {
3092*4882a593Smuzhiyun intel_read_wm_latency(dev_priv, dev_priv->wm.pri_latency);
3093*4882a593Smuzhiyun
3094*4882a593Smuzhiyun memcpy(dev_priv->wm.spr_latency, dev_priv->wm.pri_latency,
3095*4882a593Smuzhiyun sizeof(dev_priv->wm.pri_latency));
3096*4882a593Smuzhiyun memcpy(dev_priv->wm.cur_latency, dev_priv->wm.pri_latency,
3097*4882a593Smuzhiyun sizeof(dev_priv->wm.pri_latency));
3098*4882a593Smuzhiyun
3099*4882a593Smuzhiyun intel_fixup_spr_wm_latency(dev_priv, dev_priv->wm.spr_latency);
3100*4882a593Smuzhiyun intel_fixup_cur_wm_latency(dev_priv, dev_priv->wm.cur_latency);
3101*4882a593Smuzhiyun
3102*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Primary", dev_priv->wm.pri_latency);
3103*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Sprite", dev_priv->wm.spr_latency);
3104*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Cursor", dev_priv->wm.cur_latency);
3105*4882a593Smuzhiyun
3106*4882a593Smuzhiyun if (IS_GEN(dev_priv, 6)) {
3107*4882a593Smuzhiyun snb_wm_latency_quirk(dev_priv);
3108*4882a593Smuzhiyun snb_wm_lp3_irq_quirk(dev_priv);
3109*4882a593Smuzhiyun }
3110*4882a593Smuzhiyun }
3111*4882a593Smuzhiyun
skl_setup_wm_latency(struct drm_i915_private * dev_priv)3112*4882a593Smuzhiyun static void skl_setup_wm_latency(struct drm_i915_private *dev_priv)
3113*4882a593Smuzhiyun {
3114*4882a593Smuzhiyun intel_read_wm_latency(dev_priv, dev_priv->wm.skl_latency);
3115*4882a593Smuzhiyun intel_print_wm_latency(dev_priv, "Gen9 Plane", dev_priv->wm.skl_latency);
3116*4882a593Smuzhiyun }
3117*4882a593Smuzhiyun
ilk_validate_pipe_wm(const struct drm_i915_private * dev_priv,struct intel_pipe_wm * pipe_wm)3118*4882a593Smuzhiyun static bool ilk_validate_pipe_wm(const struct drm_i915_private *dev_priv,
3119*4882a593Smuzhiyun struct intel_pipe_wm *pipe_wm)
3120*4882a593Smuzhiyun {
3121*4882a593Smuzhiyun /* LP0 watermark maximums depend on this pipe alone */
3122*4882a593Smuzhiyun const struct intel_wm_config config = {
3123*4882a593Smuzhiyun .num_pipes_active = 1,
3124*4882a593Smuzhiyun .sprites_enabled = pipe_wm->sprites_enabled,
3125*4882a593Smuzhiyun .sprites_scaled = pipe_wm->sprites_scaled,
3126*4882a593Smuzhiyun };
3127*4882a593Smuzhiyun struct ilk_wm_maximums max;
3128*4882a593Smuzhiyun
3129*4882a593Smuzhiyun /* LP0 watermarks always use 1/2 DDB partitioning */
3130*4882a593Smuzhiyun ilk_compute_wm_maximums(dev_priv, 0, &config, INTEL_DDB_PART_1_2, &max);
3131*4882a593Smuzhiyun
3132*4882a593Smuzhiyun /* At least LP0 must be valid */
3133*4882a593Smuzhiyun if (!ilk_validate_wm_level(0, &max, &pipe_wm->wm[0])) {
3134*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "LP0 watermark invalid\n");
3135*4882a593Smuzhiyun return false;
3136*4882a593Smuzhiyun }
3137*4882a593Smuzhiyun
3138*4882a593Smuzhiyun return true;
3139*4882a593Smuzhiyun }
3140*4882a593Smuzhiyun
3141*4882a593Smuzhiyun /* Compute new watermarks for the pipe */
ilk_compute_pipe_wm(struct intel_crtc_state * crtc_state)3142*4882a593Smuzhiyun static int ilk_compute_pipe_wm(struct intel_crtc_state *crtc_state)
3143*4882a593Smuzhiyun {
3144*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
3145*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3146*4882a593Smuzhiyun struct intel_pipe_wm *pipe_wm;
3147*4882a593Smuzhiyun struct intel_plane *plane;
3148*4882a593Smuzhiyun const struct intel_plane_state *plane_state;
3149*4882a593Smuzhiyun const struct intel_plane_state *pristate = NULL;
3150*4882a593Smuzhiyun const struct intel_plane_state *sprstate = NULL;
3151*4882a593Smuzhiyun const struct intel_plane_state *curstate = NULL;
3152*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv), usable_level;
3153*4882a593Smuzhiyun struct ilk_wm_maximums max;
3154*4882a593Smuzhiyun
3155*4882a593Smuzhiyun pipe_wm = &crtc_state->wm.ilk.optimal;
3156*4882a593Smuzhiyun
3157*4882a593Smuzhiyun intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
3158*4882a593Smuzhiyun if (plane->base.type == DRM_PLANE_TYPE_PRIMARY)
3159*4882a593Smuzhiyun pristate = plane_state;
3160*4882a593Smuzhiyun else if (plane->base.type == DRM_PLANE_TYPE_OVERLAY)
3161*4882a593Smuzhiyun sprstate = plane_state;
3162*4882a593Smuzhiyun else if (plane->base.type == DRM_PLANE_TYPE_CURSOR)
3163*4882a593Smuzhiyun curstate = plane_state;
3164*4882a593Smuzhiyun }
3165*4882a593Smuzhiyun
3166*4882a593Smuzhiyun pipe_wm->pipe_enabled = crtc_state->hw.active;
3167*4882a593Smuzhiyun if (sprstate) {
3168*4882a593Smuzhiyun pipe_wm->sprites_enabled = sprstate->uapi.visible;
3169*4882a593Smuzhiyun pipe_wm->sprites_scaled = sprstate->uapi.visible &&
3170*4882a593Smuzhiyun (drm_rect_width(&sprstate->uapi.dst) != drm_rect_width(&sprstate->uapi.src) >> 16 ||
3171*4882a593Smuzhiyun drm_rect_height(&sprstate->uapi.dst) != drm_rect_height(&sprstate->uapi.src) >> 16);
3172*4882a593Smuzhiyun }
3173*4882a593Smuzhiyun
3174*4882a593Smuzhiyun usable_level = max_level;
3175*4882a593Smuzhiyun
3176*4882a593Smuzhiyun /* ILK/SNB: LP2+ watermarks only w/o sprites */
3177*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) <= 6 && pipe_wm->sprites_enabled)
3178*4882a593Smuzhiyun usable_level = 1;
3179*4882a593Smuzhiyun
3180*4882a593Smuzhiyun /* ILK/SNB/IVB: LP1+ watermarks only w/o scaling */
3181*4882a593Smuzhiyun if (pipe_wm->sprites_scaled)
3182*4882a593Smuzhiyun usable_level = 0;
3183*4882a593Smuzhiyun
3184*4882a593Smuzhiyun memset(&pipe_wm->wm, 0, sizeof(pipe_wm->wm));
3185*4882a593Smuzhiyun ilk_compute_wm_level(dev_priv, crtc, 0, crtc_state,
3186*4882a593Smuzhiyun pristate, sprstate, curstate, &pipe_wm->wm[0]);
3187*4882a593Smuzhiyun
3188*4882a593Smuzhiyun if (!ilk_validate_pipe_wm(dev_priv, pipe_wm))
3189*4882a593Smuzhiyun return -EINVAL;
3190*4882a593Smuzhiyun
3191*4882a593Smuzhiyun ilk_compute_wm_reg_maximums(dev_priv, 1, &max);
3192*4882a593Smuzhiyun
3193*4882a593Smuzhiyun for (level = 1; level <= usable_level; level++) {
3194*4882a593Smuzhiyun struct intel_wm_level *wm = &pipe_wm->wm[level];
3195*4882a593Smuzhiyun
3196*4882a593Smuzhiyun ilk_compute_wm_level(dev_priv, crtc, level, crtc_state,
3197*4882a593Smuzhiyun pristate, sprstate, curstate, wm);
3198*4882a593Smuzhiyun
3199*4882a593Smuzhiyun /*
3200*4882a593Smuzhiyun * Disable any watermark level that exceeds the
3201*4882a593Smuzhiyun * register maximums since such watermarks are
3202*4882a593Smuzhiyun * always invalid.
3203*4882a593Smuzhiyun */
3204*4882a593Smuzhiyun if (!ilk_validate_wm_level(level, &max, wm)) {
3205*4882a593Smuzhiyun memset(wm, 0, sizeof(*wm));
3206*4882a593Smuzhiyun break;
3207*4882a593Smuzhiyun }
3208*4882a593Smuzhiyun }
3209*4882a593Smuzhiyun
3210*4882a593Smuzhiyun return 0;
3211*4882a593Smuzhiyun }
3212*4882a593Smuzhiyun
3213*4882a593Smuzhiyun /*
3214*4882a593Smuzhiyun * Build a set of 'intermediate' watermark values that satisfy both the old
3215*4882a593Smuzhiyun * state and the new state. These can be programmed to the hardware
3216*4882a593Smuzhiyun * immediately.
3217*4882a593Smuzhiyun */
ilk_compute_intermediate_wm(struct intel_crtc_state * newstate)3218*4882a593Smuzhiyun static int ilk_compute_intermediate_wm(struct intel_crtc_state *newstate)
3219*4882a593Smuzhiyun {
3220*4882a593Smuzhiyun struct intel_crtc *intel_crtc = to_intel_crtc(newstate->uapi.crtc);
3221*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
3222*4882a593Smuzhiyun struct intel_pipe_wm *a = &newstate->wm.ilk.intermediate;
3223*4882a593Smuzhiyun struct intel_atomic_state *intel_state =
3224*4882a593Smuzhiyun to_intel_atomic_state(newstate->uapi.state);
3225*4882a593Smuzhiyun const struct intel_crtc_state *oldstate =
3226*4882a593Smuzhiyun intel_atomic_get_old_crtc_state(intel_state, intel_crtc);
3227*4882a593Smuzhiyun const struct intel_pipe_wm *b = &oldstate->wm.ilk.optimal;
3228*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
3229*4882a593Smuzhiyun
3230*4882a593Smuzhiyun /*
3231*4882a593Smuzhiyun * Start with the final, target watermarks, then combine with the
3232*4882a593Smuzhiyun * currently active watermarks to get values that are safe both before
3233*4882a593Smuzhiyun * and after the vblank.
3234*4882a593Smuzhiyun */
3235*4882a593Smuzhiyun *a = newstate->wm.ilk.optimal;
3236*4882a593Smuzhiyun if (!newstate->hw.active || drm_atomic_crtc_needs_modeset(&newstate->uapi) ||
3237*4882a593Smuzhiyun intel_state->skip_intermediate_wm)
3238*4882a593Smuzhiyun return 0;
3239*4882a593Smuzhiyun
3240*4882a593Smuzhiyun a->pipe_enabled |= b->pipe_enabled;
3241*4882a593Smuzhiyun a->sprites_enabled |= b->sprites_enabled;
3242*4882a593Smuzhiyun a->sprites_scaled |= b->sprites_scaled;
3243*4882a593Smuzhiyun
3244*4882a593Smuzhiyun for (level = 0; level <= max_level; level++) {
3245*4882a593Smuzhiyun struct intel_wm_level *a_wm = &a->wm[level];
3246*4882a593Smuzhiyun const struct intel_wm_level *b_wm = &b->wm[level];
3247*4882a593Smuzhiyun
3248*4882a593Smuzhiyun a_wm->enable &= b_wm->enable;
3249*4882a593Smuzhiyun a_wm->pri_val = max(a_wm->pri_val, b_wm->pri_val);
3250*4882a593Smuzhiyun a_wm->spr_val = max(a_wm->spr_val, b_wm->spr_val);
3251*4882a593Smuzhiyun a_wm->cur_val = max(a_wm->cur_val, b_wm->cur_val);
3252*4882a593Smuzhiyun a_wm->fbc_val = max(a_wm->fbc_val, b_wm->fbc_val);
3253*4882a593Smuzhiyun }
3254*4882a593Smuzhiyun
3255*4882a593Smuzhiyun /*
3256*4882a593Smuzhiyun * We need to make sure that these merged watermark values are
3257*4882a593Smuzhiyun * actually a valid configuration themselves. If they're not,
3258*4882a593Smuzhiyun * there's no safe way to transition from the old state to
3259*4882a593Smuzhiyun * the new state, so we need to fail the atomic transaction.
3260*4882a593Smuzhiyun */
3261*4882a593Smuzhiyun if (!ilk_validate_pipe_wm(dev_priv, a))
3262*4882a593Smuzhiyun return -EINVAL;
3263*4882a593Smuzhiyun
3264*4882a593Smuzhiyun /*
3265*4882a593Smuzhiyun * If our intermediate WM are identical to the final WM, then we can
3266*4882a593Smuzhiyun * omit the post-vblank programming; only update if it's different.
3267*4882a593Smuzhiyun */
3268*4882a593Smuzhiyun if (memcmp(a, &newstate->wm.ilk.optimal, sizeof(*a)) != 0)
3269*4882a593Smuzhiyun newstate->wm.need_postvbl_update = true;
3270*4882a593Smuzhiyun
3271*4882a593Smuzhiyun return 0;
3272*4882a593Smuzhiyun }
3273*4882a593Smuzhiyun
3274*4882a593Smuzhiyun /*
3275*4882a593Smuzhiyun * Merge the watermarks from all active pipes for a specific level.
3276*4882a593Smuzhiyun */
ilk_merge_wm_level(struct drm_i915_private * dev_priv,int level,struct intel_wm_level * ret_wm)3277*4882a593Smuzhiyun static void ilk_merge_wm_level(struct drm_i915_private *dev_priv,
3278*4882a593Smuzhiyun int level,
3279*4882a593Smuzhiyun struct intel_wm_level *ret_wm)
3280*4882a593Smuzhiyun {
3281*4882a593Smuzhiyun const struct intel_crtc *intel_crtc;
3282*4882a593Smuzhiyun
3283*4882a593Smuzhiyun ret_wm->enable = true;
3284*4882a593Smuzhiyun
3285*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, intel_crtc) {
3286*4882a593Smuzhiyun const struct intel_pipe_wm *active = &intel_crtc->wm.active.ilk;
3287*4882a593Smuzhiyun const struct intel_wm_level *wm = &active->wm[level];
3288*4882a593Smuzhiyun
3289*4882a593Smuzhiyun if (!active->pipe_enabled)
3290*4882a593Smuzhiyun continue;
3291*4882a593Smuzhiyun
3292*4882a593Smuzhiyun /*
3293*4882a593Smuzhiyun * The watermark values may have been used in the past,
3294*4882a593Smuzhiyun * so we must maintain them in the registers for some
3295*4882a593Smuzhiyun * time even if the level is now disabled.
3296*4882a593Smuzhiyun */
3297*4882a593Smuzhiyun if (!wm->enable)
3298*4882a593Smuzhiyun ret_wm->enable = false;
3299*4882a593Smuzhiyun
3300*4882a593Smuzhiyun ret_wm->pri_val = max(ret_wm->pri_val, wm->pri_val);
3301*4882a593Smuzhiyun ret_wm->spr_val = max(ret_wm->spr_val, wm->spr_val);
3302*4882a593Smuzhiyun ret_wm->cur_val = max(ret_wm->cur_val, wm->cur_val);
3303*4882a593Smuzhiyun ret_wm->fbc_val = max(ret_wm->fbc_val, wm->fbc_val);
3304*4882a593Smuzhiyun }
3305*4882a593Smuzhiyun }
3306*4882a593Smuzhiyun
3307*4882a593Smuzhiyun /*
3308*4882a593Smuzhiyun * Merge all low power watermarks for all active pipes.
3309*4882a593Smuzhiyun */
ilk_wm_merge(struct drm_i915_private * dev_priv,const struct intel_wm_config * config,const struct ilk_wm_maximums * max,struct intel_pipe_wm * merged)3310*4882a593Smuzhiyun static void ilk_wm_merge(struct drm_i915_private *dev_priv,
3311*4882a593Smuzhiyun const struct intel_wm_config *config,
3312*4882a593Smuzhiyun const struct ilk_wm_maximums *max,
3313*4882a593Smuzhiyun struct intel_pipe_wm *merged)
3314*4882a593Smuzhiyun {
3315*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
3316*4882a593Smuzhiyun int last_enabled_level = max_level;
3317*4882a593Smuzhiyun
3318*4882a593Smuzhiyun /* ILK/SNB/IVB: LP1+ watermarks only w/ single pipe */
3319*4882a593Smuzhiyun if ((INTEL_GEN(dev_priv) <= 6 || IS_IVYBRIDGE(dev_priv)) &&
3320*4882a593Smuzhiyun config->num_pipes_active > 1)
3321*4882a593Smuzhiyun last_enabled_level = 0;
3322*4882a593Smuzhiyun
3323*4882a593Smuzhiyun /* ILK: FBC WM must be disabled always */
3324*4882a593Smuzhiyun merged->fbc_wm_enabled = INTEL_GEN(dev_priv) >= 6;
3325*4882a593Smuzhiyun
3326*4882a593Smuzhiyun /* merge each WM1+ level */
3327*4882a593Smuzhiyun for (level = 1; level <= max_level; level++) {
3328*4882a593Smuzhiyun struct intel_wm_level *wm = &merged->wm[level];
3329*4882a593Smuzhiyun
3330*4882a593Smuzhiyun ilk_merge_wm_level(dev_priv, level, wm);
3331*4882a593Smuzhiyun
3332*4882a593Smuzhiyun if (level > last_enabled_level)
3333*4882a593Smuzhiyun wm->enable = false;
3334*4882a593Smuzhiyun else if (!ilk_validate_wm_level(level, max, wm))
3335*4882a593Smuzhiyun /* make sure all following levels get disabled */
3336*4882a593Smuzhiyun last_enabled_level = level - 1;
3337*4882a593Smuzhiyun
3338*4882a593Smuzhiyun /*
3339*4882a593Smuzhiyun * The spec says it is preferred to disable
3340*4882a593Smuzhiyun * FBC WMs instead of disabling a WM level.
3341*4882a593Smuzhiyun */
3342*4882a593Smuzhiyun if (wm->fbc_val > max->fbc) {
3343*4882a593Smuzhiyun if (wm->enable)
3344*4882a593Smuzhiyun merged->fbc_wm_enabled = false;
3345*4882a593Smuzhiyun wm->fbc_val = 0;
3346*4882a593Smuzhiyun }
3347*4882a593Smuzhiyun }
3348*4882a593Smuzhiyun
3349*4882a593Smuzhiyun /* ILK: LP2+ must be disabled when FBC WM is disabled but FBC enabled */
3350*4882a593Smuzhiyun /*
3351*4882a593Smuzhiyun * FIXME this is racy. FBC might get enabled later.
3352*4882a593Smuzhiyun * What we should check here is whether FBC can be
3353*4882a593Smuzhiyun * enabled sometime later.
3354*4882a593Smuzhiyun */
3355*4882a593Smuzhiyun if (IS_GEN(dev_priv, 5) && !merged->fbc_wm_enabled &&
3356*4882a593Smuzhiyun intel_fbc_is_active(dev_priv)) {
3357*4882a593Smuzhiyun for (level = 2; level <= max_level; level++) {
3358*4882a593Smuzhiyun struct intel_wm_level *wm = &merged->wm[level];
3359*4882a593Smuzhiyun
3360*4882a593Smuzhiyun wm->enable = false;
3361*4882a593Smuzhiyun }
3362*4882a593Smuzhiyun }
3363*4882a593Smuzhiyun }
3364*4882a593Smuzhiyun
ilk_wm_lp_to_level(int wm_lp,const struct intel_pipe_wm * pipe_wm)3365*4882a593Smuzhiyun static int ilk_wm_lp_to_level(int wm_lp, const struct intel_pipe_wm *pipe_wm)
3366*4882a593Smuzhiyun {
3367*4882a593Smuzhiyun /* LP1,LP2,LP3 levels are either 1,2,3 or 1,3,4 */
3368*4882a593Smuzhiyun return wm_lp + (wm_lp >= 2 && pipe_wm->wm[4].enable);
3369*4882a593Smuzhiyun }
3370*4882a593Smuzhiyun
3371*4882a593Smuzhiyun /* The value we need to program into the WM_LPx latency field */
ilk_wm_lp_latency(struct drm_i915_private * dev_priv,int level)3372*4882a593Smuzhiyun static unsigned int ilk_wm_lp_latency(struct drm_i915_private *dev_priv,
3373*4882a593Smuzhiyun int level)
3374*4882a593Smuzhiyun {
3375*4882a593Smuzhiyun if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3376*4882a593Smuzhiyun return 2 * level;
3377*4882a593Smuzhiyun else
3378*4882a593Smuzhiyun return dev_priv->wm.pri_latency[level];
3379*4882a593Smuzhiyun }
3380*4882a593Smuzhiyun
ilk_compute_wm_results(struct drm_i915_private * dev_priv,const struct intel_pipe_wm * merged,enum intel_ddb_partitioning partitioning,struct ilk_wm_values * results)3381*4882a593Smuzhiyun static void ilk_compute_wm_results(struct drm_i915_private *dev_priv,
3382*4882a593Smuzhiyun const struct intel_pipe_wm *merged,
3383*4882a593Smuzhiyun enum intel_ddb_partitioning partitioning,
3384*4882a593Smuzhiyun struct ilk_wm_values *results)
3385*4882a593Smuzhiyun {
3386*4882a593Smuzhiyun struct intel_crtc *intel_crtc;
3387*4882a593Smuzhiyun int level, wm_lp;
3388*4882a593Smuzhiyun
3389*4882a593Smuzhiyun results->enable_fbc_wm = merged->fbc_wm_enabled;
3390*4882a593Smuzhiyun results->partitioning = partitioning;
3391*4882a593Smuzhiyun
3392*4882a593Smuzhiyun /* LP1+ register values */
3393*4882a593Smuzhiyun for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
3394*4882a593Smuzhiyun const struct intel_wm_level *r;
3395*4882a593Smuzhiyun
3396*4882a593Smuzhiyun level = ilk_wm_lp_to_level(wm_lp, merged);
3397*4882a593Smuzhiyun
3398*4882a593Smuzhiyun r = &merged->wm[level];
3399*4882a593Smuzhiyun
3400*4882a593Smuzhiyun /*
3401*4882a593Smuzhiyun * Maintain the watermark values even if the level is
3402*4882a593Smuzhiyun * disabled. Doing otherwise could cause underruns.
3403*4882a593Smuzhiyun */
3404*4882a593Smuzhiyun results->wm_lp[wm_lp - 1] =
3405*4882a593Smuzhiyun (ilk_wm_lp_latency(dev_priv, level) << WM1_LP_LATENCY_SHIFT) |
3406*4882a593Smuzhiyun (r->pri_val << WM1_LP_SR_SHIFT) |
3407*4882a593Smuzhiyun r->cur_val;
3408*4882a593Smuzhiyun
3409*4882a593Smuzhiyun if (r->enable)
3410*4882a593Smuzhiyun results->wm_lp[wm_lp - 1] |= WM1_LP_SR_EN;
3411*4882a593Smuzhiyun
3412*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 8)
3413*4882a593Smuzhiyun results->wm_lp[wm_lp - 1] |=
3414*4882a593Smuzhiyun r->fbc_val << WM1_LP_FBC_SHIFT_BDW;
3415*4882a593Smuzhiyun else
3416*4882a593Smuzhiyun results->wm_lp[wm_lp - 1] |=
3417*4882a593Smuzhiyun r->fbc_val << WM1_LP_FBC_SHIFT;
3418*4882a593Smuzhiyun
3419*4882a593Smuzhiyun /*
3420*4882a593Smuzhiyun * Always set WM1S_LP_EN when spr_val != 0, even if the
3421*4882a593Smuzhiyun * level is disabled. Doing otherwise could cause underruns.
3422*4882a593Smuzhiyun */
3423*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) <= 6 && r->spr_val) {
3424*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, wm_lp != 1);
3425*4882a593Smuzhiyun results->wm_lp_spr[wm_lp - 1] = WM1S_LP_EN | r->spr_val;
3426*4882a593Smuzhiyun } else
3427*4882a593Smuzhiyun results->wm_lp_spr[wm_lp - 1] = r->spr_val;
3428*4882a593Smuzhiyun }
3429*4882a593Smuzhiyun
3430*4882a593Smuzhiyun /* LP0 register values */
3431*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, intel_crtc) {
3432*4882a593Smuzhiyun enum pipe pipe = intel_crtc->pipe;
3433*4882a593Smuzhiyun const struct intel_pipe_wm *pipe_wm = &intel_crtc->wm.active.ilk;
3434*4882a593Smuzhiyun const struct intel_wm_level *r = &pipe_wm->wm[0];
3435*4882a593Smuzhiyun
3436*4882a593Smuzhiyun if (drm_WARN_ON(&dev_priv->drm, !r->enable))
3437*4882a593Smuzhiyun continue;
3438*4882a593Smuzhiyun
3439*4882a593Smuzhiyun results->wm_pipe[pipe] =
3440*4882a593Smuzhiyun (r->pri_val << WM0_PIPE_PLANE_SHIFT) |
3441*4882a593Smuzhiyun (r->spr_val << WM0_PIPE_SPRITE_SHIFT) |
3442*4882a593Smuzhiyun r->cur_val;
3443*4882a593Smuzhiyun }
3444*4882a593Smuzhiyun }
3445*4882a593Smuzhiyun
3446*4882a593Smuzhiyun /* Find the result with the highest level enabled. Check for enable_fbc_wm in
3447*4882a593Smuzhiyun * case both are at the same level. Prefer r1 in case they're the same. */
3448*4882a593Smuzhiyun static struct intel_pipe_wm *
ilk_find_best_result(struct drm_i915_private * dev_priv,struct intel_pipe_wm * r1,struct intel_pipe_wm * r2)3449*4882a593Smuzhiyun ilk_find_best_result(struct drm_i915_private *dev_priv,
3450*4882a593Smuzhiyun struct intel_pipe_wm *r1,
3451*4882a593Smuzhiyun struct intel_pipe_wm *r2)
3452*4882a593Smuzhiyun {
3453*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
3454*4882a593Smuzhiyun int level1 = 0, level2 = 0;
3455*4882a593Smuzhiyun
3456*4882a593Smuzhiyun for (level = 1; level <= max_level; level++) {
3457*4882a593Smuzhiyun if (r1->wm[level].enable)
3458*4882a593Smuzhiyun level1 = level;
3459*4882a593Smuzhiyun if (r2->wm[level].enable)
3460*4882a593Smuzhiyun level2 = level;
3461*4882a593Smuzhiyun }
3462*4882a593Smuzhiyun
3463*4882a593Smuzhiyun if (level1 == level2) {
3464*4882a593Smuzhiyun if (r2->fbc_wm_enabled && !r1->fbc_wm_enabled)
3465*4882a593Smuzhiyun return r2;
3466*4882a593Smuzhiyun else
3467*4882a593Smuzhiyun return r1;
3468*4882a593Smuzhiyun } else if (level1 > level2) {
3469*4882a593Smuzhiyun return r1;
3470*4882a593Smuzhiyun } else {
3471*4882a593Smuzhiyun return r2;
3472*4882a593Smuzhiyun }
3473*4882a593Smuzhiyun }
3474*4882a593Smuzhiyun
3475*4882a593Smuzhiyun /* dirty bits used to track which watermarks need changes */
3476*4882a593Smuzhiyun #define WM_DIRTY_PIPE(pipe) (1 << (pipe))
3477*4882a593Smuzhiyun #define WM_DIRTY_LP(wm_lp) (1 << (15 + (wm_lp)))
3478*4882a593Smuzhiyun #define WM_DIRTY_LP_ALL (WM_DIRTY_LP(1) | WM_DIRTY_LP(2) | WM_DIRTY_LP(3))
3479*4882a593Smuzhiyun #define WM_DIRTY_FBC (1 << 24)
3480*4882a593Smuzhiyun #define WM_DIRTY_DDB (1 << 25)
3481*4882a593Smuzhiyun
ilk_compute_wm_dirty(struct drm_i915_private * dev_priv,const struct ilk_wm_values * old,const struct ilk_wm_values * new)3482*4882a593Smuzhiyun static unsigned int ilk_compute_wm_dirty(struct drm_i915_private *dev_priv,
3483*4882a593Smuzhiyun const struct ilk_wm_values *old,
3484*4882a593Smuzhiyun const struct ilk_wm_values *new)
3485*4882a593Smuzhiyun {
3486*4882a593Smuzhiyun unsigned int dirty = 0;
3487*4882a593Smuzhiyun enum pipe pipe;
3488*4882a593Smuzhiyun int wm_lp;
3489*4882a593Smuzhiyun
3490*4882a593Smuzhiyun for_each_pipe(dev_priv, pipe) {
3491*4882a593Smuzhiyun if (old->wm_pipe[pipe] != new->wm_pipe[pipe]) {
3492*4882a593Smuzhiyun dirty |= WM_DIRTY_PIPE(pipe);
3493*4882a593Smuzhiyun /* Must disable LP1+ watermarks too */
3494*4882a593Smuzhiyun dirty |= WM_DIRTY_LP_ALL;
3495*4882a593Smuzhiyun }
3496*4882a593Smuzhiyun }
3497*4882a593Smuzhiyun
3498*4882a593Smuzhiyun if (old->enable_fbc_wm != new->enable_fbc_wm) {
3499*4882a593Smuzhiyun dirty |= WM_DIRTY_FBC;
3500*4882a593Smuzhiyun /* Must disable LP1+ watermarks too */
3501*4882a593Smuzhiyun dirty |= WM_DIRTY_LP_ALL;
3502*4882a593Smuzhiyun }
3503*4882a593Smuzhiyun
3504*4882a593Smuzhiyun if (old->partitioning != new->partitioning) {
3505*4882a593Smuzhiyun dirty |= WM_DIRTY_DDB;
3506*4882a593Smuzhiyun /* Must disable LP1+ watermarks too */
3507*4882a593Smuzhiyun dirty |= WM_DIRTY_LP_ALL;
3508*4882a593Smuzhiyun }
3509*4882a593Smuzhiyun
3510*4882a593Smuzhiyun /* LP1+ watermarks already deemed dirty, no need to continue */
3511*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP_ALL)
3512*4882a593Smuzhiyun return dirty;
3513*4882a593Smuzhiyun
3514*4882a593Smuzhiyun /* Find the lowest numbered LP1+ watermark in need of an update... */
3515*4882a593Smuzhiyun for (wm_lp = 1; wm_lp <= 3; wm_lp++) {
3516*4882a593Smuzhiyun if (old->wm_lp[wm_lp - 1] != new->wm_lp[wm_lp - 1] ||
3517*4882a593Smuzhiyun old->wm_lp_spr[wm_lp - 1] != new->wm_lp_spr[wm_lp - 1])
3518*4882a593Smuzhiyun break;
3519*4882a593Smuzhiyun }
3520*4882a593Smuzhiyun
3521*4882a593Smuzhiyun /* ...and mark it and all higher numbered LP1+ watermarks as dirty */
3522*4882a593Smuzhiyun for (; wm_lp <= 3; wm_lp++)
3523*4882a593Smuzhiyun dirty |= WM_DIRTY_LP(wm_lp);
3524*4882a593Smuzhiyun
3525*4882a593Smuzhiyun return dirty;
3526*4882a593Smuzhiyun }
3527*4882a593Smuzhiyun
_ilk_disable_lp_wm(struct drm_i915_private * dev_priv,unsigned int dirty)3528*4882a593Smuzhiyun static bool _ilk_disable_lp_wm(struct drm_i915_private *dev_priv,
3529*4882a593Smuzhiyun unsigned int dirty)
3530*4882a593Smuzhiyun {
3531*4882a593Smuzhiyun struct ilk_wm_values *previous = &dev_priv->wm.hw;
3532*4882a593Smuzhiyun bool changed = false;
3533*4882a593Smuzhiyun
3534*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] & WM1_LP_SR_EN) {
3535*4882a593Smuzhiyun previous->wm_lp[2] &= ~WM1_LP_SR_EN;
3536*4882a593Smuzhiyun I915_WRITE(WM3_LP_ILK, previous->wm_lp[2]);
3537*4882a593Smuzhiyun changed = true;
3538*4882a593Smuzhiyun }
3539*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] & WM1_LP_SR_EN) {
3540*4882a593Smuzhiyun previous->wm_lp[1] &= ~WM1_LP_SR_EN;
3541*4882a593Smuzhiyun I915_WRITE(WM2_LP_ILK, previous->wm_lp[1]);
3542*4882a593Smuzhiyun changed = true;
3543*4882a593Smuzhiyun }
3544*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] & WM1_LP_SR_EN) {
3545*4882a593Smuzhiyun previous->wm_lp[0] &= ~WM1_LP_SR_EN;
3546*4882a593Smuzhiyun I915_WRITE(WM1_LP_ILK, previous->wm_lp[0]);
3547*4882a593Smuzhiyun changed = true;
3548*4882a593Smuzhiyun }
3549*4882a593Smuzhiyun
3550*4882a593Smuzhiyun /*
3551*4882a593Smuzhiyun * Don't touch WM1S_LP_EN here.
3552*4882a593Smuzhiyun * Doing so could cause underruns.
3553*4882a593Smuzhiyun */
3554*4882a593Smuzhiyun
3555*4882a593Smuzhiyun return changed;
3556*4882a593Smuzhiyun }
3557*4882a593Smuzhiyun
3558*4882a593Smuzhiyun /*
3559*4882a593Smuzhiyun * The spec says we shouldn't write when we don't need, because every write
3560*4882a593Smuzhiyun * causes WMs to be re-evaluated, expending some power.
3561*4882a593Smuzhiyun */
ilk_write_wm_values(struct drm_i915_private * dev_priv,struct ilk_wm_values * results)3562*4882a593Smuzhiyun static void ilk_write_wm_values(struct drm_i915_private *dev_priv,
3563*4882a593Smuzhiyun struct ilk_wm_values *results)
3564*4882a593Smuzhiyun {
3565*4882a593Smuzhiyun struct ilk_wm_values *previous = &dev_priv->wm.hw;
3566*4882a593Smuzhiyun unsigned int dirty;
3567*4882a593Smuzhiyun u32 val;
3568*4882a593Smuzhiyun
3569*4882a593Smuzhiyun dirty = ilk_compute_wm_dirty(dev_priv, previous, results);
3570*4882a593Smuzhiyun if (!dirty)
3571*4882a593Smuzhiyun return;
3572*4882a593Smuzhiyun
3573*4882a593Smuzhiyun _ilk_disable_lp_wm(dev_priv, dirty);
3574*4882a593Smuzhiyun
3575*4882a593Smuzhiyun if (dirty & WM_DIRTY_PIPE(PIPE_A))
3576*4882a593Smuzhiyun I915_WRITE(WM0_PIPEA_ILK, results->wm_pipe[0]);
3577*4882a593Smuzhiyun if (dirty & WM_DIRTY_PIPE(PIPE_B))
3578*4882a593Smuzhiyun I915_WRITE(WM0_PIPEB_ILK, results->wm_pipe[1]);
3579*4882a593Smuzhiyun if (dirty & WM_DIRTY_PIPE(PIPE_C))
3580*4882a593Smuzhiyun I915_WRITE(WM0_PIPEC_IVB, results->wm_pipe[2]);
3581*4882a593Smuzhiyun
3582*4882a593Smuzhiyun if (dirty & WM_DIRTY_DDB) {
3583*4882a593Smuzhiyun if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
3584*4882a593Smuzhiyun val = I915_READ(WM_MISC);
3585*4882a593Smuzhiyun if (results->partitioning == INTEL_DDB_PART_1_2)
3586*4882a593Smuzhiyun val &= ~WM_MISC_DATA_PARTITION_5_6;
3587*4882a593Smuzhiyun else
3588*4882a593Smuzhiyun val |= WM_MISC_DATA_PARTITION_5_6;
3589*4882a593Smuzhiyun I915_WRITE(WM_MISC, val);
3590*4882a593Smuzhiyun } else {
3591*4882a593Smuzhiyun val = I915_READ(DISP_ARB_CTL2);
3592*4882a593Smuzhiyun if (results->partitioning == INTEL_DDB_PART_1_2)
3593*4882a593Smuzhiyun val &= ~DISP_DATA_PARTITION_5_6;
3594*4882a593Smuzhiyun else
3595*4882a593Smuzhiyun val |= DISP_DATA_PARTITION_5_6;
3596*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL2, val);
3597*4882a593Smuzhiyun }
3598*4882a593Smuzhiyun }
3599*4882a593Smuzhiyun
3600*4882a593Smuzhiyun if (dirty & WM_DIRTY_FBC) {
3601*4882a593Smuzhiyun val = I915_READ(DISP_ARB_CTL);
3602*4882a593Smuzhiyun if (results->enable_fbc_wm)
3603*4882a593Smuzhiyun val &= ~DISP_FBC_WM_DIS;
3604*4882a593Smuzhiyun else
3605*4882a593Smuzhiyun val |= DISP_FBC_WM_DIS;
3606*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL, val);
3607*4882a593Smuzhiyun }
3608*4882a593Smuzhiyun
3609*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(1) &&
3610*4882a593Smuzhiyun previous->wm_lp_spr[0] != results->wm_lp_spr[0])
3611*4882a593Smuzhiyun I915_WRITE(WM1S_LP_ILK, results->wm_lp_spr[0]);
3612*4882a593Smuzhiyun
3613*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 7) {
3614*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(2) && previous->wm_lp_spr[1] != results->wm_lp_spr[1])
3615*4882a593Smuzhiyun I915_WRITE(WM2S_LP_IVB, results->wm_lp_spr[1]);
3616*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(3) && previous->wm_lp_spr[2] != results->wm_lp_spr[2])
3617*4882a593Smuzhiyun I915_WRITE(WM3S_LP_IVB, results->wm_lp_spr[2]);
3618*4882a593Smuzhiyun }
3619*4882a593Smuzhiyun
3620*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(1) && previous->wm_lp[0] != results->wm_lp[0])
3621*4882a593Smuzhiyun I915_WRITE(WM1_LP_ILK, results->wm_lp[0]);
3622*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(2) && previous->wm_lp[1] != results->wm_lp[1])
3623*4882a593Smuzhiyun I915_WRITE(WM2_LP_ILK, results->wm_lp[1]);
3624*4882a593Smuzhiyun if (dirty & WM_DIRTY_LP(3) && previous->wm_lp[2] != results->wm_lp[2])
3625*4882a593Smuzhiyun I915_WRITE(WM3_LP_ILK, results->wm_lp[2]);
3626*4882a593Smuzhiyun
3627*4882a593Smuzhiyun dev_priv->wm.hw = *results;
3628*4882a593Smuzhiyun }
3629*4882a593Smuzhiyun
ilk_disable_lp_wm(struct drm_i915_private * dev_priv)3630*4882a593Smuzhiyun bool ilk_disable_lp_wm(struct drm_i915_private *dev_priv)
3631*4882a593Smuzhiyun {
3632*4882a593Smuzhiyun return _ilk_disable_lp_wm(dev_priv, WM_DIRTY_LP_ALL);
3633*4882a593Smuzhiyun }
3634*4882a593Smuzhiyun
intel_enabled_dbuf_slices_mask(struct drm_i915_private * dev_priv)3635*4882a593Smuzhiyun u8 intel_enabled_dbuf_slices_mask(struct drm_i915_private *dev_priv)
3636*4882a593Smuzhiyun {
3637*4882a593Smuzhiyun int i;
3638*4882a593Smuzhiyun int max_slices = INTEL_INFO(dev_priv)->num_supported_dbuf_slices;
3639*4882a593Smuzhiyun u8 enabled_slices_mask = 0;
3640*4882a593Smuzhiyun
3641*4882a593Smuzhiyun for (i = 0; i < max_slices; i++) {
3642*4882a593Smuzhiyun if (I915_READ(DBUF_CTL_S(i)) & DBUF_POWER_STATE)
3643*4882a593Smuzhiyun enabled_slices_mask |= BIT(i);
3644*4882a593Smuzhiyun }
3645*4882a593Smuzhiyun
3646*4882a593Smuzhiyun return enabled_slices_mask;
3647*4882a593Smuzhiyun }
3648*4882a593Smuzhiyun
3649*4882a593Smuzhiyun /*
3650*4882a593Smuzhiyun * FIXME: We still don't have the proper code detect if we need to apply the WA,
3651*4882a593Smuzhiyun * so assume we'll always need it in order to avoid underruns.
3652*4882a593Smuzhiyun */
skl_needs_memory_bw_wa(struct drm_i915_private * dev_priv)3653*4882a593Smuzhiyun static bool skl_needs_memory_bw_wa(struct drm_i915_private *dev_priv)
3654*4882a593Smuzhiyun {
3655*4882a593Smuzhiyun return IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv);
3656*4882a593Smuzhiyun }
3657*4882a593Smuzhiyun
3658*4882a593Smuzhiyun static bool
intel_has_sagv(struct drm_i915_private * dev_priv)3659*4882a593Smuzhiyun intel_has_sagv(struct drm_i915_private *dev_priv)
3660*4882a593Smuzhiyun {
3661*4882a593Smuzhiyun return (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) &&
3662*4882a593Smuzhiyun dev_priv->sagv_status != I915_SAGV_NOT_CONTROLLED;
3663*4882a593Smuzhiyun }
3664*4882a593Smuzhiyun
3665*4882a593Smuzhiyun static void
skl_setup_sagv_block_time(struct drm_i915_private * dev_priv)3666*4882a593Smuzhiyun skl_setup_sagv_block_time(struct drm_i915_private *dev_priv)
3667*4882a593Smuzhiyun {
3668*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 12) {
3669*4882a593Smuzhiyun u32 val = 0;
3670*4882a593Smuzhiyun int ret;
3671*4882a593Smuzhiyun
3672*4882a593Smuzhiyun ret = sandybridge_pcode_read(dev_priv,
3673*4882a593Smuzhiyun GEN12_PCODE_READ_SAGV_BLOCK_TIME_US,
3674*4882a593Smuzhiyun &val, NULL);
3675*4882a593Smuzhiyun if (!ret) {
3676*4882a593Smuzhiyun dev_priv->sagv_block_time_us = val;
3677*4882a593Smuzhiyun return;
3678*4882a593Smuzhiyun }
3679*4882a593Smuzhiyun
3680*4882a593Smuzhiyun drm_dbg(&dev_priv->drm, "Couldn't read SAGV block time!\n");
3681*4882a593Smuzhiyun } else if (IS_GEN(dev_priv, 11)) {
3682*4882a593Smuzhiyun dev_priv->sagv_block_time_us = 10;
3683*4882a593Smuzhiyun return;
3684*4882a593Smuzhiyun } else if (IS_GEN(dev_priv, 10)) {
3685*4882a593Smuzhiyun dev_priv->sagv_block_time_us = 20;
3686*4882a593Smuzhiyun return;
3687*4882a593Smuzhiyun } else if (IS_GEN(dev_priv, 9)) {
3688*4882a593Smuzhiyun dev_priv->sagv_block_time_us = 30;
3689*4882a593Smuzhiyun return;
3690*4882a593Smuzhiyun } else {
3691*4882a593Smuzhiyun MISSING_CASE(INTEL_GEN(dev_priv));
3692*4882a593Smuzhiyun }
3693*4882a593Smuzhiyun
3694*4882a593Smuzhiyun /* Default to an unusable block time */
3695*4882a593Smuzhiyun dev_priv->sagv_block_time_us = -1;
3696*4882a593Smuzhiyun }
3697*4882a593Smuzhiyun
3698*4882a593Smuzhiyun /*
3699*4882a593Smuzhiyun * SAGV dynamically adjusts the system agent voltage and clock frequencies
3700*4882a593Smuzhiyun * depending on power and performance requirements. The display engine access
3701*4882a593Smuzhiyun * to system memory is blocked during the adjustment time. Because of the
3702*4882a593Smuzhiyun * blocking time, having this enabled can cause full system hangs and/or pipe
3703*4882a593Smuzhiyun * underruns if we don't meet all of the following requirements:
3704*4882a593Smuzhiyun *
3705*4882a593Smuzhiyun * - <= 1 pipe enabled
3706*4882a593Smuzhiyun * - All planes can enable watermarks for latencies >= SAGV engine block time
3707*4882a593Smuzhiyun * - We're not using an interlaced display configuration
3708*4882a593Smuzhiyun */
3709*4882a593Smuzhiyun int
intel_enable_sagv(struct drm_i915_private * dev_priv)3710*4882a593Smuzhiyun intel_enable_sagv(struct drm_i915_private *dev_priv)
3711*4882a593Smuzhiyun {
3712*4882a593Smuzhiyun int ret;
3713*4882a593Smuzhiyun
3714*4882a593Smuzhiyun if (!intel_has_sagv(dev_priv))
3715*4882a593Smuzhiyun return 0;
3716*4882a593Smuzhiyun
3717*4882a593Smuzhiyun if (dev_priv->sagv_status == I915_SAGV_ENABLED)
3718*4882a593Smuzhiyun return 0;
3719*4882a593Smuzhiyun
3720*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "Enabling SAGV\n");
3721*4882a593Smuzhiyun ret = sandybridge_pcode_write(dev_priv, GEN9_PCODE_SAGV_CONTROL,
3722*4882a593Smuzhiyun GEN9_SAGV_ENABLE);
3723*4882a593Smuzhiyun
3724*4882a593Smuzhiyun /* We don't need to wait for SAGV when enabling */
3725*4882a593Smuzhiyun
3726*4882a593Smuzhiyun /*
3727*4882a593Smuzhiyun * Some skl systems, pre-release machines in particular,
3728*4882a593Smuzhiyun * don't actually have SAGV.
3729*4882a593Smuzhiyun */
3730*4882a593Smuzhiyun if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) {
3731*4882a593Smuzhiyun drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n");
3732*4882a593Smuzhiyun dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
3733*4882a593Smuzhiyun return 0;
3734*4882a593Smuzhiyun } else if (ret < 0) {
3735*4882a593Smuzhiyun drm_err(&dev_priv->drm, "Failed to enable SAGV\n");
3736*4882a593Smuzhiyun return ret;
3737*4882a593Smuzhiyun }
3738*4882a593Smuzhiyun
3739*4882a593Smuzhiyun dev_priv->sagv_status = I915_SAGV_ENABLED;
3740*4882a593Smuzhiyun return 0;
3741*4882a593Smuzhiyun }
3742*4882a593Smuzhiyun
3743*4882a593Smuzhiyun int
intel_disable_sagv(struct drm_i915_private * dev_priv)3744*4882a593Smuzhiyun intel_disable_sagv(struct drm_i915_private *dev_priv)
3745*4882a593Smuzhiyun {
3746*4882a593Smuzhiyun int ret;
3747*4882a593Smuzhiyun
3748*4882a593Smuzhiyun if (!intel_has_sagv(dev_priv))
3749*4882a593Smuzhiyun return 0;
3750*4882a593Smuzhiyun
3751*4882a593Smuzhiyun if (dev_priv->sagv_status == I915_SAGV_DISABLED)
3752*4882a593Smuzhiyun return 0;
3753*4882a593Smuzhiyun
3754*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "Disabling SAGV\n");
3755*4882a593Smuzhiyun /* bspec says to keep retrying for at least 1 ms */
3756*4882a593Smuzhiyun ret = skl_pcode_request(dev_priv, GEN9_PCODE_SAGV_CONTROL,
3757*4882a593Smuzhiyun GEN9_SAGV_DISABLE,
3758*4882a593Smuzhiyun GEN9_SAGV_IS_DISABLED, GEN9_SAGV_IS_DISABLED,
3759*4882a593Smuzhiyun 1);
3760*4882a593Smuzhiyun /*
3761*4882a593Smuzhiyun * Some skl systems, pre-release machines in particular,
3762*4882a593Smuzhiyun * don't actually have SAGV.
3763*4882a593Smuzhiyun */
3764*4882a593Smuzhiyun if (IS_SKYLAKE(dev_priv) && ret == -ENXIO) {
3765*4882a593Smuzhiyun drm_dbg(&dev_priv->drm, "No SAGV found on system, ignoring\n");
3766*4882a593Smuzhiyun dev_priv->sagv_status = I915_SAGV_NOT_CONTROLLED;
3767*4882a593Smuzhiyun return 0;
3768*4882a593Smuzhiyun } else if (ret < 0) {
3769*4882a593Smuzhiyun drm_err(&dev_priv->drm, "Failed to disable SAGV (%d)\n", ret);
3770*4882a593Smuzhiyun return ret;
3771*4882a593Smuzhiyun }
3772*4882a593Smuzhiyun
3773*4882a593Smuzhiyun dev_priv->sagv_status = I915_SAGV_DISABLED;
3774*4882a593Smuzhiyun return 0;
3775*4882a593Smuzhiyun }
3776*4882a593Smuzhiyun
intel_sagv_pre_plane_update(struct intel_atomic_state * state)3777*4882a593Smuzhiyun void intel_sagv_pre_plane_update(struct intel_atomic_state *state)
3778*4882a593Smuzhiyun {
3779*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
3780*4882a593Smuzhiyun const struct intel_bw_state *new_bw_state;
3781*4882a593Smuzhiyun const struct intel_bw_state *old_bw_state;
3782*4882a593Smuzhiyun u32 new_mask = 0;
3783*4882a593Smuzhiyun
3784*4882a593Smuzhiyun /*
3785*4882a593Smuzhiyun * Just return if we can't control SAGV or don't have it.
3786*4882a593Smuzhiyun * This is different from situation when we have SAGV but just can't
3787*4882a593Smuzhiyun * afford it due to DBuf limitation - in case if SAGV is completely
3788*4882a593Smuzhiyun * disabled in a BIOS, we are not even allowed to send a PCode request,
3789*4882a593Smuzhiyun * as it will throw an error. So have to check it here.
3790*4882a593Smuzhiyun */
3791*4882a593Smuzhiyun if (!intel_has_sagv(dev_priv))
3792*4882a593Smuzhiyun return;
3793*4882a593Smuzhiyun
3794*4882a593Smuzhiyun new_bw_state = intel_atomic_get_new_bw_state(state);
3795*4882a593Smuzhiyun if (!new_bw_state)
3796*4882a593Smuzhiyun return;
3797*4882a593Smuzhiyun
3798*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) < 11 && !intel_can_enable_sagv(dev_priv, new_bw_state)) {
3799*4882a593Smuzhiyun intel_disable_sagv(dev_priv);
3800*4882a593Smuzhiyun return;
3801*4882a593Smuzhiyun }
3802*4882a593Smuzhiyun
3803*4882a593Smuzhiyun old_bw_state = intel_atomic_get_old_bw_state(state);
3804*4882a593Smuzhiyun /*
3805*4882a593Smuzhiyun * Nothing to mask
3806*4882a593Smuzhiyun */
3807*4882a593Smuzhiyun if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask)
3808*4882a593Smuzhiyun return;
3809*4882a593Smuzhiyun
3810*4882a593Smuzhiyun new_mask = old_bw_state->qgv_points_mask | new_bw_state->qgv_points_mask;
3811*4882a593Smuzhiyun
3812*4882a593Smuzhiyun /*
3813*4882a593Smuzhiyun * If new mask is zero - means there is nothing to mask,
3814*4882a593Smuzhiyun * we can only unmask, which should be done in unmask.
3815*4882a593Smuzhiyun */
3816*4882a593Smuzhiyun if (!new_mask)
3817*4882a593Smuzhiyun return;
3818*4882a593Smuzhiyun
3819*4882a593Smuzhiyun /*
3820*4882a593Smuzhiyun * Restrict required qgv points before updating the configuration.
3821*4882a593Smuzhiyun * According to BSpec we can't mask and unmask qgv points at the same
3822*4882a593Smuzhiyun * time. Also masking should be done before updating the configuration
3823*4882a593Smuzhiyun * and unmasking afterwards.
3824*4882a593Smuzhiyun */
3825*4882a593Smuzhiyun icl_pcode_restrict_qgv_points(dev_priv, new_mask);
3826*4882a593Smuzhiyun }
3827*4882a593Smuzhiyun
intel_sagv_post_plane_update(struct intel_atomic_state * state)3828*4882a593Smuzhiyun void intel_sagv_post_plane_update(struct intel_atomic_state *state)
3829*4882a593Smuzhiyun {
3830*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
3831*4882a593Smuzhiyun const struct intel_bw_state *new_bw_state;
3832*4882a593Smuzhiyun const struct intel_bw_state *old_bw_state;
3833*4882a593Smuzhiyun u32 new_mask = 0;
3834*4882a593Smuzhiyun
3835*4882a593Smuzhiyun /*
3836*4882a593Smuzhiyun * Just return if we can't control SAGV or don't have it.
3837*4882a593Smuzhiyun * This is different from situation when we have SAGV but just can't
3838*4882a593Smuzhiyun * afford it due to DBuf limitation - in case if SAGV is completely
3839*4882a593Smuzhiyun * disabled in a BIOS, we are not even allowed to send a PCode request,
3840*4882a593Smuzhiyun * as it will throw an error. So have to check it here.
3841*4882a593Smuzhiyun */
3842*4882a593Smuzhiyun if (!intel_has_sagv(dev_priv))
3843*4882a593Smuzhiyun return;
3844*4882a593Smuzhiyun
3845*4882a593Smuzhiyun new_bw_state = intel_atomic_get_new_bw_state(state);
3846*4882a593Smuzhiyun if (!new_bw_state)
3847*4882a593Smuzhiyun return;
3848*4882a593Smuzhiyun
3849*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) < 11 && intel_can_enable_sagv(dev_priv, new_bw_state)) {
3850*4882a593Smuzhiyun intel_enable_sagv(dev_priv);
3851*4882a593Smuzhiyun return;
3852*4882a593Smuzhiyun }
3853*4882a593Smuzhiyun
3854*4882a593Smuzhiyun old_bw_state = intel_atomic_get_old_bw_state(state);
3855*4882a593Smuzhiyun /*
3856*4882a593Smuzhiyun * Nothing to unmask
3857*4882a593Smuzhiyun */
3858*4882a593Smuzhiyun if (new_bw_state->qgv_points_mask == old_bw_state->qgv_points_mask)
3859*4882a593Smuzhiyun return;
3860*4882a593Smuzhiyun
3861*4882a593Smuzhiyun new_mask = new_bw_state->qgv_points_mask;
3862*4882a593Smuzhiyun
3863*4882a593Smuzhiyun /*
3864*4882a593Smuzhiyun * Allow required qgv points after updating the configuration.
3865*4882a593Smuzhiyun * According to BSpec we can't mask and unmask qgv points at the same
3866*4882a593Smuzhiyun * time. Also masking should be done before updating the configuration
3867*4882a593Smuzhiyun * and unmasking afterwards.
3868*4882a593Smuzhiyun */
3869*4882a593Smuzhiyun icl_pcode_restrict_qgv_points(dev_priv, new_mask);
3870*4882a593Smuzhiyun }
3871*4882a593Smuzhiyun
skl_crtc_can_enable_sagv(const struct intel_crtc_state * crtc_state)3872*4882a593Smuzhiyun static bool skl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state)
3873*4882a593Smuzhiyun {
3874*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3875*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3876*4882a593Smuzhiyun struct intel_plane *plane;
3877*4882a593Smuzhiyun const struct intel_plane_state *plane_state;
3878*4882a593Smuzhiyun int level, latency;
3879*4882a593Smuzhiyun
3880*4882a593Smuzhiyun if (!intel_has_sagv(dev_priv))
3881*4882a593Smuzhiyun return false;
3882*4882a593Smuzhiyun
3883*4882a593Smuzhiyun if (!crtc_state->hw.active)
3884*4882a593Smuzhiyun return true;
3885*4882a593Smuzhiyun
3886*4882a593Smuzhiyun if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3887*4882a593Smuzhiyun return false;
3888*4882a593Smuzhiyun
3889*4882a593Smuzhiyun intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
3890*4882a593Smuzhiyun const struct skl_plane_wm *wm =
3891*4882a593Smuzhiyun &crtc_state->wm.skl.optimal.planes[plane->id];
3892*4882a593Smuzhiyun
3893*4882a593Smuzhiyun /* Skip this plane if it's not enabled */
3894*4882a593Smuzhiyun if (!wm->wm[0].plane_en)
3895*4882a593Smuzhiyun continue;
3896*4882a593Smuzhiyun
3897*4882a593Smuzhiyun /* Find the highest enabled wm level for this plane */
3898*4882a593Smuzhiyun for (level = ilk_wm_max_level(dev_priv);
3899*4882a593Smuzhiyun !wm->wm[level].plane_en; --level)
3900*4882a593Smuzhiyun { }
3901*4882a593Smuzhiyun
3902*4882a593Smuzhiyun latency = dev_priv->wm.skl_latency[level];
3903*4882a593Smuzhiyun
3904*4882a593Smuzhiyun if (skl_needs_memory_bw_wa(dev_priv) &&
3905*4882a593Smuzhiyun plane_state->uapi.fb->modifier ==
3906*4882a593Smuzhiyun I915_FORMAT_MOD_X_TILED)
3907*4882a593Smuzhiyun latency += 15;
3908*4882a593Smuzhiyun
3909*4882a593Smuzhiyun /*
3910*4882a593Smuzhiyun * If any of the planes on this pipe don't enable wm levels that
3911*4882a593Smuzhiyun * incur memory latencies higher than sagv_block_time_us we
3912*4882a593Smuzhiyun * can't enable SAGV.
3913*4882a593Smuzhiyun */
3914*4882a593Smuzhiyun if (latency < dev_priv->sagv_block_time_us)
3915*4882a593Smuzhiyun return false;
3916*4882a593Smuzhiyun }
3917*4882a593Smuzhiyun
3918*4882a593Smuzhiyun return true;
3919*4882a593Smuzhiyun }
3920*4882a593Smuzhiyun
tgl_crtc_can_enable_sagv(const struct intel_crtc_state * crtc_state)3921*4882a593Smuzhiyun static bool tgl_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state)
3922*4882a593Smuzhiyun {
3923*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3924*4882a593Smuzhiyun enum plane_id plane_id;
3925*4882a593Smuzhiyun
3926*4882a593Smuzhiyun if (!crtc_state->hw.active)
3927*4882a593Smuzhiyun return true;
3928*4882a593Smuzhiyun
3929*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
3930*4882a593Smuzhiyun const struct skl_ddb_entry *plane_alloc =
3931*4882a593Smuzhiyun &crtc_state->wm.skl.plane_ddb_y[plane_id];
3932*4882a593Smuzhiyun const struct skl_plane_wm *wm =
3933*4882a593Smuzhiyun &crtc_state->wm.skl.optimal.planes[plane_id];
3934*4882a593Smuzhiyun
3935*4882a593Smuzhiyun if (skl_ddb_entry_size(plane_alloc) < wm->sagv_wm0.min_ddb_alloc)
3936*4882a593Smuzhiyun return false;
3937*4882a593Smuzhiyun }
3938*4882a593Smuzhiyun
3939*4882a593Smuzhiyun return true;
3940*4882a593Smuzhiyun }
3941*4882a593Smuzhiyun
intel_crtc_can_enable_sagv(const struct intel_crtc_state * crtc_state)3942*4882a593Smuzhiyun static bool intel_crtc_can_enable_sagv(const struct intel_crtc_state *crtc_state)
3943*4882a593Smuzhiyun {
3944*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3945*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3946*4882a593Smuzhiyun
3947*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 12)
3948*4882a593Smuzhiyun return tgl_crtc_can_enable_sagv(crtc_state);
3949*4882a593Smuzhiyun else
3950*4882a593Smuzhiyun return skl_crtc_can_enable_sagv(crtc_state);
3951*4882a593Smuzhiyun }
3952*4882a593Smuzhiyun
intel_can_enable_sagv(struct drm_i915_private * dev_priv,const struct intel_bw_state * bw_state)3953*4882a593Smuzhiyun bool intel_can_enable_sagv(struct drm_i915_private *dev_priv,
3954*4882a593Smuzhiyun const struct intel_bw_state *bw_state)
3955*4882a593Smuzhiyun {
3956*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) < 11 &&
3957*4882a593Smuzhiyun bw_state->active_pipes && !is_power_of_2(bw_state->active_pipes))
3958*4882a593Smuzhiyun return false;
3959*4882a593Smuzhiyun
3960*4882a593Smuzhiyun return bw_state->pipe_sagv_reject == 0;
3961*4882a593Smuzhiyun }
3962*4882a593Smuzhiyun
intel_compute_sagv_mask(struct intel_atomic_state * state)3963*4882a593Smuzhiyun static int intel_compute_sagv_mask(struct intel_atomic_state *state)
3964*4882a593Smuzhiyun {
3965*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
3966*4882a593Smuzhiyun int ret;
3967*4882a593Smuzhiyun struct intel_crtc *crtc;
3968*4882a593Smuzhiyun struct intel_crtc_state *new_crtc_state;
3969*4882a593Smuzhiyun struct intel_bw_state *new_bw_state = NULL;
3970*4882a593Smuzhiyun const struct intel_bw_state *old_bw_state = NULL;
3971*4882a593Smuzhiyun int i;
3972*4882a593Smuzhiyun
3973*4882a593Smuzhiyun for_each_new_intel_crtc_in_state(state, crtc,
3974*4882a593Smuzhiyun new_crtc_state, i) {
3975*4882a593Smuzhiyun new_bw_state = intel_atomic_get_bw_state(state);
3976*4882a593Smuzhiyun if (IS_ERR(new_bw_state))
3977*4882a593Smuzhiyun return PTR_ERR(new_bw_state);
3978*4882a593Smuzhiyun
3979*4882a593Smuzhiyun old_bw_state = intel_atomic_get_old_bw_state(state);
3980*4882a593Smuzhiyun
3981*4882a593Smuzhiyun if (intel_crtc_can_enable_sagv(new_crtc_state))
3982*4882a593Smuzhiyun new_bw_state->pipe_sagv_reject &= ~BIT(crtc->pipe);
3983*4882a593Smuzhiyun else
3984*4882a593Smuzhiyun new_bw_state->pipe_sagv_reject |= BIT(crtc->pipe);
3985*4882a593Smuzhiyun }
3986*4882a593Smuzhiyun
3987*4882a593Smuzhiyun if (!new_bw_state)
3988*4882a593Smuzhiyun return 0;
3989*4882a593Smuzhiyun
3990*4882a593Smuzhiyun new_bw_state->active_pipes =
3991*4882a593Smuzhiyun intel_calc_active_pipes(state, old_bw_state->active_pipes);
3992*4882a593Smuzhiyun
3993*4882a593Smuzhiyun if (new_bw_state->active_pipes != old_bw_state->active_pipes) {
3994*4882a593Smuzhiyun ret = intel_atomic_lock_global_state(&new_bw_state->base);
3995*4882a593Smuzhiyun if (ret)
3996*4882a593Smuzhiyun return ret;
3997*4882a593Smuzhiyun }
3998*4882a593Smuzhiyun
3999*4882a593Smuzhiyun if (intel_can_enable_sagv(dev_priv, new_bw_state) !=
4000*4882a593Smuzhiyun intel_can_enable_sagv(dev_priv, old_bw_state)) {
4001*4882a593Smuzhiyun ret = intel_atomic_serialize_global_state(&new_bw_state->base);
4002*4882a593Smuzhiyun if (ret)
4003*4882a593Smuzhiyun return ret;
4004*4882a593Smuzhiyun } else if (new_bw_state->pipe_sagv_reject != old_bw_state->pipe_sagv_reject) {
4005*4882a593Smuzhiyun ret = intel_atomic_lock_global_state(&new_bw_state->base);
4006*4882a593Smuzhiyun if (ret)
4007*4882a593Smuzhiyun return ret;
4008*4882a593Smuzhiyun }
4009*4882a593Smuzhiyun
4010*4882a593Smuzhiyun for_each_new_intel_crtc_in_state(state, crtc,
4011*4882a593Smuzhiyun new_crtc_state, i) {
4012*4882a593Smuzhiyun struct skl_pipe_wm *pipe_wm = &new_crtc_state->wm.skl.optimal;
4013*4882a593Smuzhiyun
4014*4882a593Smuzhiyun /*
4015*4882a593Smuzhiyun * We store use_sagv_wm in the crtc state rather than relying on
4016*4882a593Smuzhiyun * that bw state since we have no convenient way to get at the
4017*4882a593Smuzhiyun * latter from the plane commit hooks (especially in the legacy
4018*4882a593Smuzhiyun * cursor case)
4019*4882a593Smuzhiyun */
4020*4882a593Smuzhiyun pipe_wm->use_sagv_wm = INTEL_GEN(dev_priv) >= 12 &&
4021*4882a593Smuzhiyun intel_can_enable_sagv(dev_priv, new_bw_state);
4022*4882a593Smuzhiyun }
4023*4882a593Smuzhiyun
4024*4882a593Smuzhiyun return 0;
4025*4882a593Smuzhiyun }
4026*4882a593Smuzhiyun
4027*4882a593Smuzhiyun /*
4028*4882a593Smuzhiyun * Calculate initial DBuf slice offset, based on slice size
4029*4882a593Smuzhiyun * and mask(i.e if slice size is 1024 and second slice is enabled
4030*4882a593Smuzhiyun * offset would be 1024)
4031*4882a593Smuzhiyun */
4032*4882a593Smuzhiyun static unsigned int
icl_get_first_dbuf_slice_offset(u32 dbuf_slice_mask,u32 slice_size,u32 ddb_size)4033*4882a593Smuzhiyun icl_get_first_dbuf_slice_offset(u32 dbuf_slice_mask,
4034*4882a593Smuzhiyun u32 slice_size,
4035*4882a593Smuzhiyun u32 ddb_size)
4036*4882a593Smuzhiyun {
4037*4882a593Smuzhiyun unsigned int offset = 0;
4038*4882a593Smuzhiyun
4039*4882a593Smuzhiyun if (!dbuf_slice_mask)
4040*4882a593Smuzhiyun return 0;
4041*4882a593Smuzhiyun
4042*4882a593Smuzhiyun offset = (ffs(dbuf_slice_mask) - 1) * slice_size;
4043*4882a593Smuzhiyun
4044*4882a593Smuzhiyun WARN_ON(offset >= ddb_size);
4045*4882a593Smuzhiyun return offset;
4046*4882a593Smuzhiyun }
4047*4882a593Smuzhiyun
intel_get_ddb_size(struct drm_i915_private * dev_priv)4048*4882a593Smuzhiyun u16 intel_get_ddb_size(struct drm_i915_private *dev_priv)
4049*4882a593Smuzhiyun {
4050*4882a593Smuzhiyun u16 ddb_size = INTEL_INFO(dev_priv)->ddb_size;
4051*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, ddb_size == 0);
4052*4882a593Smuzhiyun
4053*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) < 11)
4054*4882a593Smuzhiyun return ddb_size - 4; /* 4 blocks for bypass path allocation */
4055*4882a593Smuzhiyun
4056*4882a593Smuzhiyun return ddb_size;
4057*4882a593Smuzhiyun }
4058*4882a593Smuzhiyun
skl_ddb_dbuf_slice_mask(struct drm_i915_private * dev_priv,const struct skl_ddb_entry * entry)4059*4882a593Smuzhiyun u32 skl_ddb_dbuf_slice_mask(struct drm_i915_private *dev_priv,
4060*4882a593Smuzhiyun const struct skl_ddb_entry *entry)
4061*4882a593Smuzhiyun {
4062*4882a593Smuzhiyun u32 slice_mask = 0;
4063*4882a593Smuzhiyun u16 ddb_size = intel_get_ddb_size(dev_priv);
4064*4882a593Smuzhiyun u16 num_supported_slices = INTEL_INFO(dev_priv)->num_supported_dbuf_slices;
4065*4882a593Smuzhiyun u16 slice_size = ddb_size / num_supported_slices;
4066*4882a593Smuzhiyun u16 start_slice;
4067*4882a593Smuzhiyun u16 end_slice;
4068*4882a593Smuzhiyun
4069*4882a593Smuzhiyun if (!skl_ddb_entry_size(entry))
4070*4882a593Smuzhiyun return 0;
4071*4882a593Smuzhiyun
4072*4882a593Smuzhiyun start_slice = entry->start / slice_size;
4073*4882a593Smuzhiyun end_slice = (entry->end - 1) / slice_size;
4074*4882a593Smuzhiyun
4075*4882a593Smuzhiyun /*
4076*4882a593Smuzhiyun * Per plane DDB entry can in a really worst case be on multiple slices
4077*4882a593Smuzhiyun * but single entry is anyway contigious.
4078*4882a593Smuzhiyun */
4079*4882a593Smuzhiyun while (start_slice <= end_slice) {
4080*4882a593Smuzhiyun slice_mask |= BIT(start_slice);
4081*4882a593Smuzhiyun start_slice++;
4082*4882a593Smuzhiyun }
4083*4882a593Smuzhiyun
4084*4882a593Smuzhiyun return slice_mask;
4085*4882a593Smuzhiyun }
4086*4882a593Smuzhiyun
4087*4882a593Smuzhiyun static u8 skl_compute_dbuf_slices(const struct intel_crtc_state *crtc_state,
4088*4882a593Smuzhiyun u8 active_pipes);
4089*4882a593Smuzhiyun
4090*4882a593Smuzhiyun static int
skl_ddb_get_pipe_allocation_limits(struct drm_i915_private * dev_priv,const struct intel_crtc_state * crtc_state,const u64 total_data_rate,struct skl_ddb_entry * alloc,int * num_active)4091*4882a593Smuzhiyun skl_ddb_get_pipe_allocation_limits(struct drm_i915_private *dev_priv,
4092*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state,
4093*4882a593Smuzhiyun const u64 total_data_rate,
4094*4882a593Smuzhiyun struct skl_ddb_entry *alloc, /* out */
4095*4882a593Smuzhiyun int *num_active /* out */)
4096*4882a593Smuzhiyun {
4097*4882a593Smuzhiyun struct drm_atomic_state *state = crtc_state->uapi.state;
4098*4882a593Smuzhiyun struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
4099*4882a593Smuzhiyun struct drm_crtc *for_crtc = crtc_state->uapi.crtc;
4100*4882a593Smuzhiyun const struct intel_crtc *crtc;
4101*4882a593Smuzhiyun u32 pipe_width = 0, total_width_in_range = 0, width_before_pipe_in_range = 0;
4102*4882a593Smuzhiyun enum pipe for_pipe = to_intel_crtc(for_crtc)->pipe;
4103*4882a593Smuzhiyun struct intel_dbuf_state *new_dbuf_state =
4104*4882a593Smuzhiyun intel_atomic_get_new_dbuf_state(intel_state);
4105*4882a593Smuzhiyun const struct intel_dbuf_state *old_dbuf_state =
4106*4882a593Smuzhiyun intel_atomic_get_old_dbuf_state(intel_state);
4107*4882a593Smuzhiyun u8 active_pipes = new_dbuf_state->active_pipes;
4108*4882a593Smuzhiyun u16 ddb_size;
4109*4882a593Smuzhiyun u32 ddb_range_size;
4110*4882a593Smuzhiyun u32 i;
4111*4882a593Smuzhiyun u32 dbuf_slice_mask;
4112*4882a593Smuzhiyun u32 offset;
4113*4882a593Smuzhiyun u32 slice_size;
4114*4882a593Smuzhiyun u32 total_slice_mask;
4115*4882a593Smuzhiyun u32 start, end;
4116*4882a593Smuzhiyun int ret;
4117*4882a593Smuzhiyun
4118*4882a593Smuzhiyun *num_active = hweight8(active_pipes);
4119*4882a593Smuzhiyun
4120*4882a593Smuzhiyun if (!crtc_state->hw.active) {
4121*4882a593Smuzhiyun alloc->start = 0;
4122*4882a593Smuzhiyun alloc->end = 0;
4123*4882a593Smuzhiyun return 0;
4124*4882a593Smuzhiyun }
4125*4882a593Smuzhiyun
4126*4882a593Smuzhiyun ddb_size = intel_get_ddb_size(dev_priv);
4127*4882a593Smuzhiyun
4128*4882a593Smuzhiyun slice_size = ddb_size / INTEL_INFO(dev_priv)->num_supported_dbuf_slices;
4129*4882a593Smuzhiyun
4130*4882a593Smuzhiyun /*
4131*4882a593Smuzhiyun * If the state doesn't change the active CRTC's or there is no
4132*4882a593Smuzhiyun * modeset request, then there's no need to recalculate;
4133*4882a593Smuzhiyun * the existing pipe allocation limits should remain unchanged.
4134*4882a593Smuzhiyun * Note that we're safe from racing commits since any racing commit
4135*4882a593Smuzhiyun * that changes the active CRTC list or do modeset would need to
4136*4882a593Smuzhiyun * grab _all_ crtc locks, including the one we currently hold.
4137*4882a593Smuzhiyun */
4138*4882a593Smuzhiyun if (old_dbuf_state->active_pipes == new_dbuf_state->active_pipes &&
4139*4882a593Smuzhiyun !dev_priv->wm.distrust_bios_wm) {
4140*4882a593Smuzhiyun /*
4141*4882a593Smuzhiyun * alloc may be cleared by clear_intel_crtc_state,
4142*4882a593Smuzhiyun * copy from old state to be sure
4143*4882a593Smuzhiyun *
4144*4882a593Smuzhiyun * FIXME get rid of this mess
4145*4882a593Smuzhiyun */
4146*4882a593Smuzhiyun *alloc = to_intel_crtc_state(for_crtc->state)->wm.skl.ddb;
4147*4882a593Smuzhiyun return 0;
4148*4882a593Smuzhiyun }
4149*4882a593Smuzhiyun
4150*4882a593Smuzhiyun /*
4151*4882a593Smuzhiyun * Get allowed DBuf slices for correspondent pipe and platform.
4152*4882a593Smuzhiyun */
4153*4882a593Smuzhiyun dbuf_slice_mask = skl_compute_dbuf_slices(crtc_state, active_pipes);
4154*4882a593Smuzhiyun
4155*4882a593Smuzhiyun /*
4156*4882a593Smuzhiyun * Figure out at which DBuf slice we start, i.e if we start at Dbuf S2
4157*4882a593Smuzhiyun * and slice size is 1024, the offset would be 1024
4158*4882a593Smuzhiyun */
4159*4882a593Smuzhiyun offset = icl_get_first_dbuf_slice_offset(dbuf_slice_mask,
4160*4882a593Smuzhiyun slice_size, ddb_size);
4161*4882a593Smuzhiyun
4162*4882a593Smuzhiyun /*
4163*4882a593Smuzhiyun * Figure out total size of allowed DBuf slices, which is basically
4164*4882a593Smuzhiyun * a number of allowed slices for that pipe multiplied by slice size.
4165*4882a593Smuzhiyun * Inside of this
4166*4882a593Smuzhiyun * range ddb entries are still allocated in proportion to display width.
4167*4882a593Smuzhiyun */
4168*4882a593Smuzhiyun ddb_range_size = hweight8(dbuf_slice_mask) * slice_size;
4169*4882a593Smuzhiyun
4170*4882a593Smuzhiyun /*
4171*4882a593Smuzhiyun * Watermark/ddb requirement highly depends upon width of the
4172*4882a593Smuzhiyun * framebuffer, So instead of allocating DDB equally among pipes
4173*4882a593Smuzhiyun * distribute DDB based on resolution/width of the display.
4174*4882a593Smuzhiyun */
4175*4882a593Smuzhiyun total_slice_mask = dbuf_slice_mask;
4176*4882a593Smuzhiyun for_each_new_intel_crtc_in_state(intel_state, crtc, crtc_state, i) {
4177*4882a593Smuzhiyun const struct drm_display_mode *adjusted_mode =
4178*4882a593Smuzhiyun &crtc_state->hw.adjusted_mode;
4179*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
4180*4882a593Smuzhiyun int hdisplay, vdisplay;
4181*4882a593Smuzhiyun u32 pipe_dbuf_slice_mask;
4182*4882a593Smuzhiyun
4183*4882a593Smuzhiyun if (!crtc_state->hw.active)
4184*4882a593Smuzhiyun continue;
4185*4882a593Smuzhiyun
4186*4882a593Smuzhiyun pipe_dbuf_slice_mask = skl_compute_dbuf_slices(crtc_state,
4187*4882a593Smuzhiyun active_pipes);
4188*4882a593Smuzhiyun
4189*4882a593Smuzhiyun /*
4190*4882a593Smuzhiyun * According to BSpec pipe can share one dbuf slice with another
4191*4882a593Smuzhiyun * pipes or pipe can use multiple dbufs, in both cases we
4192*4882a593Smuzhiyun * account for other pipes only if they have exactly same mask.
4193*4882a593Smuzhiyun * However we need to account how many slices we should enable
4194*4882a593Smuzhiyun * in total.
4195*4882a593Smuzhiyun */
4196*4882a593Smuzhiyun total_slice_mask |= pipe_dbuf_slice_mask;
4197*4882a593Smuzhiyun
4198*4882a593Smuzhiyun /*
4199*4882a593Smuzhiyun * Do not account pipes using other slice sets
4200*4882a593Smuzhiyun * luckily as of current BSpec slice sets do not partially
4201*4882a593Smuzhiyun * intersect(pipes share either same one slice or same slice set
4202*4882a593Smuzhiyun * i.e no partial intersection), so it is enough to check for
4203*4882a593Smuzhiyun * equality for now.
4204*4882a593Smuzhiyun */
4205*4882a593Smuzhiyun if (dbuf_slice_mask != pipe_dbuf_slice_mask)
4206*4882a593Smuzhiyun continue;
4207*4882a593Smuzhiyun
4208*4882a593Smuzhiyun drm_mode_get_hv_timing(adjusted_mode, &hdisplay, &vdisplay);
4209*4882a593Smuzhiyun
4210*4882a593Smuzhiyun total_width_in_range += hdisplay;
4211*4882a593Smuzhiyun
4212*4882a593Smuzhiyun if (pipe < for_pipe)
4213*4882a593Smuzhiyun width_before_pipe_in_range += hdisplay;
4214*4882a593Smuzhiyun else if (pipe == for_pipe)
4215*4882a593Smuzhiyun pipe_width = hdisplay;
4216*4882a593Smuzhiyun }
4217*4882a593Smuzhiyun
4218*4882a593Smuzhiyun /*
4219*4882a593Smuzhiyun * FIXME: For now we always enable slice S1 as per
4220*4882a593Smuzhiyun * the Bspec display initialization sequence.
4221*4882a593Smuzhiyun */
4222*4882a593Smuzhiyun new_dbuf_state->enabled_slices = total_slice_mask | BIT(DBUF_S1);
4223*4882a593Smuzhiyun
4224*4882a593Smuzhiyun if (old_dbuf_state->enabled_slices != new_dbuf_state->enabled_slices) {
4225*4882a593Smuzhiyun ret = intel_atomic_serialize_global_state(&new_dbuf_state->base);
4226*4882a593Smuzhiyun if (ret)
4227*4882a593Smuzhiyun return ret;
4228*4882a593Smuzhiyun }
4229*4882a593Smuzhiyun
4230*4882a593Smuzhiyun start = ddb_range_size * width_before_pipe_in_range / total_width_in_range;
4231*4882a593Smuzhiyun end = ddb_range_size *
4232*4882a593Smuzhiyun (width_before_pipe_in_range + pipe_width) / total_width_in_range;
4233*4882a593Smuzhiyun
4234*4882a593Smuzhiyun alloc->start = offset + start;
4235*4882a593Smuzhiyun alloc->end = offset + end;
4236*4882a593Smuzhiyun
4237*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
4238*4882a593Smuzhiyun "[CRTC:%d:%s] dbuf slices 0x%x, ddb (%d - %d), active pipes 0x%x\n",
4239*4882a593Smuzhiyun for_crtc->base.id, for_crtc->name,
4240*4882a593Smuzhiyun dbuf_slice_mask, alloc->start, alloc->end, active_pipes);
4241*4882a593Smuzhiyun
4242*4882a593Smuzhiyun return 0;
4243*4882a593Smuzhiyun }
4244*4882a593Smuzhiyun
4245*4882a593Smuzhiyun static int skl_compute_wm_params(const struct intel_crtc_state *crtc_state,
4246*4882a593Smuzhiyun int width, const struct drm_format_info *format,
4247*4882a593Smuzhiyun u64 modifier, unsigned int rotation,
4248*4882a593Smuzhiyun u32 plane_pixel_rate, struct skl_wm_params *wp,
4249*4882a593Smuzhiyun int color_plane);
4250*4882a593Smuzhiyun static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state,
4251*4882a593Smuzhiyun int level,
4252*4882a593Smuzhiyun unsigned int latency,
4253*4882a593Smuzhiyun const struct skl_wm_params *wp,
4254*4882a593Smuzhiyun const struct skl_wm_level *result_prev,
4255*4882a593Smuzhiyun struct skl_wm_level *result /* out */);
4256*4882a593Smuzhiyun
4257*4882a593Smuzhiyun static unsigned int
skl_cursor_allocation(const struct intel_crtc_state * crtc_state,int num_active)4258*4882a593Smuzhiyun skl_cursor_allocation(const struct intel_crtc_state *crtc_state,
4259*4882a593Smuzhiyun int num_active)
4260*4882a593Smuzhiyun {
4261*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4262*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
4263*4882a593Smuzhiyun struct skl_wm_level wm = {};
4264*4882a593Smuzhiyun int ret, min_ddb_alloc = 0;
4265*4882a593Smuzhiyun struct skl_wm_params wp;
4266*4882a593Smuzhiyun
4267*4882a593Smuzhiyun ret = skl_compute_wm_params(crtc_state, 256,
4268*4882a593Smuzhiyun drm_format_info(DRM_FORMAT_ARGB8888),
4269*4882a593Smuzhiyun DRM_FORMAT_MOD_LINEAR,
4270*4882a593Smuzhiyun DRM_MODE_ROTATE_0,
4271*4882a593Smuzhiyun crtc_state->pixel_rate, &wp, 0);
4272*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, ret);
4273*4882a593Smuzhiyun
4274*4882a593Smuzhiyun for (level = 0; level <= max_level; level++) {
4275*4882a593Smuzhiyun unsigned int latency = dev_priv->wm.skl_latency[level];
4276*4882a593Smuzhiyun
4277*4882a593Smuzhiyun skl_compute_plane_wm(crtc_state, level, latency, &wp, &wm, &wm);
4278*4882a593Smuzhiyun if (wm.min_ddb_alloc == U16_MAX)
4279*4882a593Smuzhiyun break;
4280*4882a593Smuzhiyun
4281*4882a593Smuzhiyun min_ddb_alloc = wm.min_ddb_alloc;
4282*4882a593Smuzhiyun }
4283*4882a593Smuzhiyun
4284*4882a593Smuzhiyun return max(num_active == 1 ? 32 : 8, min_ddb_alloc);
4285*4882a593Smuzhiyun }
4286*4882a593Smuzhiyun
skl_ddb_entry_init_from_hw(struct drm_i915_private * dev_priv,struct skl_ddb_entry * entry,u32 reg)4287*4882a593Smuzhiyun static void skl_ddb_entry_init_from_hw(struct drm_i915_private *dev_priv,
4288*4882a593Smuzhiyun struct skl_ddb_entry *entry, u32 reg)
4289*4882a593Smuzhiyun {
4290*4882a593Smuzhiyun
4291*4882a593Smuzhiyun entry->start = reg & DDB_ENTRY_MASK;
4292*4882a593Smuzhiyun entry->end = (reg >> DDB_ENTRY_END_SHIFT) & DDB_ENTRY_MASK;
4293*4882a593Smuzhiyun
4294*4882a593Smuzhiyun if (entry->end)
4295*4882a593Smuzhiyun entry->end += 1;
4296*4882a593Smuzhiyun }
4297*4882a593Smuzhiyun
4298*4882a593Smuzhiyun static void
skl_ddb_get_hw_plane_state(struct drm_i915_private * dev_priv,const enum pipe pipe,const enum plane_id plane_id,struct skl_ddb_entry * ddb_y,struct skl_ddb_entry * ddb_uv)4299*4882a593Smuzhiyun skl_ddb_get_hw_plane_state(struct drm_i915_private *dev_priv,
4300*4882a593Smuzhiyun const enum pipe pipe,
4301*4882a593Smuzhiyun const enum plane_id plane_id,
4302*4882a593Smuzhiyun struct skl_ddb_entry *ddb_y,
4303*4882a593Smuzhiyun struct skl_ddb_entry *ddb_uv)
4304*4882a593Smuzhiyun {
4305*4882a593Smuzhiyun u32 val, val2;
4306*4882a593Smuzhiyun u32 fourcc = 0;
4307*4882a593Smuzhiyun
4308*4882a593Smuzhiyun /* Cursor doesn't support NV12/planar, so no extra calculation needed */
4309*4882a593Smuzhiyun if (plane_id == PLANE_CURSOR) {
4310*4882a593Smuzhiyun val = I915_READ(CUR_BUF_CFG(pipe));
4311*4882a593Smuzhiyun skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val);
4312*4882a593Smuzhiyun return;
4313*4882a593Smuzhiyun }
4314*4882a593Smuzhiyun
4315*4882a593Smuzhiyun val = I915_READ(PLANE_CTL(pipe, plane_id));
4316*4882a593Smuzhiyun
4317*4882a593Smuzhiyun /* No DDB allocated for disabled planes */
4318*4882a593Smuzhiyun if (val & PLANE_CTL_ENABLE)
4319*4882a593Smuzhiyun fourcc = skl_format_to_fourcc(val & PLANE_CTL_FORMAT_MASK,
4320*4882a593Smuzhiyun val & PLANE_CTL_ORDER_RGBX,
4321*4882a593Smuzhiyun val & PLANE_CTL_ALPHA_MASK);
4322*4882a593Smuzhiyun
4323*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 11) {
4324*4882a593Smuzhiyun val = I915_READ(PLANE_BUF_CFG(pipe, plane_id));
4325*4882a593Smuzhiyun skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val);
4326*4882a593Smuzhiyun } else {
4327*4882a593Smuzhiyun val = I915_READ(PLANE_BUF_CFG(pipe, plane_id));
4328*4882a593Smuzhiyun val2 = I915_READ(PLANE_NV12_BUF_CFG(pipe, plane_id));
4329*4882a593Smuzhiyun
4330*4882a593Smuzhiyun if (fourcc &&
4331*4882a593Smuzhiyun drm_format_info_is_yuv_semiplanar(drm_format_info(fourcc)))
4332*4882a593Smuzhiyun swap(val, val2);
4333*4882a593Smuzhiyun
4334*4882a593Smuzhiyun skl_ddb_entry_init_from_hw(dev_priv, ddb_y, val);
4335*4882a593Smuzhiyun skl_ddb_entry_init_from_hw(dev_priv, ddb_uv, val2);
4336*4882a593Smuzhiyun }
4337*4882a593Smuzhiyun }
4338*4882a593Smuzhiyun
skl_pipe_ddb_get_hw_state(struct intel_crtc * crtc,struct skl_ddb_entry * ddb_y,struct skl_ddb_entry * ddb_uv)4339*4882a593Smuzhiyun void skl_pipe_ddb_get_hw_state(struct intel_crtc *crtc,
4340*4882a593Smuzhiyun struct skl_ddb_entry *ddb_y,
4341*4882a593Smuzhiyun struct skl_ddb_entry *ddb_uv)
4342*4882a593Smuzhiyun {
4343*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4344*4882a593Smuzhiyun enum intel_display_power_domain power_domain;
4345*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
4346*4882a593Smuzhiyun intel_wakeref_t wakeref;
4347*4882a593Smuzhiyun enum plane_id plane_id;
4348*4882a593Smuzhiyun
4349*4882a593Smuzhiyun power_domain = POWER_DOMAIN_PIPE(pipe);
4350*4882a593Smuzhiyun wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
4351*4882a593Smuzhiyun if (!wakeref)
4352*4882a593Smuzhiyun return;
4353*4882a593Smuzhiyun
4354*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id)
4355*4882a593Smuzhiyun skl_ddb_get_hw_plane_state(dev_priv, pipe,
4356*4882a593Smuzhiyun plane_id,
4357*4882a593Smuzhiyun &ddb_y[plane_id],
4358*4882a593Smuzhiyun &ddb_uv[plane_id]);
4359*4882a593Smuzhiyun
4360*4882a593Smuzhiyun intel_display_power_put(dev_priv, power_domain, wakeref);
4361*4882a593Smuzhiyun }
4362*4882a593Smuzhiyun
4363*4882a593Smuzhiyun /*
4364*4882a593Smuzhiyun * Determines the downscale amount of a plane for the purposes of watermark calculations.
4365*4882a593Smuzhiyun * The bspec defines downscale amount as:
4366*4882a593Smuzhiyun *
4367*4882a593Smuzhiyun * """
4368*4882a593Smuzhiyun * Horizontal down scale amount = maximum[1, Horizontal source size /
4369*4882a593Smuzhiyun * Horizontal destination size]
4370*4882a593Smuzhiyun * Vertical down scale amount = maximum[1, Vertical source size /
4371*4882a593Smuzhiyun * Vertical destination size]
4372*4882a593Smuzhiyun * Total down scale amount = Horizontal down scale amount *
4373*4882a593Smuzhiyun * Vertical down scale amount
4374*4882a593Smuzhiyun * """
4375*4882a593Smuzhiyun *
4376*4882a593Smuzhiyun * Return value is provided in 16.16 fixed point form to retain fractional part.
4377*4882a593Smuzhiyun * Caller should take care of dividing & rounding off the value.
4378*4882a593Smuzhiyun */
4379*4882a593Smuzhiyun static uint_fixed_16_16_t
skl_plane_downscale_amount(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)4380*4882a593Smuzhiyun skl_plane_downscale_amount(const struct intel_crtc_state *crtc_state,
4381*4882a593Smuzhiyun const struct intel_plane_state *plane_state)
4382*4882a593Smuzhiyun {
4383*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
4384*4882a593Smuzhiyun u32 src_w, src_h, dst_w, dst_h;
4385*4882a593Smuzhiyun uint_fixed_16_16_t fp_w_ratio, fp_h_ratio;
4386*4882a593Smuzhiyun uint_fixed_16_16_t downscale_h, downscale_w;
4387*4882a593Smuzhiyun
4388*4882a593Smuzhiyun if (drm_WARN_ON(&dev_priv->drm,
4389*4882a593Smuzhiyun !intel_wm_plane_visible(crtc_state, plane_state)))
4390*4882a593Smuzhiyun return u32_to_fixed16(0);
4391*4882a593Smuzhiyun
4392*4882a593Smuzhiyun /*
4393*4882a593Smuzhiyun * Src coordinates are already rotated by 270 degrees for
4394*4882a593Smuzhiyun * the 90/270 degree plane rotation cases (to match the
4395*4882a593Smuzhiyun * GTT mapping), hence no need to account for rotation here.
4396*4882a593Smuzhiyun *
4397*4882a593Smuzhiyun * n.b., src is 16.16 fixed point, dst is whole integer.
4398*4882a593Smuzhiyun */
4399*4882a593Smuzhiyun src_w = drm_rect_width(&plane_state->uapi.src) >> 16;
4400*4882a593Smuzhiyun src_h = drm_rect_height(&plane_state->uapi.src) >> 16;
4401*4882a593Smuzhiyun dst_w = drm_rect_width(&plane_state->uapi.dst);
4402*4882a593Smuzhiyun dst_h = drm_rect_height(&plane_state->uapi.dst);
4403*4882a593Smuzhiyun
4404*4882a593Smuzhiyun fp_w_ratio = div_fixed16(src_w, dst_w);
4405*4882a593Smuzhiyun fp_h_ratio = div_fixed16(src_h, dst_h);
4406*4882a593Smuzhiyun downscale_w = max_fixed16(fp_w_ratio, u32_to_fixed16(1));
4407*4882a593Smuzhiyun downscale_h = max_fixed16(fp_h_ratio, u32_to_fixed16(1));
4408*4882a593Smuzhiyun
4409*4882a593Smuzhiyun return mul_fixed16(downscale_w, downscale_h);
4410*4882a593Smuzhiyun }
4411*4882a593Smuzhiyun
4412*4882a593Smuzhiyun struct dbuf_slice_conf_entry {
4413*4882a593Smuzhiyun u8 active_pipes;
4414*4882a593Smuzhiyun u8 dbuf_mask[I915_MAX_PIPES];
4415*4882a593Smuzhiyun };
4416*4882a593Smuzhiyun
4417*4882a593Smuzhiyun /*
4418*4882a593Smuzhiyun * Table taken from Bspec 12716
4419*4882a593Smuzhiyun * Pipes do have some preferred DBuf slice affinity,
4420*4882a593Smuzhiyun * plus there are some hardcoded requirements on how
4421*4882a593Smuzhiyun * those should be distributed for multipipe scenarios.
4422*4882a593Smuzhiyun * For more DBuf slices algorithm can get even more messy
4423*4882a593Smuzhiyun * and less readable, so decided to use a table almost
4424*4882a593Smuzhiyun * as is from BSpec itself - that way it is at least easier
4425*4882a593Smuzhiyun * to compare, change and check.
4426*4882a593Smuzhiyun */
4427*4882a593Smuzhiyun static const struct dbuf_slice_conf_entry icl_allowed_dbufs[] =
4428*4882a593Smuzhiyun /* Autogenerated with igt/tools/intel_dbuf_map tool: */
4429*4882a593Smuzhiyun {
4430*4882a593Smuzhiyun {
4431*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A),
4432*4882a593Smuzhiyun .dbuf_mask = {
4433*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4434*4882a593Smuzhiyun },
4435*4882a593Smuzhiyun },
4436*4882a593Smuzhiyun {
4437*4882a593Smuzhiyun .active_pipes = BIT(PIPE_B),
4438*4882a593Smuzhiyun .dbuf_mask = {
4439*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4440*4882a593Smuzhiyun },
4441*4882a593Smuzhiyun },
4442*4882a593Smuzhiyun {
4443*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_B),
4444*4882a593Smuzhiyun .dbuf_mask = {
4445*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4446*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S2),
4447*4882a593Smuzhiyun },
4448*4882a593Smuzhiyun },
4449*4882a593Smuzhiyun {
4450*4882a593Smuzhiyun .active_pipes = BIT(PIPE_C),
4451*4882a593Smuzhiyun .dbuf_mask = {
4452*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4453*4882a593Smuzhiyun },
4454*4882a593Smuzhiyun },
4455*4882a593Smuzhiyun {
4456*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_C),
4457*4882a593Smuzhiyun .dbuf_mask = {
4458*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4459*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4460*4882a593Smuzhiyun },
4461*4882a593Smuzhiyun },
4462*4882a593Smuzhiyun {
4463*4882a593Smuzhiyun .active_pipes = BIT(PIPE_B) | BIT(PIPE_C),
4464*4882a593Smuzhiyun .dbuf_mask = {
4465*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4466*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4467*4882a593Smuzhiyun },
4468*4882a593Smuzhiyun },
4469*4882a593Smuzhiyun {
4470*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C),
4471*4882a593Smuzhiyun .dbuf_mask = {
4472*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4473*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4474*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4475*4882a593Smuzhiyun },
4476*4882a593Smuzhiyun },
4477*4882a593Smuzhiyun {}
4478*4882a593Smuzhiyun };
4479*4882a593Smuzhiyun
4480*4882a593Smuzhiyun /*
4481*4882a593Smuzhiyun * Table taken from Bspec 49255
4482*4882a593Smuzhiyun * Pipes do have some preferred DBuf slice affinity,
4483*4882a593Smuzhiyun * plus there are some hardcoded requirements on how
4484*4882a593Smuzhiyun * those should be distributed for multipipe scenarios.
4485*4882a593Smuzhiyun * For more DBuf slices algorithm can get even more messy
4486*4882a593Smuzhiyun * and less readable, so decided to use a table almost
4487*4882a593Smuzhiyun * as is from BSpec itself - that way it is at least easier
4488*4882a593Smuzhiyun * to compare, change and check.
4489*4882a593Smuzhiyun */
4490*4882a593Smuzhiyun static const struct dbuf_slice_conf_entry tgl_allowed_dbufs[] =
4491*4882a593Smuzhiyun /* Autogenerated with igt/tools/intel_dbuf_map tool: */
4492*4882a593Smuzhiyun {
4493*4882a593Smuzhiyun {
4494*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A),
4495*4882a593Smuzhiyun .dbuf_mask = {
4496*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1) | BIT(DBUF_S2),
4497*4882a593Smuzhiyun },
4498*4882a593Smuzhiyun },
4499*4882a593Smuzhiyun {
4500*4882a593Smuzhiyun .active_pipes = BIT(PIPE_B),
4501*4882a593Smuzhiyun .dbuf_mask = {
4502*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1) | BIT(DBUF_S2),
4503*4882a593Smuzhiyun },
4504*4882a593Smuzhiyun },
4505*4882a593Smuzhiyun {
4506*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_B),
4507*4882a593Smuzhiyun .dbuf_mask = {
4508*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S2),
4509*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4510*4882a593Smuzhiyun },
4511*4882a593Smuzhiyun },
4512*4882a593Smuzhiyun {
4513*4882a593Smuzhiyun .active_pipes = BIT(PIPE_C),
4514*4882a593Smuzhiyun .dbuf_mask = {
4515*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2) | BIT(DBUF_S1),
4516*4882a593Smuzhiyun },
4517*4882a593Smuzhiyun },
4518*4882a593Smuzhiyun {
4519*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_C),
4520*4882a593Smuzhiyun .dbuf_mask = {
4521*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4522*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4523*4882a593Smuzhiyun },
4524*4882a593Smuzhiyun },
4525*4882a593Smuzhiyun {
4526*4882a593Smuzhiyun .active_pipes = BIT(PIPE_B) | BIT(PIPE_C),
4527*4882a593Smuzhiyun .dbuf_mask = {
4528*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4529*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4530*4882a593Smuzhiyun },
4531*4882a593Smuzhiyun },
4532*4882a593Smuzhiyun {
4533*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C),
4534*4882a593Smuzhiyun .dbuf_mask = {
4535*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4536*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4537*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4538*4882a593Smuzhiyun },
4539*4882a593Smuzhiyun },
4540*4882a593Smuzhiyun {
4541*4882a593Smuzhiyun .active_pipes = BIT(PIPE_D),
4542*4882a593Smuzhiyun .dbuf_mask = {
4543*4882a593Smuzhiyun [PIPE_D] = BIT(DBUF_S2) | BIT(DBUF_S1),
4544*4882a593Smuzhiyun },
4545*4882a593Smuzhiyun },
4546*4882a593Smuzhiyun {
4547*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_D),
4548*4882a593Smuzhiyun .dbuf_mask = {
4549*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4550*4882a593Smuzhiyun [PIPE_D] = BIT(DBUF_S2),
4551*4882a593Smuzhiyun },
4552*4882a593Smuzhiyun },
4553*4882a593Smuzhiyun {
4554*4882a593Smuzhiyun .active_pipes = BIT(PIPE_B) | BIT(PIPE_D),
4555*4882a593Smuzhiyun .dbuf_mask = {
4556*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4557*4882a593Smuzhiyun [PIPE_D] = BIT(DBUF_S2),
4558*4882a593Smuzhiyun },
4559*4882a593Smuzhiyun },
4560*4882a593Smuzhiyun {
4561*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_D),
4562*4882a593Smuzhiyun .dbuf_mask = {
4563*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4564*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4565*4882a593Smuzhiyun [PIPE_D] = BIT(DBUF_S2),
4566*4882a593Smuzhiyun },
4567*4882a593Smuzhiyun },
4568*4882a593Smuzhiyun {
4569*4882a593Smuzhiyun .active_pipes = BIT(PIPE_C) | BIT(PIPE_D),
4570*4882a593Smuzhiyun .dbuf_mask = {
4571*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S1),
4572*4882a593Smuzhiyun [PIPE_D] = BIT(DBUF_S2),
4573*4882a593Smuzhiyun },
4574*4882a593Smuzhiyun },
4575*4882a593Smuzhiyun {
4576*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_C) | BIT(PIPE_D),
4577*4882a593Smuzhiyun .dbuf_mask = {
4578*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4579*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4580*4882a593Smuzhiyun [PIPE_D] = BIT(DBUF_S2),
4581*4882a593Smuzhiyun },
4582*4882a593Smuzhiyun },
4583*4882a593Smuzhiyun {
4584*4882a593Smuzhiyun .active_pipes = BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
4585*4882a593Smuzhiyun .dbuf_mask = {
4586*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4587*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4588*4882a593Smuzhiyun [PIPE_D] = BIT(DBUF_S2),
4589*4882a593Smuzhiyun },
4590*4882a593Smuzhiyun },
4591*4882a593Smuzhiyun {
4592*4882a593Smuzhiyun .active_pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
4593*4882a593Smuzhiyun .dbuf_mask = {
4594*4882a593Smuzhiyun [PIPE_A] = BIT(DBUF_S1),
4595*4882a593Smuzhiyun [PIPE_B] = BIT(DBUF_S1),
4596*4882a593Smuzhiyun [PIPE_C] = BIT(DBUF_S2),
4597*4882a593Smuzhiyun [PIPE_D] = BIT(DBUF_S2),
4598*4882a593Smuzhiyun },
4599*4882a593Smuzhiyun },
4600*4882a593Smuzhiyun {}
4601*4882a593Smuzhiyun };
4602*4882a593Smuzhiyun
compute_dbuf_slices(enum pipe pipe,u8 active_pipes,const struct dbuf_slice_conf_entry * dbuf_slices)4603*4882a593Smuzhiyun static u8 compute_dbuf_slices(enum pipe pipe, u8 active_pipes,
4604*4882a593Smuzhiyun const struct dbuf_slice_conf_entry *dbuf_slices)
4605*4882a593Smuzhiyun {
4606*4882a593Smuzhiyun int i;
4607*4882a593Smuzhiyun
4608*4882a593Smuzhiyun for (i = 0; i < dbuf_slices[i].active_pipes; i++) {
4609*4882a593Smuzhiyun if (dbuf_slices[i].active_pipes == active_pipes)
4610*4882a593Smuzhiyun return dbuf_slices[i].dbuf_mask[pipe];
4611*4882a593Smuzhiyun }
4612*4882a593Smuzhiyun return 0;
4613*4882a593Smuzhiyun }
4614*4882a593Smuzhiyun
4615*4882a593Smuzhiyun /*
4616*4882a593Smuzhiyun * This function finds an entry with same enabled pipe configuration and
4617*4882a593Smuzhiyun * returns correspondent DBuf slice mask as stated in BSpec for particular
4618*4882a593Smuzhiyun * platform.
4619*4882a593Smuzhiyun */
icl_compute_dbuf_slices(enum pipe pipe,u8 active_pipes)4620*4882a593Smuzhiyun static u8 icl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes)
4621*4882a593Smuzhiyun {
4622*4882a593Smuzhiyun /*
4623*4882a593Smuzhiyun * FIXME: For ICL this is still a bit unclear as prev BSpec revision
4624*4882a593Smuzhiyun * required calculating "pipe ratio" in order to determine
4625*4882a593Smuzhiyun * if one or two slices can be used for single pipe configurations
4626*4882a593Smuzhiyun * as additional constraint to the existing table.
4627*4882a593Smuzhiyun * However based on recent info, it should be not "pipe ratio"
4628*4882a593Smuzhiyun * but rather ratio between pixel_rate and cdclk with additional
4629*4882a593Smuzhiyun * constants, so for now we are using only table until this is
4630*4882a593Smuzhiyun * clarified. Also this is the reason why crtc_state param is
4631*4882a593Smuzhiyun * still here - we will need it once those additional constraints
4632*4882a593Smuzhiyun * pop up.
4633*4882a593Smuzhiyun */
4634*4882a593Smuzhiyun return compute_dbuf_slices(pipe, active_pipes, icl_allowed_dbufs);
4635*4882a593Smuzhiyun }
4636*4882a593Smuzhiyun
tgl_compute_dbuf_slices(enum pipe pipe,u8 active_pipes)4637*4882a593Smuzhiyun static u8 tgl_compute_dbuf_slices(enum pipe pipe, u8 active_pipes)
4638*4882a593Smuzhiyun {
4639*4882a593Smuzhiyun return compute_dbuf_slices(pipe, active_pipes, tgl_allowed_dbufs);
4640*4882a593Smuzhiyun }
4641*4882a593Smuzhiyun
skl_compute_dbuf_slices(const struct intel_crtc_state * crtc_state,u8 active_pipes)4642*4882a593Smuzhiyun static u8 skl_compute_dbuf_slices(const struct intel_crtc_state *crtc_state,
4643*4882a593Smuzhiyun u8 active_pipes)
4644*4882a593Smuzhiyun {
4645*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4646*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4647*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
4648*4882a593Smuzhiyun
4649*4882a593Smuzhiyun if (IS_GEN(dev_priv, 12))
4650*4882a593Smuzhiyun return tgl_compute_dbuf_slices(pipe, active_pipes);
4651*4882a593Smuzhiyun else if (IS_GEN(dev_priv, 11))
4652*4882a593Smuzhiyun return icl_compute_dbuf_slices(pipe, active_pipes);
4653*4882a593Smuzhiyun /*
4654*4882a593Smuzhiyun * For anything else just return one slice yet.
4655*4882a593Smuzhiyun * Should be extended for other platforms.
4656*4882a593Smuzhiyun */
4657*4882a593Smuzhiyun return active_pipes & BIT(pipe) ? BIT(DBUF_S1) : 0;
4658*4882a593Smuzhiyun }
4659*4882a593Smuzhiyun
4660*4882a593Smuzhiyun static u64
skl_plane_relative_data_rate(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,int color_plane)4661*4882a593Smuzhiyun skl_plane_relative_data_rate(const struct intel_crtc_state *crtc_state,
4662*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
4663*4882a593Smuzhiyun int color_plane)
4664*4882a593Smuzhiyun {
4665*4882a593Smuzhiyun struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
4666*4882a593Smuzhiyun const struct drm_framebuffer *fb = plane_state->hw.fb;
4667*4882a593Smuzhiyun u32 data_rate;
4668*4882a593Smuzhiyun u32 width = 0, height = 0;
4669*4882a593Smuzhiyun uint_fixed_16_16_t down_scale_amount;
4670*4882a593Smuzhiyun u64 rate;
4671*4882a593Smuzhiyun
4672*4882a593Smuzhiyun if (!plane_state->uapi.visible)
4673*4882a593Smuzhiyun return 0;
4674*4882a593Smuzhiyun
4675*4882a593Smuzhiyun if (plane->id == PLANE_CURSOR)
4676*4882a593Smuzhiyun return 0;
4677*4882a593Smuzhiyun
4678*4882a593Smuzhiyun if (color_plane == 1 &&
4679*4882a593Smuzhiyun !intel_format_info_is_yuv_semiplanar(fb->format, fb->modifier))
4680*4882a593Smuzhiyun return 0;
4681*4882a593Smuzhiyun
4682*4882a593Smuzhiyun /*
4683*4882a593Smuzhiyun * Src coordinates are already rotated by 270 degrees for
4684*4882a593Smuzhiyun * the 90/270 degree plane rotation cases (to match the
4685*4882a593Smuzhiyun * GTT mapping), hence no need to account for rotation here.
4686*4882a593Smuzhiyun */
4687*4882a593Smuzhiyun width = drm_rect_width(&plane_state->uapi.src) >> 16;
4688*4882a593Smuzhiyun height = drm_rect_height(&plane_state->uapi.src) >> 16;
4689*4882a593Smuzhiyun
4690*4882a593Smuzhiyun /* UV plane does 1/2 pixel sub-sampling */
4691*4882a593Smuzhiyun if (color_plane == 1) {
4692*4882a593Smuzhiyun width /= 2;
4693*4882a593Smuzhiyun height /= 2;
4694*4882a593Smuzhiyun }
4695*4882a593Smuzhiyun
4696*4882a593Smuzhiyun data_rate = width * height;
4697*4882a593Smuzhiyun
4698*4882a593Smuzhiyun down_scale_amount = skl_plane_downscale_amount(crtc_state, plane_state);
4699*4882a593Smuzhiyun
4700*4882a593Smuzhiyun rate = mul_round_up_u32_fixed16(data_rate, down_scale_amount);
4701*4882a593Smuzhiyun
4702*4882a593Smuzhiyun rate *= fb->format->cpp[color_plane];
4703*4882a593Smuzhiyun return rate;
4704*4882a593Smuzhiyun }
4705*4882a593Smuzhiyun
4706*4882a593Smuzhiyun static u64
skl_get_total_relative_data_rate(struct intel_crtc_state * crtc_state,u64 * plane_data_rate,u64 * uv_plane_data_rate)4707*4882a593Smuzhiyun skl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state,
4708*4882a593Smuzhiyun u64 *plane_data_rate,
4709*4882a593Smuzhiyun u64 *uv_plane_data_rate)
4710*4882a593Smuzhiyun {
4711*4882a593Smuzhiyun struct intel_plane *plane;
4712*4882a593Smuzhiyun const struct intel_plane_state *plane_state;
4713*4882a593Smuzhiyun u64 total_data_rate = 0;
4714*4882a593Smuzhiyun
4715*4882a593Smuzhiyun /* Calculate and cache data rate for each plane */
4716*4882a593Smuzhiyun intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
4717*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
4718*4882a593Smuzhiyun u64 rate;
4719*4882a593Smuzhiyun
4720*4882a593Smuzhiyun /* packed/y */
4721*4882a593Smuzhiyun rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0);
4722*4882a593Smuzhiyun plane_data_rate[plane_id] = rate;
4723*4882a593Smuzhiyun total_data_rate += rate;
4724*4882a593Smuzhiyun
4725*4882a593Smuzhiyun /* uv-plane */
4726*4882a593Smuzhiyun rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1);
4727*4882a593Smuzhiyun uv_plane_data_rate[plane_id] = rate;
4728*4882a593Smuzhiyun total_data_rate += rate;
4729*4882a593Smuzhiyun }
4730*4882a593Smuzhiyun
4731*4882a593Smuzhiyun return total_data_rate;
4732*4882a593Smuzhiyun }
4733*4882a593Smuzhiyun
4734*4882a593Smuzhiyun static u64
icl_get_total_relative_data_rate(struct intel_crtc_state * crtc_state,u64 * plane_data_rate)4735*4882a593Smuzhiyun icl_get_total_relative_data_rate(struct intel_crtc_state *crtc_state,
4736*4882a593Smuzhiyun u64 *plane_data_rate)
4737*4882a593Smuzhiyun {
4738*4882a593Smuzhiyun struct intel_plane *plane;
4739*4882a593Smuzhiyun const struct intel_plane_state *plane_state;
4740*4882a593Smuzhiyun u64 total_data_rate = 0;
4741*4882a593Smuzhiyun
4742*4882a593Smuzhiyun /* Calculate and cache data rate for each plane */
4743*4882a593Smuzhiyun intel_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) {
4744*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
4745*4882a593Smuzhiyun u64 rate;
4746*4882a593Smuzhiyun
4747*4882a593Smuzhiyun if (!plane_state->planar_linked_plane) {
4748*4882a593Smuzhiyun rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0);
4749*4882a593Smuzhiyun plane_data_rate[plane_id] = rate;
4750*4882a593Smuzhiyun total_data_rate += rate;
4751*4882a593Smuzhiyun } else {
4752*4882a593Smuzhiyun enum plane_id y_plane_id;
4753*4882a593Smuzhiyun
4754*4882a593Smuzhiyun /*
4755*4882a593Smuzhiyun * The slave plane might not iterate in
4756*4882a593Smuzhiyun * intel_atomic_crtc_state_for_each_plane_state(),
4757*4882a593Smuzhiyun * and needs the master plane state which may be
4758*4882a593Smuzhiyun * NULL if we try get_new_plane_state(), so we
4759*4882a593Smuzhiyun * always calculate from the master.
4760*4882a593Smuzhiyun */
4761*4882a593Smuzhiyun if (plane_state->planar_slave)
4762*4882a593Smuzhiyun continue;
4763*4882a593Smuzhiyun
4764*4882a593Smuzhiyun /* Y plane rate is calculated on the slave */
4765*4882a593Smuzhiyun rate = skl_plane_relative_data_rate(crtc_state, plane_state, 0);
4766*4882a593Smuzhiyun y_plane_id = plane_state->planar_linked_plane->id;
4767*4882a593Smuzhiyun plane_data_rate[y_plane_id] = rate;
4768*4882a593Smuzhiyun total_data_rate += rate;
4769*4882a593Smuzhiyun
4770*4882a593Smuzhiyun rate = skl_plane_relative_data_rate(crtc_state, plane_state, 1);
4771*4882a593Smuzhiyun plane_data_rate[plane_id] = rate;
4772*4882a593Smuzhiyun total_data_rate += rate;
4773*4882a593Smuzhiyun }
4774*4882a593Smuzhiyun }
4775*4882a593Smuzhiyun
4776*4882a593Smuzhiyun return total_data_rate;
4777*4882a593Smuzhiyun }
4778*4882a593Smuzhiyun
4779*4882a593Smuzhiyun static const struct skl_wm_level *
skl_plane_wm_level(const struct intel_crtc_state * crtc_state,enum plane_id plane_id,int level)4780*4882a593Smuzhiyun skl_plane_wm_level(const struct intel_crtc_state *crtc_state,
4781*4882a593Smuzhiyun enum plane_id plane_id,
4782*4882a593Smuzhiyun int level)
4783*4882a593Smuzhiyun {
4784*4882a593Smuzhiyun const struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal;
4785*4882a593Smuzhiyun const struct skl_plane_wm *wm = &pipe_wm->planes[plane_id];
4786*4882a593Smuzhiyun
4787*4882a593Smuzhiyun if (level == 0 && pipe_wm->use_sagv_wm)
4788*4882a593Smuzhiyun return &wm->sagv_wm0;
4789*4882a593Smuzhiyun
4790*4882a593Smuzhiyun return &wm->wm[level];
4791*4882a593Smuzhiyun }
4792*4882a593Smuzhiyun
4793*4882a593Smuzhiyun static int
skl_allocate_pipe_ddb(struct intel_crtc_state * crtc_state)4794*4882a593Smuzhiyun skl_allocate_pipe_ddb(struct intel_crtc_state *crtc_state)
4795*4882a593Smuzhiyun {
4796*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4797*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4798*4882a593Smuzhiyun struct skl_ddb_entry *alloc = &crtc_state->wm.skl.ddb;
4799*4882a593Smuzhiyun u16 alloc_size, start = 0;
4800*4882a593Smuzhiyun u16 total[I915_MAX_PLANES] = {};
4801*4882a593Smuzhiyun u16 uv_total[I915_MAX_PLANES] = {};
4802*4882a593Smuzhiyun u64 total_data_rate;
4803*4882a593Smuzhiyun enum plane_id plane_id;
4804*4882a593Smuzhiyun int num_active;
4805*4882a593Smuzhiyun u64 plane_data_rate[I915_MAX_PLANES] = {};
4806*4882a593Smuzhiyun u64 uv_plane_data_rate[I915_MAX_PLANES] = {};
4807*4882a593Smuzhiyun u32 blocks;
4808*4882a593Smuzhiyun int level;
4809*4882a593Smuzhiyun int ret;
4810*4882a593Smuzhiyun
4811*4882a593Smuzhiyun /* Clear the partitioning for disabled planes. */
4812*4882a593Smuzhiyun memset(crtc_state->wm.skl.plane_ddb_y, 0, sizeof(crtc_state->wm.skl.plane_ddb_y));
4813*4882a593Smuzhiyun memset(crtc_state->wm.skl.plane_ddb_uv, 0, sizeof(crtc_state->wm.skl.plane_ddb_uv));
4814*4882a593Smuzhiyun
4815*4882a593Smuzhiyun if (!crtc_state->hw.active) {
4816*4882a593Smuzhiyun struct intel_atomic_state *state =
4817*4882a593Smuzhiyun to_intel_atomic_state(crtc_state->uapi.state);
4818*4882a593Smuzhiyun struct intel_dbuf_state *new_dbuf_state =
4819*4882a593Smuzhiyun intel_atomic_get_new_dbuf_state(state);
4820*4882a593Smuzhiyun const struct intel_dbuf_state *old_dbuf_state =
4821*4882a593Smuzhiyun intel_atomic_get_old_dbuf_state(state);
4822*4882a593Smuzhiyun
4823*4882a593Smuzhiyun /*
4824*4882a593Smuzhiyun * FIXME hack to make sure we compute this sensibly when
4825*4882a593Smuzhiyun * turning off all the pipes. Otherwise we leave it at
4826*4882a593Smuzhiyun * whatever we had previously, and then runtime PM will
4827*4882a593Smuzhiyun * mess it up by turning off all but S1. Remove this
4828*4882a593Smuzhiyun * once the dbuf state computation flow becomes sane.
4829*4882a593Smuzhiyun */
4830*4882a593Smuzhiyun if (new_dbuf_state->active_pipes == 0) {
4831*4882a593Smuzhiyun new_dbuf_state->enabled_slices = BIT(DBUF_S1);
4832*4882a593Smuzhiyun
4833*4882a593Smuzhiyun if (old_dbuf_state->enabled_slices != new_dbuf_state->enabled_slices) {
4834*4882a593Smuzhiyun ret = intel_atomic_serialize_global_state(&new_dbuf_state->base);
4835*4882a593Smuzhiyun if (ret)
4836*4882a593Smuzhiyun return ret;
4837*4882a593Smuzhiyun }
4838*4882a593Smuzhiyun }
4839*4882a593Smuzhiyun
4840*4882a593Smuzhiyun alloc->start = alloc->end = 0;
4841*4882a593Smuzhiyun return 0;
4842*4882a593Smuzhiyun }
4843*4882a593Smuzhiyun
4844*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 11)
4845*4882a593Smuzhiyun total_data_rate =
4846*4882a593Smuzhiyun icl_get_total_relative_data_rate(crtc_state,
4847*4882a593Smuzhiyun plane_data_rate);
4848*4882a593Smuzhiyun else
4849*4882a593Smuzhiyun total_data_rate =
4850*4882a593Smuzhiyun skl_get_total_relative_data_rate(crtc_state,
4851*4882a593Smuzhiyun plane_data_rate,
4852*4882a593Smuzhiyun uv_plane_data_rate);
4853*4882a593Smuzhiyun
4854*4882a593Smuzhiyun ret = skl_ddb_get_pipe_allocation_limits(dev_priv, crtc_state,
4855*4882a593Smuzhiyun total_data_rate,
4856*4882a593Smuzhiyun alloc, &num_active);
4857*4882a593Smuzhiyun if (ret)
4858*4882a593Smuzhiyun return ret;
4859*4882a593Smuzhiyun
4860*4882a593Smuzhiyun alloc_size = skl_ddb_entry_size(alloc);
4861*4882a593Smuzhiyun if (alloc_size == 0)
4862*4882a593Smuzhiyun return 0;
4863*4882a593Smuzhiyun
4864*4882a593Smuzhiyun /* Allocate fixed number of blocks for cursor. */
4865*4882a593Smuzhiyun total[PLANE_CURSOR] = skl_cursor_allocation(crtc_state, num_active);
4866*4882a593Smuzhiyun alloc_size -= total[PLANE_CURSOR];
4867*4882a593Smuzhiyun crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].start =
4868*4882a593Smuzhiyun alloc->end - total[PLANE_CURSOR];
4869*4882a593Smuzhiyun crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR].end = alloc->end;
4870*4882a593Smuzhiyun
4871*4882a593Smuzhiyun if (total_data_rate == 0)
4872*4882a593Smuzhiyun return 0;
4873*4882a593Smuzhiyun
4874*4882a593Smuzhiyun /*
4875*4882a593Smuzhiyun * Find the highest watermark level for which we can satisfy the block
4876*4882a593Smuzhiyun * requirement of active planes.
4877*4882a593Smuzhiyun */
4878*4882a593Smuzhiyun for (level = ilk_wm_max_level(dev_priv); level >= 0; level--) {
4879*4882a593Smuzhiyun blocks = 0;
4880*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
4881*4882a593Smuzhiyun const struct skl_plane_wm *wm =
4882*4882a593Smuzhiyun &crtc_state->wm.skl.optimal.planes[plane_id];
4883*4882a593Smuzhiyun
4884*4882a593Smuzhiyun if (plane_id == PLANE_CURSOR) {
4885*4882a593Smuzhiyun if (wm->wm[level].min_ddb_alloc > total[PLANE_CURSOR]) {
4886*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm,
4887*4882a593Smuzhiyun wm->wm[level].min_ddb_alloc != U16_MAX);
4888*4882a593Smuzhiyun blocks = U32_MAX;
4889*4882a593Smuzhiyun break;
4890*4882a593Smuzhiyun }
4891*4882a593Smuzhiyun continue;
4892*4882a593Smuzhiyun }
4893*4882a593Smuzhiyun
4894*4882a593Smuzhiyun blocks += wm->wm[level].min_ddb_alloc;
4895*4882a593Smuzhiyun blocks += wm->uv_wm[level].min_ddb_alloc;
4896*4882a593Smuzhiyun }
4897*4882a593Smuzhiyun
4898*4882a593Smuzhiyun if (blocks <= alloc_size) {
4899*4882a593Smuzhiyun alloc_size -= blocks;
4900*4882a593Smuzhiyun break;
4901*4882a593Smuzhiyun }
4902*4882a593Smuzhiyun }
4903*4882a593Smuzhiyun
4904*4882a593Smuzhiyun if (level < 0) {
4905*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
4906*4882a593Smuzhiyun "Requested display configuration exceeds system DDB limitations");
4907*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "minimum required %d/%d\n",
4908*4882a593Smuzhiyun blocks, alloc_size);
4909*4882a593Smuzhiyun return -EINVAL;
4910*4882a593Smuzhiyun }
4911*4882a593Smuzhiyun
4912*4882a593Smuzhiyun /*
4913*4882a593Smuzhiyun * Grant each plane the blocks it requires at the highest achievable
4914*4882a593Smuzhiyun * watermark level, plus an extra share of the leftover blocks
4915*4882a593Smuzhiyun * proportional to its relative data rate.
4916*4882a593Smuzhiyun */
4917*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
4918*4882a593Smuzhiyun const struct skl_plane_wm *wm =
4919*4882a593Smuzhiyun &crtc_state->wm.skl.optimal.planes[plane_id];
4920*4882a593Smuzhiyun u64 rate;
4921*4882a593Smuzhiyun u16 extra;
4922*4882a593Smuzhiyun
4923*4882a593Smuzhiyun if (plane_id == PLANE_CURSOR)
4924*4882a593Smuzhiyun continue;
4925*4882a593Smuzhiyun
4926*4882a593Smuzhiyun /*
4927*4882a593Smuzhiyun * We've accounted for all active planes; remaining planes are
4928*4882a593Smuzhiyun * all disabled.
4929*4882a593Smuzhiyun */
4930*4882a593Smuzhiyun if (total_data_rate == 0)
4931*4882a593Smuzhiyun break;
4932*4882a593Smuzhiyun
4933*4882a593Smuzhiyun rate = plane_data_rate[plane_id];
4934*4882a593Smuzhiyun extra = min_t(u16, alloc_size,
4935*4882a593Smuzhiyun DIV64_U64_ROUND_UP(alloc_size * rate,
4936*4882a593Smuzhiyun total_data_rate));
4937*4882a593Smuzhiyun total[plane_id] = wm->wm[level].min_ddb_alloc + extra;
4938*4882a593Smuzhiyun alloc_size -= extra;
4939*4882a593Smuzhiyun total_data_rate -= rate;
4940*4882a593Smuzhiyun
4941*4882a593Smuzhiyun if (total_data_rate == 0)
4942*4882a593Smuzhiyun break;
4943*4882a593Smuzhiyun
4944*4882a593Smuzhiyun rate = uv_plane_data_rate[plane_id];
4945*4882a593Smuzhiyun extra = min_t(u16, alloc_size,
4946*4882a593Smuzhiyun DIV64_U64_ROUND_UP(alloc_size * rate,
4947*4882a593Smuzhiyun total_data_rate));
4948*4882a593Smuzhiyun uv_total[plane_id] = wm->uv_wm[level].min_ddb_alloc + extra;
4949*4882a593Smuzhiyun alloc_size -= extra;
4950*4882a593Smuzhiyun total_data_rate -= rate;
4951*4882a593Smuzhiyun }
4952*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, alloc_size != 0 || total_data_rate != 0);
4953*4882a593Smuzhiyun
4954*4882a593Smuzhiyun /* Set the actual DDB start/end points for each plane */
4955*4882a593Smuzhiyun start = alloc->start;
4956*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
4957*4882a593Smuzhiyun struct skl_ddb_entry *plane_alloc =
4958*4882a593Smuzhiyun &crtc_state->wm.skl.plane_ddb_y[plane_id];
4959*4882a593Smuzhiyun struct skl_ddb_entry *uv_plane_alloc =
4960*4882a593Smuzhiyun &crtc_state->wm.skl.plane_ddb_uv[plane_id];
4961*4882a593Smuzhiyun
4962*4882a593Smuzhiyun if (plane_id == PLANE_CURSOR)
4963*4882a593Smuzhiyun continue;
4964*4882a593Smuzhiyun
4965*4882a593Smuzhiyun /* Gen11+ uses a separate plane for UV watermarks */
4966*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm,
4967*4882a593Smuzhiyun INTEL_GEN(dev_priv) >= 11 && uv_total[plane_id]);
4968*4882a593Smuzhiyun
4969*4882a593Smuzhiyun /* Leave disabled planes at (0,0) */
4970*4882a593Smuzhiyun if (total[plane_id]) {
4971*4882a593Smuzhiyun plane_alloc->start = start;
4972*4882a593Smuzhiyun start += total[plane_id];
4973*4882a593Smuzhiyun plane_alloc->end = start;
4974*4882a593Smuzhiyun }
4975*4882a593Smuzhiyun
4976*4882a593Smuzhiyun if (uv_total[plane_id]) {
4977*4882a593Smuzhiyun uv_plane_alloc->start = start;
4978*4882a593Smuzhiyun start += uv_total[plane_id];
4979*4882a593Smuzhiyun uv_plane_alloc->end = start;
4980*4882a593Smuzhiyun }
4981*4882a593Smuzhiyun }
4982*4882a593Smuzhiyun
4983*4882a593Smuzhiyun /*
4984*4882a593Smuzhiyun * When we calculated watermark values we didn't know how high
4985*4882a593Smuzhiyun * of a level we'd actually be able to hit, so we just marked
4986*4882a593Smuzhiyun * all levels as "enabled." Go back now and disable the ones
4987*4882a593Smuzhiyun * that aren't actually possible.
4988*4882a593Smuzhiyun */
4989*4882a593Smuzhiyun for (level++; level <= ilk_wm_max_level(dev_priv); level++) {
4990*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
4991*4882a593Smuzhiyun struct skl_plane_wm *wm =
4992*4882a593Smuzhiyun &crtc_state->wm.skl.optimal.planes[plane_id];
4993*4882a593Smuzhiyun
4994*4882a593Smuzhiyun /*
4995*4882a593Smuzhiyun * We only disable the watermarks for each plane if
4996*4882a593Smuzhiyun * they exceed the ddb allocation of said plane. This
4997*4882a593Smuzhiyun * is done so that we don't end up touching cursor
4998*4882a593Smuzhiyun * watermarks needlessly when some other plane reduces
4999*4882a593Smuzhiyun * our max possible watermark level.
5000*4882a593Smuzhiyun *
5001*4882a593Smuzhiyun * Bspec has this to say about the PLANE_WM enable bit:
5002*4882a593Smuzhiyun * "All the watermarks at this level for all enabled
5003*4882a593Smuzhiyun * planes must be enabled before the level will be used."
5004*4882a593Smuzhiyun * So this is actually safe to do.
5005*4882a593Smuzhiyun */
5006*4882a593Smuzhiyun if (wm->wm[level].min_ddb_alloc > total[plane_id] ||
5007*4882a593Smuzhiyun wm->uv_wm[level].min_ddb_alloc > uv_total[plane_id])
5008*4882a593Smuzhiyun memset(&wm->wm[level], 0, sizeof(wm->wm[level]));
5009*4882a593Smuzhiyun
5010*4882a593Smuzhiyun /*
5011*4882a593Smuzhiyun * Wa_1408961008:icl, ehl
5012*4882a593Smuzhiyun * Underruns with WM1+ disabled
5013*4882a593Smuzhiyun */
5014*4882a593Smuzhiyun if (IS_GEN(dev_priv, 11) &&
5015*4882a593Smuzhiyun level == 1 && wm->wm[0].plane_en) {
5016*4882a593Smuzhiyun wm->wm[level].plane_res_b = wm->wm[0].plane_res_b;
5017*4882a593Smuzhiyun wm->wm[level].plane_res_l = wm->wm[0].plane_res_l;
5018*4882a593Smuzhiyun wm->wm[level].ignore_lines = wm->wm[0].ignore_lines;
5019*4882a593Smuzhiyun }
5020*4882a593Smuzhiyun }
5021*4882a593Smuzhiyun }
5022*4882a593Smuzhiyun
5023*4882a593Smuzhiyun /*
5024*4882a593Smuzhiyun * Go back and disable the transition watermark if it turns out we
5025*4882a593Smuzhiyun * don't have enough DDB blocks for it.
5026*4882a593Smuzhiyun */
5027*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
5028*4882a593Smuzhiyun struct skl_plane_wm *wm =
5029*4882a593Smuzhiyun &crtc_state->wm.skl.optimal.planes[plane_id];
5030*4882a593Smuzhiyun
5031*4882a593Smuzhiyun if (wm->trans_wm.plane_res_b >= total[plane_id])
5032*4882a593Smuzhiyun memset(&wm->trans_wm, 0, sizeof(wm->trans_wm));
5033*4882a593Smuzhiyun }
5034*4882a593Smuzhiyun
5035*4882a593Smuzhiyun return 0;
5036*4882a593Smuzhiyun }
5037*4882a593Smuzhiyun
5038*4882a593Smuzhiyun /*
5039*4882a593Smuzhiyun * The max latency should be 257 (max the punit can code is 255 and we add 2us
5040*4882a593Smuzhiyun * for the read latency) and cpp should always be <= 8, so that
5041*4882a593Smuzhiyun * should allow pixel_rate up to ~2 GHz which seems sufficient since max
5042*4882a593Smuzhiyun * 2xcdclk is 1350 MHz and the pixel rate should never exceed that.
5043*4882a593Smuzhiyun */
5044*4882a593Smuzhiyun static uint_fixed_16_16_t
skl_wm_method1(const struct drm_i915_private * dev_priv,u32 pixel_rate,u8 cpp,u32 latency,u32 dbuf_block_size)5045*4882a593Smuzhiyun skl_wm_method1(const struct drm_i915_private *dev_priv, u32 pixel_rate,
5046*4882a593Smuzhiyun u8 cpp, u32 latency, u32 dbuf_block_size)
5047*4882a593Smuzhiyun {
5048*4882a593Smuzhiyun u32 wm_intermediate_val;
5049*4882a593Smuzhiyun uint_fixed_16_16_t ret;
5050*4882a593Smuzhiyun
5051*4882a593Smuzhiyun if (latency == 0)
5052*4882a593Smuzhiyun return FP_16_16_MAX;
5053*4882a593Smuzhiyun
5054*4882a593Smuzhiyun wm_intermediate_val = latency * pixel_rate * cpp;
5055*4882a593Smuzhiyun ret = div_fixed16(wm_intermediate_val, 1000 * dbuf_block_size);
5056*4882a593Smuzhiyun
5057*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
5058*4882a593Smuzhiyun ret = add_fixed16_u32(ret, 1);
5059*4882a593Smuzhiyun
5060*4882a593Smuzhiyun return ret;
5061*4882a593Smuzhiyun }
5062*4882a593Smuzhiyun
5063*4882a593Smuzhiyun static uint_fixed_16_16_t
skl_wm_method2(u32 pixel_rate,u32 pipe_htotal,u32 latency,uint_fixed_16_16_t plane_blocks_per_line)5064*4882a593Smuzhiyun skl_wm_method2(u32 pixel_rate, u32 pipe_htotal, u32 latency,
5065*4882a593Smuzhiyun uint_fixed_16_16_t plane_blocks_per_line)
5066*4882a593Smuzhiyun {
5067*4882a593Smuzhiyun u32 wm_intermediate_val;
5068*4882a593Smuzhiyun uint_fixed_16_16_t ret;
5069*4882a593Smuzhiyun
5070*4882a593Smuzhiyun if (latency == 0)
5071*4882a593Smuzhiyun return FP_16_16_MAX;
5072*4882a593Smuzhiyun
5073*4882a593Smuzhiyun wm_intermediate_val = latency * pixel_rate;
5074*4882a593Smuzhiyun wm_intermediate_val = DIV_ROUND_UP(wm_intermediate_val,
5075*4882a593Smuzhiyun pipe_htotal * 1000);
5076*4882a593Smuzhiyun ret = mul_u32_fixed16(wm_intermediate_val, plane_blocks_per_line);
5077*4882a593Smuzhiyun return ret;
5078*4882a593Smuzhiyun }
5079*4882a593Smuzhiyun
5080*4882a593Smuzhiyun static uint_fixed_16_16_t
intel_get_linetime_us(const struct intel_crtc_state * crtc_state)5081*4882a593Smuzhiyun intel_get_linetime_us(const struct intel_crtc_state *crtc_state)
5082*4882a593Smuzhiyun {
5083*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5084*4882a593Smuzhiyun u32 pixel_rate;
5085*4882a593Smuzhiyun u32 crtc_htotal;
5086*4882a593Smuzhiyun uint_fixed_16_16_t linetime_us;
5087*4882a593Smuzhiyun
5088*4882a593Smuzhiyun if (!crtc_state->hw.active)
5089*4882a593Smuzhiyun return u32_to_fixed16(0);
5090*4882a593Smuzhiyun
5091*4882a593Smuzhiyun pixel_rate = crtc_state->pixel_rate;
5092*4882a593Smuzhiyun
5093*4882a593Smuzhiyun if (drm_WARN_ON(&dev_priv->drm, pixel_rate == 0))
5094*4882a593Smuzhiyun return u32_to_fixed16(0);
5095*4882a593Smuzhiyun
5096*4882a593Smuzhiyun crtc_htotal = crtc_state->hw.adjusted_mode.crtc_htotal;
5097*4882a593Smuzhiyun linetime_us = div_fixed16(crtc_htotal * 1000, pixel_rate);
5098*4882a593Smuzhiyun
5099*4882a593Smuzhiyun return linetime_us;
5100*4882a593Smuzhiyun }
5101*4882a593Smuzhiyun
5102*4882a593Smuzhiyun static u32
skl_adjusted_plane_pixel_rate(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)5103*4882a593Smuzhiyun skl_adjusted_plane_pixel_rate(const struct intel_crtc_state *crtc_state,
5104*4882a593Smuzhiyun const struct intel_plane_state *plane_state)
5105*4882a593Smuzhiyun {
5106*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5107*4882a593Smuzhiyun u64 adjusted_pixel_rate;
5108*4882a593Smuzhiyun uint_fixed_16_16_t downscale_amount;
5109*4882a593Smuzhiyun
5110*4882a593Smuzhiyun /* Shouldn't reach here on disabled planes... */
5111*4882a593Smuzhiyun if (drm_WARN_ON(&dev_priv->drm,
5112*4882a593Smuzhiyun !intel_wm_plane_visible(crtc_state, plane_state)))
5113*4882a593Smuzhiyun return 0;
5114*4882a593Smuzhiyun
5115*4882a593Smuzhiyun /*
5116*4882a593Smuzhiyun * Adjusted plane pixel rate is just the pipe's adjusted pixel rate
5117*4882a593Smuzhiyun * with additional adjustments for plane-specific scaling.
5118*4882a593Smuzhiyun */
5119*4882a593Smuzhiyun adjusted_pixel_rate = crtc_state->pixel_rate;
5120*4882a593Smuzhiyun downscale_amount = skl_plane_downscale_amount(crtc_state, plane_state);
5121*4882a593Smuzhiyun
5122*4882a593Smuzhiyun return mul_round_up_u32_fixed16(adjusted_pixel_rate,
5123*4882a593Smuzhiyun downscale_amount);
5124*4882a593Smuzhiyun }
5125*4882a593Smuzhiyun
5126*4882a593Smuzhiyun static int
skl_compute_wm_params(const struct intel_crtc_state * crtc_state,int width,const struct drm_format_info * format,u64 modifier,unsigned int rotation,u32 plane_pixel_rate,struct skl_wm_params * wp,int color_plane)5127*4882a593Smuzhiyun skl_compute_wm_params(const struct intel_crtc_state *crtc_state,
5128*4882a593Smuzhiyun int width, const struct drm_format_info *format,
5129*4882a593Smuzhiyun u64 modifier, unsigned int rotation,
5130*4882a593Smuzhiyun u32 plane_pixel_rate, struct skl_wm_params *wp,
5131*4882a593Smuzhiyun int color_plane)
5132*4882a593Smuzhiyun {
5133*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5134*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5135*4882a593Smuzhiyun u32 interm_pbpl;
5136*4882a593Smuzhiyun
5137*4882a593Smuzhiyun /* only planar format has two planes */
5138*4882a593Smuzhiyun if (color_plane == 1 &&
5139*4882a593Smuzhiyun !intel_format_info_is_yuv_semiplanar(format, modifier)) {
5140*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
5141*4882a593Smuzhiyun "Non planar format have single plane\n");
5142*4882a593Smuzhiyun return -EINVAL;
5143*4882a593Smuzhiyun }
5144*4882a593Smuzhiyun
5145*4882a593Smuzhiyun wp->y_tiled = modifier == I915_FORMAT_MOD_Y_TILED ||
5146*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Yf_TILED ||
5147*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
5148*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
5149*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
5150*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
5151*4882a593Smuzhiyun wp->x_tiled = modifier == I915_FORMAT_MOD_X_TILED;
5152*4882a593Smuzhiyun wp->rc_surface = modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
5153*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Yf_TILED_CCS ||
5154*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS ||
5155*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS;
5156*4882a593Smuzhiyun wp->is_planar = intel_format_info_is_yuv_semiplanar(format, modifier);
5157*4882a593Smuzhiyun
5158*4882a593Smuzhiyun wp->width = width;
5159*4882a593Smuzhiyun if (color_plane == 1 && wp->is_planar)
5160*4882a593Smuzhiyun wp->width /= 2;
5161*4882a593Smuzhiyun
5162*4882a593Smuzhiyun wp->cpp = format->cpp[color_plane];
5163*4882a593Smuzhiyun wp->plane_pixel_rate = plane_pixel_rate;
5164*4882a593Smuzhiyun
5165*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 11 &&
5166*4882a593Smuzhiyun modifier == I915_FORMAT_MOD_Yf_TILED && wp->cpp == 1)
5167*4882a593Smuzhiyun wp->dbuf_block_size = 256;
5168*4882a593Smuzhiyun else
5169*4882a593Smuzhiyun wp->dbuf_block_size = 512;
5170*4882a593Smuzhiyun
5171*4882a593Smuzhiyun if (drm_rotation_90_or_270(rotation)) {
5172*4882a593Smuzhiyun switch (wp->cpp) {
5173*4882a593Smuzhiyun case 1:
5174*4882a593Smuzhiyun wp->y_min_scanlines = 16;
5175*4882a593Smuzhiyun break;
5176*4882a593Smuzhiyun case 2:
5177*4882a593Smuzhiyun wp->y_min_scanlines = 8;
5178*4882a593Smuzhiyun break;
5179*4882a593Smuzhiyun case 4:
5180*4882a593Smuzhiyun wp->y_min_scanlines = 4;
5181*4882a593Smuzhiyun break;
5182*4882a593Smuzhiyun default:
5183*4882a593Smuzhiyun MISSING_CASE(wp->cpp);
5184*4882a593Smuzhiyun return -EINVAL;
5185*4882a593Smuzhiyun }
5186*4882a593Smuzhiyun } else {
5187*4882a593Smuzhiyun wp->y_min_scanlines = 4;
5188*4882a593Smuzhiyun }
5189*4882a593Smuzhiyun
5190*4882a593Smuzhiyun if (skl_needs_memory_bw_wa(dev_priv))
5191*4882a593Smuzhiyun wp->y_min_scanlines *= 2;
5192*4882a593Smuzhiyun
5193*4882a593Smuzhiyun wp->plane_bytes_per_line = wp->width * wp->cpp;
5194*4882a593Smuzhiyun if (wp->y_tiled) {
5195*4882a593Smuzhiyun interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line *
5196*4882a593Smuzhiyun wp->y_min_scanlines,
5197*4882a593Smuzhiyun wp->dbuf_block_size);
5198*4882a593Smuzhiyun
5199*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
5200*4882a593Smuzhiyun interm_pbpl++;
5201*4882a593Smuzhiyun
5202*4882a593Smuzhiyun wp->plane_blocks_per_line = div_fixed16(interm_pbpl,
5203*4882a593Smuzhiyun wp->y_min_scanlines);
5204*4882a593Smuzhiyun } else {
5205*4882a593Smuzhiyun interm_pbpl = DIV_ROUND_UP(wp->plane_bytes_per_line,
5206*4882a593Smuzhiyun wp->dbuf_block_size);
5207*4882a593Smuzhiyun
5208*4882a593Smuzhiyun if (!wp->x_tiled ||
5209*4882a593Smuzhiyun INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
5210*4882a593Smuzhiyun interm_pbpl++;
5211*4882a593Smuzhiyun
5212*4882a593Smuzhiyun wp->plane_blocks_per_line = u32_to_fixed16(interm_pbpl);
5213*4882a593Smuzhiyun }
5214*4882a593Smuzhiyun
5215*4882a593Smuzhiyun wp->y_tile_minimum = mul_u32_fixed16(wp->y_min_scanlines,
5216*4882a593Smuzhiyun wp->plane_blocks_per_line);
5217*4882a593Smuzhiyun
5218*4882a593Smuzhiyun wp->linetime_us = fixed16_to_u32_round_up(
5219*4882a593Smuzhiyun intel_get_linetime_us(crtc_state));
5220*4882a593Smuzhiyun
5221*4882a593Smuzhiyun return 0;
5222*4882a593Smuzhiyun }
5223*4882a593Smuzhiyun
5224*4882a593Smuzhiyun static int
skl_compute_plane_wm_params(const struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,struct skl_wm_params * wp,int color_plane)5225*4882a593Smuzhiyun skl_compute_plane_wm_params(const struct intel_crtc_state *crtc_state,
5226*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
5227*4882a593Smuzhiyun struct skl_wm_params *wp, int color_plane)
5228*4882a593Smuzhiyun {
5229*4882a593Smuzhiyun const struct drm_framebuffer *fb = plane_state->hw.fb;
5230*4882a593Smuzhiyun int width;
5231*4882a593Smuzhiyun
5232*4882a593Smuzhiyun /*
5233*4882a593Smuzhiyun * Src coordinates are already rotated by 270 degrees for
5234*4882a593Smuzhiyun * the 90/270 degree plane rotation cases (to match the
5235*4882a593Smuzhiyun * GTT mapping), hence no need to account for rotation here.
5236*4882a593Smuzhiyun */
5237*4882a593Smuzhiyun width = drm_rect_width(&plane_state->uapi.src) >> 16;
5238*4882a593Smuzhiyun
5239*4882a593Smuzhiyun return skl_compute_wm_params(crtc_state, width,
5240*4882a593Smuzhiyun fb->format, fb->modifier,
5241*4882a593Smuzhiyun plane_state->hw.rotation,
5242*4882a593Smuzhiyun skl_adjusted_plane_pixel_rate(crtc_state, plane_state),
5243*4882a593Smuzhiyun wp, color_plane);
5244*4882a593Smuzhiyun }
5245*4882a593Smuzhiyun
skl_wm_has_lines(struct drm_i915_private * dev_priv,int level)5246*4882a593Smuzhiyun static bool skl_wm_has_lines(struct drm_i915_private *dev_priv, int level)
5247*4882a593Smuzhiyun {
5248*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
5249*4882a593Smuzhiyun return true;
5250*4882a593Smuzhiyun
5251*4882a593Smuzhiyun /* The number of lines are ignored for the level 0 watermark. */
5252*4882a593Smuzhiyun return level > 0;
5253*4882a593Smuzhiyun }
5254*4882a593Smuzhiyun
skl_compute_plane_wm(const struct intel_crtc_state * crtc_state,int level,unsigned int latency,const struct skl_wm_params * wp,const struct skl_wm_level * result_prev,struct skl_wm_level * result)5255*4882a593Smuzhiyun static void skl_compute_plane_wm(const struct intel_crtc_state *crtc_state,
5256*4882a593Smuzhiyun int level,
5257*4882a593Smuzhiyun unsigned int latency,
5258*4882a593Smuzhiyun const struct skl_wm_params *wp,
5259*4882a593Smuzhiyun const struct skl_wm_level *result_prev,
5260*4882a593Smuzhiyun struct skl_wm_level *result /* out */)
5261*4882a593Smuzhiyun {
5262*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5263*4882a593Smuzhiyun uint_fixed_16_16_t method1, method2;
5264*4882a593Smuzhiyun uint_fixed_16_16_t selected_result;
5265*4882a593Smuzhiyun u32 res_blocks, res_lines, min_ddb_alloc = 0;
5266*4882a593Smuzhiyun
5267*4882a593Smuzhiyun if (latency == 0) {
5268*4882a593Smuzhiyun /* reject it */
5269*4882a593Smuzhiyun result->min_ddb_alloc = U16_MAX;
5270*4882a593Smuzhiyun return;
5271*4882a593Smuzhiyun }
5272*4882a593Smuzhiyun
5273*4882a593Smuzhiyun /*
5274*4882a593Smuzhiyun * WaIncreaseLatencyIPCEnabled: kbl,cfl
5275*4882a593Smuzhiyun * Display WA #1141: kbl,cfl
5276*4882a593Smuzhiyun */
5277*4882a593Smuzhiyun if ((IS_KABYLAKE(dev_priv) ||
5278*4882a593Smuzhiyun IS_COFFEELAKE(dev_priv) ||
5279*4882a593Smuzhiyun IS_COMETLAKE(dev_priv)) &&
5280*4882a593Smuzhiyun dev_priv->ipc_enabled)
5281*4882a593Smuzhiyun latency += 4;
5282*4882a593Smuzhiyun
5283*4882a593Smuzhiyun if (skl_needs_memory_bw_wa(dev_priv) && wp->x_tiled)
5284*4882a593Smuzhiyun latency += 15;
5285*4882a593Smuzhiyun
5286*4882a593Smuzhiyun method1 = skl_wm_method1(dev_priv, wp->plane_pixel_rate,
5287*4882a593Smuzhiyun wp->cpp, latency, wp->dbuf_block_size);
5288*4882a593Smuzhiyun method2 = skl_wm_method2(wp->plane_pixel_rate,
5289*4882a593Smuzhiyun crtc_state->hw.adjusted_mode.crtc_htotal,
5290*4882a593Smuzhiyun latency,
5291*4882a593Smuzhiyun wp->plane_blocks_per_line);
5292*4882a593Smuzhiyun
5293*4882a593Smuzhiyun if (wp->y_tiled) {
5294*4882a593Smuzhiyun selected_result = max_fixed16(method2, wp->y_tile_minimum);
5295*4882a593Smuzhiyun } else {
5296*4882a593Smuzhiyun if ((wp->cpp * crtc_state->hw.adjusted_mode.crtc_htotal /
5297*4882a593Smuzhiyun wp->dbuf_block_size < 1) &&
5298*4882a593Smuzhiyun (wp->plane_bytes_per_line / wp->dbuf_block_size < 1)) {
5299*4882a593Smuzhiyun selected_result = method2;
5300*4882a593Smuzhiyun } else if (latency >= wp->linetime_us) {
5301*4882a593Smuzhiyun if (IS_GEN(dev_priv, 9) &&
5302*4882a593Smuzhiyun !IS_GEMINILAKE(dev_priv))
5303*4882a593Smuzhiyun selected_result = min_fixed16(method1, method2);
5304*4882a593Smuzhiyun else
5305*4882a593Smuzhiyun selected_result = method2;
5306*4882a593Smuzhiyun } else {
5307*4882a593Smuzhiyun selected_result = method1;
5308*4882a593Smuzhiyun }
5309*4882a593Smuzhiyun }
5310*4882a593Smuzhiyun
5311*4882a593Smuzhiyun res_blocks = fixed16_to_u32_round_up(selected_result) + 1;
5312*4882a593Smuzhiyun res_lines = div_round_up_fixed16(selected_result,
5313*4882a593Smuzhiyun wp->plane_blocks_per_line);
5314*4882a593Smuzhiyun
5315*4882a593Smuzhiyun if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv)) {
5316*4882a593Smuzhiyun /* Display WA #1125: skl,bxt,kbl */
5317*4882a593Smuzhiyun if (level == 0 && wp->rc_surface)
5318*4882a593Smuzhiyun res_blocks +=
5319*4882a593Smuzhiyun fixed16_to_u32_round_up(wp->y_tile_minimum);
5320*4882a593Smuzhiyun
5321*4882a593Smuzhiyun /* Display WA #1126: skl,bxt,kbl */
5322*4882a593Smuzhiyun if (level >= 1 && level <= 7) {
5323*4882a593Smuzhiyun if (wp->y_tiled) {
5324*4882a593Smuzhiyun res_blocks +=
5325*4882a593Smuzhiyun fixed16_to_u32_round_up(wp->y_tile_minimum);
5326*4882a593Smuzhiyun res_lines += wp->y_min_scanlines;
5327*4882a593Smuzhiyun } else {
5328*4882a593Smuzhiyun res_blocks++;
5329*4882a593Smuzhiyun }
5330*4882a593Smuzhiyun
5331*4882a593Smuzhiyun /*
5332*4882a593Smuzhiyun * Make sure result blocks for higher latency levels are
5333*4882a593Smuzhiyun * atleast as high as level below the current level.
5334*4882a593Smuzhiyun * Assumption in DDB algorithm optimization for special
5335*4882a593Smuzhiyun * cases. Also covers Display WA #1125 for RC.
5336*4882a593Smuzhiyun */
5337*4882a593Smuzhiyun if (result_prev->plane_res_b > res_blocks)
5338*4882a593Smuzhiyun res_blocks = result_prev->plane_res_b;
5339*4882a593Smuzhiyun }
5340*4882a593Smuzhiyun }
5341*4882a593Smuzhiyun
5342*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 11) {
5343*4882a593Smuzhiyun if (wp->y_tiled) {
5344*4882a593Smuzhiyun int extra_lines;
5345*4882a593Smuzhiyun
5346*4882a593Smuzhiyun if (res_lines % wp->y_min_scanlines == 0)
5347*4882a593Smuzhiyun extra_lines = wp->y_min_scanlines;
5348*4882a593Smuzhiyun else
5349*4882a593Smuzhiyun extra_lines = wp->y_min_scanlines * 2 -
5350*4882a593Smuzhiyun res_lines % wp->y_min_scanlines;
5351*4882a593Smuzhiyun
5352*4882a593Smuzhiyun min_ddb_alloc = mul_round_up_u32_fixed16(res_lines + extra_lines,
5353*4882a593Smuzhiyun wp->plane_blocks_per_line);
5354*4882a593Smuzhiyun } else {
5355*4882a593Smuzhiyun min_ddb_alloc = res_blocks +
5356*4882a593Smuzhiyun DIV_ROUND_UP(res_blocks, 10);
5357*4882a593Smuzhiyun }
5358*4882a593Smuzhiyun }
5359*4882a593Smuzhiyun
5360*4882a593Smuzhiyun if (!skl_wm_has_lines(dev_priv, level))
5361*4882a593Smuzhiyun res_lines = 0;
5362*4882a593Smuzhiyun
5363*4882a593Smuzhiyun if (res_lines > 31) {
5364*4882a593Smuzhiyun /* reject it */
5365*4882a593Smuzhiyun result->min_ddb_alloc = U16_MAX;
5366*4882a593Smuzhiyun return;
5367*4882a593Smuzhiyun }
5368*4882a593Smuzhiyun
5369*4882a593Smuzhiyun /*
5370*4882a593Smuzhiyun * If res_lines is valid, assume we can use this watermark level
5371*4882a593Smuzhiyun * for now. We'll come back and disable it after we calculate the
5372*4882a593Smuzhiyun * DDB allocation if it turns out we don't actually have enough
5373*4882a593Smuzhiyun * blocks to satisfy it.
5374*4882a593Smuzhiyun */
5375*4882a593Smuzhiyun result->plane_res_b = res_blocks;
5376*4882a593Smuzhiyun result->plane_res_l = res_lines;
5377*4882a593Smuzhiyun /* Bspec says: value >= plane ddb allocation -> invalid, hence the +1 here */
5378*4882a593Smuzhiyun result->min_ddb_alloc = max(min_ddb_alloc, res_blocks) + 1;
5379*4882a593Smuzhiyun result->plane_en = true;
5380*4882a593Smuzhiyun }
5381*4882a593Smuzhiyun
5382*4882a593Smuzhiyun static void
skl_compute_wm_levels(const struct intel_crtc_state * crtc_state,const struct skl_wm_params * wm_params,struct skl_wm_level * levels)5383*4882a593Smuzhiyun skl_compute_wm_levels(const struct intel_crtc_state *crtc_state,
5384*4882a593Smuzhiyun const struct skl_wm_params *wm_params,
5385*4882a593Smuzhiyun struct skl_wm_level *levels)
5386*4882a593Smuzhiyun {
5387*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5388*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
5389*4882a593Smuzhiyun struct skl_wm_level *result_prev = &levels[0];
5390*4882a593Smuzhiyun
5391*4882a593Smuzhiyun for (level = 0; level <= max_level; level++) {
5392*4882a593Smuzhiyun struct skl_wm_level *result = &levels[level];
5393*4882a593Smuzhiyun unsigned int latency = dev_priv->wm.skl_latency[level];
5394*4882a593Smuzhiyun
5395*4882a593Smuzhiyun skl_compute_plane_wm(crtc_state, level, latency,
5396*4882a593Smuzhiyun wm_params, result_prev, result);
5397*4882a593Smuzhiyun
5398*4882a593Smuzhiyun result_prev = result;
5399*4882a593Smuzhiyun }
5400*4882a593Smuzhiyun }
5401*4882a593Smuzhiyun
tgl_compute_sagv_wm(const struct intel_crtc_state * crtc_state,const struct skl_wm_params * wm_params,struct skl_plane_wm * plane_wm)5402*4882a593Smuzhiyun static void tgl_compute_sagv_wm(const struct intel_crtc_state *crtc_state,
5403*4882a593Smuzhiyun const struct skl_wm_params *wm_params,
5404*4882a593Smuzhiyun struct skl_plane_wm *plane_wm)
5405*4882a593Smuzhiyun {
5406*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5407*4882a593Smuzhiyun struct skl_wm_level *sagv_wm = &plane_wm->sagv_wm0;
5408*4882a593Smuzhiyun struct skl_wm_level *levels = plane_wm->wm;
5409*4882a593Smuzhiyun unsigned int latency = dev_priv->wm.skl_latency[0] + dev_priv->sagv_block_time_us;
5410*4882a593Smuzhiyun
5411*4882a593Smuzhiyun skl_compute_plane_wm(crtc_state, 0, latency,
5412*4882a593Smuzhiyun wm_params, &levels[0],
5413*4882a593Smuzhiyun sagv_wm);
5414*4882a593Smuzhiyun }
5415*4882a593Smuzhiyun
skl_compute_transition_wm(const struct intel_crtc_state * crtc_state,const struct skl_wm_params * wp,struct skl_plane_wm * wm)5416*4882a593Smuzhiyun static void skl_compute_transition_wm(const struct intel_crtc_state *crtc_state,
5417*4882a593Smuzhiyun const struct skl_wm_params *wp,
5418*4882a593Smuzhiyun struct skl_plane_wm *wm)
5419*4882a593Smuzhiyun {
5420*4882a593Smuzhiyun struct drm_device *dev = crtc_state->uapi.crtc->dev;
5421*4882a593Smuzhiyun const struct drm_i915_private *dev_priv = to_i915(dev);
5422*4882a593Smuzhiyun u16 trans_min, trans_amount, trans_y_tile_min;
5423*4882a593Smuzhiyun u16 wm0_sel_res_b, trans_offset_b, res_blocks;
5424*4882a593Smuzhiyun
5425*4882a593Smuzhiyun /* Transition WM don't make any sense if ipc is disabled */
5426*4882a593Smuzhiyun if (!dev_priv->ipc_enabled)
5427*4882a593Smuzhiyun return;
5428*4882a593Smuzhiyun
5429*4882a593Smuzhiyun /*
5430*4882a593Smuzhiyun * WaDisableTWM:skl,kbl,cfl,bxt
5431*4882a593Smuzhiyun * Transition WM are not recommended by HW team for GEN9
5432*4882a593Smuzhiyun */
5433*4882a593Smuzhiyun if (IS_GEN9_BC(dev_priv) || IS_BROXTON(dev_priv))
5434*4882a593Smuzhiyun return;
5435*4882a593Smuzhiyun
5436*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 11)
5437*4882a593Smuzhiyun trans_min = 4;
5438*4882a593Smuzhiyun else
5439*4882a593Smuzhiyun trans_min = 14;
5440*4882a593Smuzhiyun
5441*4882a593Smuzhiyun /* Display WA #1140: glk,cnl */
5442*4882a593Smuzhiyun if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
5443*4882a593Smuzhiyun trans_amount = 0;
5444*4882a593Smuzhiyun else
5445*4882a593Smuzhiyun trans_amount = 10; /* This is configurable amount */
5446*4882a593Smuzhiyun
5447*4882a593Smuzhiyun trans_offset_b = trans_min + trans_amount;
5448*4882a593Smuzhiyun
5449*4882a593Smuzhiyun /*
5450*4882a593Smuzhiyun * The spec asks for Selected Result Blocks for wm0 (the real value),
5451*4882a593Smuzhiyun * not Result Blocks (the integer value). Pay attention to the capital
5452*4882a593Smuzhiyun * letters. The value wm_l0->plane_res_b is actually Result Blocks, but
5453*4882a593Smuzhiyun * since Result Blocks is the ceiling of Selected Result Blocks plus 1,
5454*4882a593Smuzhiyun * and since we later will have to get the ceiling of the sum in the
5455*4882a593Smuzhiyun * transition watermarks calculation, we can just pretend Selected
5456*4882a593Smuzhiyun * Result Blocks is Result Blocks minus 1 and it should work for the
5457*4882a593Smuzhiyun * current platforms.
5458*4882a593Smuzhiyun */
5459*4882a593Smuzhiyun wm0_sel_res_b = wm->wm[0].plane_res_b - 1;
5460*4882a593Smuzhiyun
5461*4882a593Smuzhiyun if (wp->y_tiled) {
5462*4882a593Smuzhiyun trans_y_tile_min =
5463*4882a593Smuzhiyun (u16)mul_round_up_u32_fixed16(2, wp->y_tile_minimum);
5464*4882a593Smuzhiyun res_blocks = max(wm0_sel_res_b, trans_y_tile_min) +
5465*4882a593Smuzhiyun trans_offset_b;
5466*4882a593Smuzhiyun } else {
5467*4882a593Smuzhiyun res_blocks = wm0_sel_res_b + trans_offset_b;
5468*4882a593Smuzhiyun }
5469*4882a593Smuzhiyun
5470*4882a593Smuzhiyun /*
5471*4882a593Smuzhiyun * Just assume we can enable the transition watermark. After
5472*4882a593Smuzhiyun * computing the DDB we'll come back and disable it if that
5473*4882a593Smuzhiyun * assumption turns out to be false.
5474*4882a593Smuzhiyun */
5475*4882a593Smuzhiyun wm->trans_wm.plane_res_b = res_blocks + 1;
5476*4882a593Smuzhiyun wm->trans_wm.plane_en = true;
5477*4882a593Smuzhiyun }
5478*4882a593Smuzhiyun
skl_build_plane_wm_single(struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,enum plane_id plane_id,int color_plane)5479*4882a593Smuzhiyun static int skl_build_plane_wm_single(struct intel_crtc_state *crtc_state,
5480*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
5481*4882a593Smuzhiyun enum plane_id plane_id, int color_plane)
5482*4882a593Smuzhiyun {
5483*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5484*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5485*4882a593Smuzhiyun struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id];
5486*4882a593Smuzhiyun struct skl_wm_params wm_params;
5487*4882a593Smuzhiyun int ret;
5488*4882a593Smuzhiyun
5489*4882a593Smuzhiyun ret = skl_compute_plane_wm_params(crtc_state, plane_state,
5490*4882a593Smuzhiyun &wm_params, color_plane);
5491*4882a593Smuzhiyun if (ret)
5492*4882a593Smuzhiyun return ret;
5493*4882a593Smuzhiyun
5494*4882a593Smuzhiyun skl_compute_wm_levels(crtc_state, &wm_params, wm->wm);
5495*4882a593Smuzhiyun
5496*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 12)
5497*4882a593Smuzhiyun tgl_compute_sagv_wm(crtc_state, &wm_params, wm);
5498*4882a593Smuzhiyun
5499*4882a593Smuzhiyun skl_compute_transition_wm(crtc_state, &wm_params, wm);
5500*4882a593Smuzhiyun
5501*4882a593Smuzhiyun return 0;
5502*4882a593Smuzhiyun }
5503*4882a593Smuzhiyun
skl_build_plane_wm_uv(struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state,enum plane_id plane_id)5504*4882a593Smuzhiyun static int skl_build_plane_wm_uv(struct intel_crtc_state *crtc_state,
5505*4882a593Smuzhiyun const struct intel_plane_state *plane_state,
5506*4882a593Smuzhiyun enum plane_id plane_id)
5507*4882a593Smuzhiyun {
5508*4882a593Smuzhiyun struct skl_plane_wm *wm = &crtc_state->wm.skl.optimal.planes[plane_id];
5509*4882a593Smuzhiyun struct skl_wm_params wm_params;
5510*4882a593Smuzhiyun int ret;
5511*4882a593Smuzhiyun
5512*4882a593Smuzhiyun wm->is_planar = true;
5513*4882a593Smuzhiyun
5514*4882a593Smuzhiyun /* uv plane watermarks must also be validated for NV12/Planar */
5515*4882a593Smuzhiyun ret = skl_compute_plane_wm_params(crtc_state, plane_state,
5516*4882a593Smuzhiyun &wm_params, 1);
5517*4882a593Smuzhiyun if (ret)
5518*4882a593Smuzhiyun return ret;
5519*4882a593Smuzhiyun
5520*4882a593Smuzhiyun skl_compute_wm_levels(crtc_state, &wm_params, wm->uv_wm);
5521*4882a593Smuzhiyun
5522*4882a593Smuzhiyun return 0;
5523*4882a593Smuzhiyun }
5524*4882a593Smuzhiyun
skl_build_plane_wm(struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)5525*4882a593Smuzhiyun static int skl_build_plane_wm(struct intel_crtc_state *crtc_state,
5526*4882a593Smuzhiyun const struct intel_plane_state *plane_state)
5527*4882a593Smuzhiyun {
5528*4882a593Smuzhiyun struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
5529*4882a593Smuzhiyun const struct drm_framebuffer *fb = plane_state->hw.fb;
5530*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
5531*4882a593Smuzhiyun int ret;
5532*4882a593Smuzhiyun
5533*4882a593Smuzhiyun if (!intel_wm_plane_visible(crtc_state, plane_state))
5534*4882a593Smuzhiyun return 0;
5535*4882a593Smuzhiyun
5536*4882a593Smuzhiyun ret = skl_build_plane_wm_single(crtc_state, plane_state,
5537*4882a593Smuzhiyun plane_id, 0);
5538*4882a593Smuzhiyun if (ret)
5539*4882a593Smuzhiyun return ret;
5540*4882a593Smuzhiyun
5541*4882a593Smuzhiyun if (fb->format->is_yuv && fb->format->num_planes > 1) {
5542*4882a593Smuzhiyun ret = skl_build_plane_wm_uv(crtc_state, plane_state,
5543*4882a593Smuzhiyun plane_id);
5544*4882a593Smuzhiyun if (ret)
5545*4882a593Smuzhiyun return ret;
5546*4882a593Smuzhiyun }
5547*4882a593Smuzhiyun
5548*4882a593Smuzhiyun return 0;
5549*4882a593Smuzhiyun }
5550*4882a593Smuzhiyun
icl_build_plane_wm(struct intel_crtc_state * crtc_state,const struct intel_plane_state * plane_state)5551*4882a593Smuzhiyun static int icl_build_plane_wm(struct intel_crtc_state *crtc_state,
5552*4882a593Smuzhiyun const struct intel_plane_state *plane_state)
5553*4882a593Smuzhiyun {
5554*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5555*4882a593Smuzhiyun enum plane_id plane_id = to_intel_plane(plane_state->uapi.plane)->id;
5556*4882a593Smuzhiyun int ret;
5557*4882a593Smuzhiyun
5558*4882a593Smuzhiyun /* Watermarks calculated in master */
5559*4882a593Smuzhiyun if (plane_state->planar_slave)
5560*4882a593Smuzhiyun return 0;
5561*4882a593Smuzhiyun
5562*4882a593Smuzhiyun if (plane_state->planar_linked_plane) {
5563*4882a593Smuzhiyun const struct drm_framebuffer *fb = plane_state->hw.fb;
5564*4882a593Smuzhiyun enum plane_id y_plane_id = plane_state->planar_linked_plane->id;
5565*4882a593Smuzhiyun
5566*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm,
5567*4882a593Smuzhiyun !intel_wm_plane_visible(crtc_state, plane_state));
5568*4882a593Smuzhiyun drm_WARN_ON(&dev_priv->drm, !fb->format->is_yuv ||
5569*4882a593Smuzhiyun fb->format->num_planes == 1);
5570*4882a593Smuzhiyun
5571*4882a593Smuzhiyun ret = skl_build_plane_wm_single(crtc_state, plane_state,
5572*4882a593Smuzhiyun y_plane_id, 0);
5573*4882a593Smuzhiyun if (ret)
5574*4882a593Smuzhiyun return ret;
5575*4882a593Smuzhiyun
5576*4882a593Smuzhiyun ret = skl_build_plane_wm_single(crtc_state, plane_state,
5577*4882a593Smuzhiyun plane_id, 1);
5578*4882a593Smuzhiyun if (ret)
5579*4882a593Smuzhiyun return ret;
5580*4882a593Smuzhiyun } else if (intel_wm_plane_visible(crtc_state, plane_state)) {
5581*4882a593Smuzhiyun ret = skl_build_plane_wm_single(crtc_state, plane_state,
5582*4882a593Smuzhiyun plane_id, 0);
5583*4882a593Smuzhiyun if (ret)
5584*4882a593Smuzhiyun return ret;
5585*4882a593Smuzhiyun }
5586*4882a593Smuzhiyun
5587*4882a593Smuzhiyun return 0;
5588*4882a593Smuzhiyun }
5589*4882a593Smuzhiyun
skl_build_pipe_wm(struct intel_crtc_state * crtc_state)5590*4882a593Smuzhiyun static int skl_build_pipe_wm(struct intel_crtc_state *crtc_state)
5591*4882a593Smuzhiyun {
5592*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
5593*4882a593Smuzhiyun struct skl_pipe_wm *pipe_wm = &crtc_state->wm.skl.optimal;
5594*4882a593Smuzhiyun struct intel_plane *plane;
5595*4882a593Smuzhiyun const struct intel_plane_state *plane_state;
5596*4882a593Smuzhiyun int ret;
5597*4882a593Smuzhiyun
5598*4882a593Smuzhiyun /*
5599*4882a593Smuzhiyun * We'll only calculate watermarks for planes that are actually
5600*4882a593Smuzhiyun * enabled, so make sure all other planes are set as disabled.
5601*4882a593Smuzhiyun */
5602*4882a593Smuzhiyun memset(pipe_wm->planes, 0, sizeof(pipe_wm->planes));
5603*4882a593Smuzhiyun
5604*4882a593Smuzhiyun intel_atomic_crtc_state_for_each_plane_state(plane, plane_state,
5605*4882a593Smuzhiyun crtc_state) {
5606*4882a593Smuzhiyun
5607*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 11)
5608*4882a593Smuzhiyun ret = icl_build_plane_wm(crtc_state, plane_state);
5609*4882a593Smuzhiyun else
5610*4882a593Smuzhiyun ret = skl_build_plane_wm(crtc_state, plane_state);
5611*4882a593Smuzhiyun if (ret)
5612*4882a593Smuzhiyun return ret;
5613*4882a593Smuzhiyun }
5614*4882a593Smuzhiyun
5615*4882a593Smuzhiyun return 0;
5616*4882a593Smuzhiyun }
5617*4882a593Smuzhiyun
skl_ddb_entry_write(struct drm_i915_private * dev_priv,i915_reg_t reg,const struct skl_ddb_entry * entry)5618*4882a593Smuzhiyun static void skl_ddb_entry_write(struct drm_i915_private *dev_priv,
5619*4882a593Smuzhiyun i915_reg_t reg,
5620*4882a593Smuzhiyun const struct skl_ddb_entry *entry)
5621*4882a593Smuzhiyun {
5622*4882a593Smuzhiyun if (entry->end)
5623*4882a593Smuzhiyun intel_de_write_fw(dev_priv, reg,
5624*4882a593Smuzhiyun (entry->end - 1) << 16 | entry->start);
5625*4882a593Smuzhiyun else
5626*4882a593Smuzhiyun intel_de_write_fw(dev_priv, reg, 0);
5627*4882a593Smuzhiyun }
5628*4882a593Smuzhiyun
skl_write_wm_level(struct drm_i915_private * dev_priv,i915_reg_t reg,const struct skl_wm_level * level)5629*4882a593Smuzhiyun static void skl_write_wm_level(struct drm_i915_private *dev_priv,
5630*4882a593Smuzhiyun i915_reg_t reg,
5631*4882a593Smuzhiyun const struct skl_wm_level *level)
5632*4882a593Smuzhiyun {
5633*4882a593Smuzhiyun u32 val = 0;
5634*4882a593Smuzhiyun
5635*4882a593Smuzhiyun if (level->plane_en)
5636*4882a593Smuzhiyun val |= PLANE_WM_EN;
5637*4882a593Smuzhiyun if (level->ignore_lines)
5638*4882a593Smuzhiyun val |= PLANE_WM_IGNORE_LINES;
5639*4882a593Smuzhiyun val |= level->plane_res_b;
5640*4882a593Smuzhiyun val |= level->plane_res_l << PLANE_WM_LINES_SHIFT;
5641*4882a593Smuzhiyun
5642*4882a593Smuzhiyun intel_de_write_fw(dev_priv, reg, val);
5643*4882a593Smuzhiyun }
5644*4882a593Smuzhiyun
skl_write_plane_wm(struct intel_plane * plane,const struct intel_crtc_state * crtc_state)5645*4882a593Smuzhiyun void skl_write_plane_wm(struct intel_plane *plane,
5646*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state)
5647*4882a593Smuzhiyun {
5648*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
5649*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
5650*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
5651*4882a593Smuzhiyun enum pipe pipe = plane->pipe;
5652*4882a593Smuzhiyun const struct skl_plane_wm *wm =
5653*4882a593Smuzhiyun &crtc_state->wm.skl.optimal.planes[plane_id];
5654*4882a593Smuzhiyun const struct skl_ddb_entry *ddb_y =
5655*4882a593Smuzhiyun &crtc_state->wm.skl.plane_ddb_y[plane_id];
5656*4882a593Smuzhiyun const struct skl_ddb_entry *ddb_uv =
5657*4882a593Smuzhiyun &crtc_state->wm.skl.plane_ddb_uv[plane_id];
5658*4882a593Smuzhiyun
5659*4882a593Smuzhiyun for (level = 0; level <= max_level; level++) {
5660*4882a593Smuzhiyun const struct skl_wm_level *wm_level;
5661*4882a593Smuzhiyun
5662*4882a593Smuzhiyun wm_level = skl_plane_wm_level(crtc_state, plane_id, level);
5663*4882a593Smuzhiyun
5664*4882a593Smuzhiyun skl_write_wm_level(dev_priv, PLANE_WM(pipe, plane_id, level),
5665*4882a593Smuzhiyun wm_level);
5666*4882a593Smuzhiyun }
5667*4882a593Smuzhiyun skl_write_wm_level(dev_priv, PLANE_WM_TRANS(pipe, plane_id),
5668*4882a593Smuzhiyun &wm->trans_wm);
5669*4882a593Smuzhiyun
5670*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 11) {
5671*4882a593Smuzhiyun skl_ddb_entry_write(dev_priv,
5672*4882a593Smuzhiyun PLANE_BUF_CFG(pipe, plane_id), ddb_y);
5673*4882a593Smuzhiyun return;
5674*4882a593Smuzhiyun }
5675*4882a593Smuzhiyun
5676*4882a593Smuzhiyun if (wm->is_planar)
5677*4882a593Smuzhiyun swap(ddb_y, ddb_uv);
5678*4882a593Smuzhiyun
5679*4882a593Smuzhiyun skl_ddb_entry_write(dev_priv,
5680*4882a593Smuzhiyun PLANE_BUF_CFG(pipe, plane_id), ddb_y);
5681*4882a593Smuzhiyun skl_ddb_entry_write(dev_priv,
5682*4882a593Smuzhiyun PLANE_NV12_BUF_CFG(pipe, plane_id), ddb_uv);
5683*4882a593Smuzhiyun }
5684*4882a593Smuzhiyun
skl_write_cursor_wm(struct intel_plane * plane,const struct intel_crtc_state * crtc_state)5685*4882a593Smuzhiyun void skl_write_cursor_wm(struct intel_plane *plane,
5686*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state)
5687*4882a593Smuzhiyun {
5688*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
5689*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
5690*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
5691*4882a593Smuzhiyun enum pipe pipe = plane->pipe;
5692*4882a593Smuzhiyun const struct skl_plane_wm *wm =
5693*4882a593Smuzhiyun &crtc_state->wm.skl.optimal.planes[plane_id];
5694*4882a593Smuzhiyun const struct skl_ddb_entry *ddb =
5695*4882a593Smuzhiyun &crtc_state->wm.skl.plane_ddb_y[plane_id];
5696*4882a593Smuzhiyun
5697*4882a593Smuzhiyun for (level = 0; level <= max_level; level++) {
5698*4882a593Smuzhiyun const struct skl_wm_level *wm_level;
5699*4882a593Smuzhiyun
5700*4882a593Smuzhiyun wm_level = skl_plane_wm_level(crtc_state, plane_id, level);
5701*4882a593Smuzhiyun
5702*4882a593Smuzhiyun skl_write_wm_level(dev_priv, CUR_WM(pipe, level),
5703*4882a593Smuzhiyun wm_level);
5704*4882a593Smuzhiyun }
5705*4882a593Smuzhiyun skl_write_wm_level(dev_priv, CUR_WM_TRANS(pipe), &wm->trans_wm);
5706*4882a593Smuzhiyun
5707*4882a593Smuzhiyun skl_ddb_entry_write(dev_priv, CUR_BUF_CFG(pipe), ddb);
5708*4882a593Smuzhiyun }
5709*4882a593Smuzhiyun
skl_wm_level_equals(const struct skl_wm_level * l1,const struct skl_wm_level * l2)5710*4882a593Smuzhiyun bool skl_wm_level_equals(const struct skl_wm_level *l1,
5711*4882a593Smuzhiyun const struct skl_wm_level *l2)
5712*4882a593Smuzhiyun {
5713*4882a593Smuzhiyun return l1->plane_en == l2->plane_en &&
5714*4882a593Smuzhiyun l1->ignore_lines == l2->ignore_lines &&
5715*4882a593Smuzhiyun l1->plane_res_l == l2->plane_res_l &&
5716*4882a593Smuzhiyun l1->plane_res_b == l2->plane_res_b;
5717*4882a593Smuzhiyun }
5718*4882a593Smuzhiyun
skl_plane_wm_equals(struct drm_i915_private * dev_priv,const struct skl_plane_wm * wm1,const struct skl_plane_wm * wm2)5719*4882a593Smuzhiyun static bool skl_plane_wm_equals(struct drm_i915_private *dev_priv,
5720*4882a593Smuzhiyun const struct skl_plane_wm *wm1,
5721*4882a593Smuzhiyun const struct skl_plane_wm *wm2)
5722*4882a593Smuzhiyun {
5723*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
5724*4882a593Smuzhiyun
5725*4882a593Smuzhiyun for (level = 0; level <= max_level; level++) {
5726*4882a593Smuzhiyun /*
5727*4882a593Smuzhiyun * We don't check uv_wm as the hardware doesn't actually
5728*4882a593Smuzhiyun * use it. It only gets used for calculating the required
5729*4882a593Smuzhiyun * ddb allocation.
5730*4882a593Smuzhiyun */
5731*4882a593Smuzhiyun if (!skl_wm_level_equals(&wm1->wm[level], &wm2->wm[level]))
5732*4882a593Smuzhiyun return false;
5733*4882a593Smuzhiyun }
5734*4882a593Smuzhiyun
5735*4882a593Smuzhiyun return skl_wm_level_equals(&wm1->trans_wm, &wm2->trans_wm);
5736*4882a593Smuzhiyun }
5737*4882a593Smuzhiyun
skl_ddb_entries_overlap(const struct skl_ddb_entry * a,const struct skl_ddb_entry * b)5738*4882a593Smuzhiyun static bool skl_ddb_entries_overlap(const struct skl_ddb_entry *a,
5739*4882a593Smuzhiyun const struct skl_ddb_entry *b)
5740*4882a593Smuzhiyun {
5741*4882a593Smuzhiyun return a->start < b->end && b->start < a->end;
5742*4882a593Smuzhiyun }
5743*4882a593Smuzhiyun
skl_ddb_allocation_overlaps(const struct skl_ddb_entry * ddb,const struct skl_ddb_entry * entries,int num_entries,int ignore_idx)5744*4882a593Smuzhiyun bool skl_ddb_allocation_overlaps(const struct skl_ddb_entry *ddb,
5745*4882a593Smuzhiyun const struct skl_ddb_entry *entries,
5746*4882a593Smuzhiyun int num_entries, int ignore_idx)
5747*4882a593Smuzhiyun {
5748*4882a593Smuzhiyun int i;
5749*4882a593Smuzhiyun
5750*4882a593Smuzhiyun for (i = 0; i < num_entries; i++) {
5751*4882a593Smuzhiyun if (i != ignore_idx &&
5752*4882a593Smuzhiyun skl_ddb_entries_overlap(ddb, &entries[i]))
5753*4882a593Smuzhiyun return true;
5754*4882a593Smuzhiyun }
5755*4882a593Smuzhiyun
5756*4882a593Smuzhiyun return false;
5757*4882a593Smuzhiyun }
5758*4882a593Smuzhiyun
5759*4882a593Smuzhiyun static int
skl_ddb_add_affected_planes(const struct intel_crtc_state * old_crtc_state,struct intel_crtc_state * new_crtc_state)5760*4882a593Smuzhiyun skl_ddb_add_affected_planes(const struct intel_crtc_state *old_crtc_state,
5761*4882a593Smuzhiyun struct intel_crtc_state *new_crtc_state)
5762*4882a593Smuzhiyun {
5763*4882a593Smuzhiyun struct intel_atomic_state *state = to_intel_atomic_state(new_crtc_state->uapi.state);
5764*4882a593Smuzhiyun struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
5765*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5766*4882a593Smuzhiyun struct intel_plane *plane;
5767*4882a593Smuzhiyun
5768*4882a593Smuzhiyun for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5769*4882a593Smuzhiyun struct intel_plane_state *plane_state;
5770*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
5771*4882a593Smuzhiyun
5772*4882a593Smuzhiyun if (skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_y[plane_id],
5773*4882a593Smuzhiyun &new_crtc_state->wm.skl.plane_ddb_y[plane_id]) &&
5774*4882a593Smuzhiyun skl_ddb_entry_equal(&old_crtc_state->wm.skl.plane_ddb_uv[plane_id],
5775*4882a593Smuzhiyun &new_crtc_state->wm.skl.plane_ddb_uv[plane_id]))
5776*4882a593Smuzhiyun continue;
5777*4882a593Smuzhiyun
5778*4882a593Smuzhiyun plane_state = intel_atomic_get_plane_state(state, plane);
5779*4882a593Smuzhiyun if (IS_ERR(plane_state))
5780*4882a593Smuzhiyun return PTR_ERR(plane_state);
5781*4882a593Smuzhiyun
5782*4882a593Smuzhiyun new_crtc_state->update_planes |= BIT(plane_id);
5783*4882a593Smuzhiyun }
5784*4882a593Smuzhiyun
5785*4882a593Smuzhiyun return 0;
5786*4882a593Smuzhiyun }
5787*4882a593Smuzhiyun
5788*4882a593Smuzhiyun static int
skl_compute_ddb(struct intel_atomic_state * state)5789*4882a593Smuzhiyun skl_compute_ddb(struct intel_atomic_state *state)
5790*4882a593Smuzhiyun {
5791*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5792*4882a593Smuzhiyun const struct intel_dbuf_state *old_dbuf_state;
5793*4882a593Smuzhiyun const struct intel_dbuf_state *new_dbuf_state;
5794*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state;
5795*4882a593Smuzhiyun struct intel_crtc_state *new_crtc_state;
5796*4882a593Smuzhiyun struct intel_crtc *crtc;
5797*4882a593Smuzhiyun int ret, i;
5798*4882a593Smuzhiyun
5799*4882a593Smuzhiyun for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
5800*4882a593Smuzhiyun new_crtc_state, i) {
5801*4882a593Smuzhiyun ret = skl_allocate_pipe_ddb(new_crtc_state);
5802*4882a593Smuzhiyun if (ret)
5803*4882a593Smuzhiyun return ret;
5804*4882a593Smuzhiyun
5805*4882a593Smuzhiyun ret = skl_ddb_add_affected_planes(old_crtc_state,
5806*4882a593Smuzhiyun new_crtc_state);
5807*4882a593Smuzhiyun if (ret)
5808*4882a593Smuzhiyun return ret;
5809*4882a593Smuzhiyun }
5810*4882a593Smuzhiyun
5811*4882a593Smuzhiyun old_dbuf_state = intel_atomic_get_old_dbuf_state(state);
5812*4882a593Smuzhiyun new_dbuf_state = intel_atomic_get_new_dbuf_state(state);
5813*4882a593Smuzhiyun
5814*4882a593Smuzhiyun if (new_dbuf_state &&
5815*4882a593Smuzhiyun new_dbuf_state->enabled_slices != old_dbuf_state->enabled_slices)
5816*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
5817*4882a593Smuzhiyun "Enabled dbuf slices 0x%x -> 0x%x (out of %d dbuf slices)\n",
5818*4882a593Smuzhiyun old_dbuf_state->enabled_slices,
5819*4882a593Smuzhiyun new_dbuf_state->enabled_slices,
5820*4882a593Smuzhiyun INTEL_INFO(dev_priv)->num_supported_dbuf_slices);
5821*4882a593Smuzhiyun
5822*4882a593Smuzhiyun return 0;
5823*4882a593Smuzhiyun }
5824*4882a593Smuzhiyun
enast(bool enable)5825*4882a593Smuzhiyun static char enast(bool enable)
5826*4882a593Smuzhiyun {
5827*4882a593Smuzhiyun return enable ? '*' : ' ';
5828*4882a593Smuzhiyun }
5829*4882a593Smuzhiyun
5830*4882a593Smuzhiyun static void
skl_print_wm_changes(struct intel_atomic_state * state)5831*4882a593Smuzhiyun skl_print_wm_changes(struct intel_atomic_state *state)
5832*4882a593Smuzhiyun {
5833*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5834*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state;
5835*4882a593Smuzhiyun const struct intel_crtc_state *new_crtc_state;
5836*4882a593Smuzhiyun struct intel_plane *plane;
5837*4882a593Smuzhiyun struct intel_crtc *crtc;
5838*4882a593Smuzhiyun int i;
5839*4882a593Smuzhiyun
5840*4882a593Smuzhiyun if (!drm_debug_enabled(DRM_UT_KMS))
5841*4882a593Smuzhiyun return;
5842*4882a593Smuzhiyun
5843*4882a593Smuzhiyun for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
5844*4882a593Smuzhiyun new_crtc_state, i) {
5845*4882a593Smuzhiyun const struct skl_pipe_wm *old_pipe_wm, *new_pipe_wm;
5846*4882a593Smuzhiyun
5847*4882a593Smuzhiyun old_pipe_wm = &old_crtc_state->wm.skl.optimal;
5848*4882a593Smuzhiyun new_pipe_wm = &new_crtc_state->wm.skl.optimal;
5849*4882a593Smuzhiyun
5850*4882a593Smuzhiyun for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5851*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
5852*4882a593Smuzhiyun const struct skl_ddb_entry *old, *new;
5853*4882a593Smuzhiyun
5854*4882a593Smuzhiyun old = &old_crtc_state->wm.skl.plane_ddb_y[plane_id];
5855*4882a593Smuzhiyun new = &new_crtc_state->wm.skl.plane_ddb_y[plane_id];
5856*4882a593Smuzhiyun
5857*4882a593Smuzhiyun if (skl_ddb_entry_equal(old, new))
5858*4882a593Smuzhiyun continue;
5859*4882a593Smuzhiyun
5860*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
5861*4882a593Smuzhiyun "[PLANE:%d:%s] ddb (%4d - %4d) -> (%4d - %4d), size %4d -> %4d\n",
5862*4882a593Smuzhiyun plane->base.base.id, plane->base.name,
5863*4882a593Smuzhiyun old->start, old->end, new->start, new->end,
5864*4882a593Smuzhiyun skl_ddb_entry_size(old), skl_ddb_entry_size(new));
5865*4882a593Smuzhiyun }
5866*4882a593Smuzhiyun
5867*4882a593Smuzhiyun for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
5868*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
5869*4882a593Smuzhiyun const struct skl_plane_wm *old_wm, *new_wm;
5870*4882a593Smuzhiyun
5871*4882a593Smuzhiyun old_wm = &old_pipe_wm->planes[plane_id];
5872*4882a593Smuzhiyun new_wm = &new_pipe_wm->planes[plane_id];
5873*4882a593Smuzhiyun
5874*4882a593Smuzhiyun if (skl_plane_wm_equals(dev_priv, old_wm, new_wm))
5875*4882a593Smuzhiyun continue;
5876*4882a593Smuzhiyun
5877*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
5878*4882a593Smuzhiyun "[PLANE:%d:%s] level %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm"
5879*4882a593Smuzhiyun " -> %cwm0,%cwm1,%cwm2,%cwm3,%cwm4,%cwm5,%cwm6,%cwm7,%ctwm,%cswm\n",
5880*4882a593Smuzhiyun plane->base.base.id, plane->base.name,
5881*4882a593Smuzhiyun enast(old_wm->wm[0].plane_en), enast(old_wm->wm[1].plane_en),
5882*4882a593Smuzhiyun enast(old_wm->wm[2].plane_en), enast(old_wm->wm[3].plane_en),
5883*4882a593Smuzhiyun enast(old_wm->wm[4].plane_en), enast(old_wm->wm[5].plane_en),
5884*4882a593Smuzhiyun enast(old_wm->wm[6].plane_en), enast(old_wm->wm[7].plane_en),
5885*4882a593Smuzhiyun enast(old_wm->trans_wm.plane_en),
5886*4882a593Smuzhiyun enast(old_wm->sagv_wm0.plane_en),
5887*4882a593Smuzhiyun enast(new_wm->wm[0].plane_en), enast(new_wm->wm[1].plane_en),
5888*4882a593Smuzhiyun enast(new_wm->wm[2].plane_en), enast(new_wm->wm[3].plane_en),
5889*4882a593Smuzhiyun enast(new_wm->wm[4].plane_en), enast(new_wm->wm[5].plane_en),
5890*4882a593Smuzhiyun enast(new_wm->wm[6].plane_en), enast(new_wm->wm[7].plane_en),
5891*4882a593Smuzhiyun enast(new_wm->trans_wm.plane_en),
5892*4882a593Smuzhiyun enast(new_wm->sagv_wm0.plane_en));
5893*4882a593Smuzhiyun
5894*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
5895*4882a593Smuzhiyun "[PLANE:%d:%s] lines %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d"
5896*4882a593Smuzhiyun " -> %c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d,%c%3d\n",
5897*4882a593Smuzhiyun plane->base.base.id, plane->base.name,
5898*4882a593Smuzhiyun enast(old_wm->wm[0].ignore_lines), old_wm->wm[0].plane_res_l,
5899*4882a593Smuzhiyun enast(old_wm->wm[1].ignore_lines), old_wm->wm[1].plane_res_l,
5900*4882a593Smuzhiyun enast(old_wm->wm[2].ignore_lines), old_wm->wm[2].plane_res_l,
5901*4882a593Smuzhiyun enast(old_wm->wm[3].ignore_lines), old_wm->wm[3].plane_res_l,
5902*4882a593Smuzhiyun enast(old_wm->wm[4].ignore_lines), old_wm->wm[4].plane_res_l,
5903*4882a593Smuzhiyun enast(old_wm->wm[5].ignore_lines), old_wm->wm[5].plane_res_l,
5904*4882a593Smuzhiyun enast(old_wm->wm[6].ignore_lines), old_wm->wm[6].plane_res_l,
5905*4882a593Smuzhiyun enast(old_wm->wm[7].ignore_lines), old_wm->wm[7].plane_res_l,
5906*4882a593Smuzhiyun enast(old_wm->trans_wm.ignore_lines), old_wm->trans_wm.plane_res_l,
5907*4882a593Smuzhiyun enast(old_wm->sagv_wm0.ignore_lines), old_wm->sagv_wm0.plane_res_l,
5908*4882a593Smuzhiyun
5909*4882a593Smuzhiyun enast(new_wm->wm[0].ignore_lines), new_wm->wm[0].plane_res_l,
5910*4882a593Smuzhiyun enast(new_wm->wm[1].ignore_lines), new_wm->wm[1].plane_res_l,
5911*4882a593Smuzhiyun enast(new_wm->wm[2].ignore_lines), new_wm->wm[2].plane_res_l,
5912*4882a593Smuzhiyun enast(new_wm->wm[3].ignore_lines), new_wm->wm[3].plane_res_l,
5913*4882a593Smuzhiyun enast(new_wm->wm[4].ignore_lines), new_wm->wm[4].plane_res_l,
5914*4882a593Smuzhiyun enast(new_wm->wm[5].ignore_lines), new_wm->wm[5].plane_res_l,
5915*4882a593Smuzhiyun enast(new_wm->wm[6].ignore_lines), new_wm->wm[6].plane_res_l,
5916*4882a593Smuzhiyun enast(new_wm->wm[7].ignore_lines), new_wm->wm[7].plane_res_l,
5917*4882a593Smuzhiyun enast(new_wm->trans_wm.ignore_lines), new_wm->trans_wm.plane_res_l,
5918*4882a593Smuzhiyun enast(new_wm->sagv_wm0.ignore_lines), new_wm->sagv_wm0.plane_res_l);
5919*4882a593Smuzhiyun
5920*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
5921*4882a593Smuzhiyun "[PLANE:%d:%s] blocks %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d"
5922*4882a593Smuzhiyun " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n",
5923*4882a593Smuzhiyun plane->base.base.id, plane->base.name,
5924*4882a593Smuzhiyun old_wm->wm[0].plane_res_b, old_wm->wm[1].plane_res_b,
5925*4882a593Smuzhiyun old_wm->wm[2].plane_res_b, old_wm->wm[3].plane_res_b,
5926*4882a593Smuzhiyun old_wm->wm[4].plane_res_b, old_wm->wm[5].plane_res_b,
5927*4882a593Smuzhiyun old_wm->wm[6].plane_res_b, old_wm->wm[7].plane_res_b,
5928*4882a593Smuzhiyun old_wm->trans_wm.plane_res_b,
5929*4882a593Smuzhiyun old_wm->sagv_wm0.plane_res_b,
5930*4882a593Smuzhiyun new_wm->wm[0].plane_res_b, new_wm->wm[1].plane_res_b,
5931*4882a593Smuzhiyun new_wm->wm[2].plane_res_b, new_wm->wm[3].plane_res_b,
5932*4882a593Smuzhiyun new_wm->wm[4].plane_res_b, new_wm->wm[5].plane_res_b,
5933*4882a593Smuzhiyun new_wm->wm[6].plane_res_b, new_wm->wm[7].plane_res_b,
5934*4882a593Smuzhiyun new_wm->trans_wm.plane_res_b,
5935*4882a593Smuzhiyun new_wm->sagv_wm0.plane_res_b);
5936*4882a593Smuzhiyun
5937*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
5938*4882a593Smuzhiyun "[PLANE:%d:%s] min_ddb %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d"
5939*4882a593Smuzhiyun " -> %4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d,%4d\n",
5940*4882a593Smuzhiyun plane->base.base.id, plane->base.name,
5941*4882a593Smuzhiyun old_wm->wm[0].min_ddb_alloc, old_wm->wm[1].min_ddb_alloc,
5942*4882a593Smuzhiyun old_wm->wm[2].min_ddb_alloc, old_wm->wm[3].min_ddb_alloc,
5943*4882a593Smuzhiyun old_wm->wm[4].min_ddb_alloc, old_wm->wm[5].min_ddb_alloc,
5944*4882a593Smuzhiyun old_wm->wm[6].min_ddb_alloc, old_wm->wm[7].min_ddb_alloc,
5945*4882a593Smuzhiyun old_wm->trans_wm.min_ddb_alloc,
5946*4882a593Smuzhiyun old_wm->sagv_wm0.min_ddb_alloc,
5947*4882a593Smuzhiyun new_wm->wm[0].min_ddb_alloc, new_wm->wm[1].min_ddb_alloc,
5948*4882a593Smuzhiyun new_wm->wm[2].min_ddb_alloc, new_wm->wm[3].min_ddb_alloc,
5949*4882a593Smuzhiyun new_wm->wm[4].min_ddb_alloc, new_wm->wm[5].min_ddb_alloc,
5950*4882a593Smuzhiyun new_wm->wm[6].min_ddb_alloc, new_wm->wm[7].min_ddb_alloc,
5951*4882a593Smuzhiyun new_wm->trans_wm.min_ddb_alloc,
5952*4882a593Smuzhiyun new_wm->sagv_wm0.min_ddb_alloc);
5953*4882a593Smuzhiyun }
5954*4882a593Smuzhiyun }
5955*4882a593Smuzhiyun }
5956*4882a593Smuzhiyun
intel_add_affected_pipes(struct intel_atomic_state * state,u8 pipe_mask)5957*4882a593Smuzhiyun static int intel_add_affected_pipes(struct intel_atomic_state *state,
5958*4882a593Smuzhiyun u8 pipe_mask)
5959*4882a593Smuzhiyun {
5960*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5961*4882a593Smuzhiyun struct intel_crtc *crtc;
5962*4882a593Smuzhiyun
5963*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
5964*4882a593Smuzhiyun struct intel_crtc_state *crtc_state;
5965*4882a593Smuzhiyun
5966*4882a593Smuzhiyun if ((pipe_mask & BIT(crtc->pipe)) == 0)
5967*4882a593Smuzhiyun continue;
5968*4882a593Smuzhiyun
5969*4882a593Smuzhiyun crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5970*4882a593Smuzhiyun if (IS_ERR(crtc_state))
5971*4882a593Smuzhiyun return PTR_ERR(crtc_state);
5972*4882a593Smuzhiyun }
5973*4882a593Smuzhiyun
5974*4882a593Smuzhiyun return 0;
5975*4882a593Smuzhiyun }
5976*4882a593Smuzhiyun
5977*4882a593Smuzhiyun static int
skl_ddb_add_affected_pipes(struct intel_atomic_state * state)5978*4882a593Smuzhiyun skl_ddb_add_affected_pipes(struct intel_atomic_state *state)
5979*4882a593Smuzhiyun {
5980*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5981*4882a593Smuzhiyun struct intel_crtc_state *crtc_state;
5982*4882a593Smuzhiyun struct intel_crtc *crtc;
5983*4882a593Smuzhiyun int i, ret;
5984*4882a593Smuzhiyun
5985*4882a593Smuzhiyun if (dev_priv->wm.distrust_bios_wm) {
5986*4882a593Smuzhiyun /*
5987*4882a593Smuzhiyun * skl_ddb_get_pipe_allocation_limits() currently requires
5988*4882a593Smuzhiyun * all active pipes to be included in the state so that
5989*4882a593Smuzhiyun * it can redistribute the dbuf among them, and it really
5990*4882a593Smuzhiyun * wants to recompute things when distrust_bios_wm is set
5991*4882a593Smuzhiyun * so we add all the pipes to the state.
5992*4882a593Smuzhiyun */
5993*4882a593Smuzhiyun ret = intel_add_affected_pipes(state, ~0);
5994*4882a593Smuzhiyun if (ret)
5995*4882a593Smuzhiyun return ret;
5996*4882a593Smuzhiyun }
5997*4882a593Smuzhiyun
5998*4882a593Smuzhiyun for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5999*4882a593Smuzhiyun struct intel_dbuf_state *new_dbuf_state;
6000*4882a593Smuzhiyun const struct intel_dbuf_state *old_dbuf_state;
6001*4882a593Smuzhiyun
6002*4882a593Smuzhiyun new_dbuf_state = intel_atomic_get_dbuf_state(state);
6003*4882a593Smuzhiyun if (IS_ERR(new_dbuf_state))
6004*4882a593Smuzhiyun return PTR_ERR(new_dbuf_state);
6005*4882a593Smuzhiyun
6006*4882a593Smuzhiyun old_dbuf_state = intel_atomic_get_old_dbuf_state(state);
6007*4882a593Smuzhiyun
6008*4882a593Smuzhiyun new_dbuf_state->active_pipes =
6009*4882a593Smuzhiyun intel_calc_active_pipes(state, old_dbuf_state->active_pipes);
6010*4882a593Smuzhiyun
6011*4882a593Smuzhiyun if (old_dbuf_state->active_pipes == new_dbuf_state->active_pipes)
6012*4882a593Smuzhiyun break;
6013*4882a593Smuzhiyun
6014*4882a593Smuzhiyun ret = intel_atomic_lock_global_state(&new_dbuf_state->base);
6015*4882a593Smuzhiyun if (ret)
6016*4882a593Smuzhiyun return ret;
6017*4882a593Smuzhiyun
6018*4882a593Smuzhiyun /*
6019*4882a593Smuzhiyun * skl_ddb_get_pipe_allocation_limits() currently requires
6020*4882a593Smuzhiyun * all active pipes to be included in the state so that
6021*4882a593Smuzhiyun * it can redistribute the dbuf among them.
6022*4882a593Smuzhiyun */
6023*4882a593Smuzhiyun ret = intel_add_affected_pipes(state,
6024*4882a593Smuzhiyun new_dbuf_state->active_pipes);
6025*4882a593Smuzhiyun if (ret)
6026*4882a593Smuzhiyun return ret;
6027*4882a593Smuzhiyun
6028*4882a593Smuzhiyun break;
6029*4882a593Smuzhiyun }
6030*4882a593Smuzhiyun
6031*4882a593Smuzhiyun return 0;
6032*4882a593Smuzhiyun }
6033*4882a593Smuzhiyun
6034*4882a593Smuzhiyun /*
6035*4882a593Smuzhiyun * To make sure the cursor watermark registers are always consistent
6036*4882a593Smuzhiyun * with our computed state the following scenario needs special
6037*4882a593Smuzhiyun * treatment:
6038*4882a593Smuzhiyun *
6039*4882a593Smuzhiyun * 1. enable cursor
6040*4882a593Smuzhiyun * 2. move cursor entirely offscreen
6041*4882a593Smuzhiyun * 3. disable cursor
6042*4882a593Smuzhiyun *
6043*4882a593Smuzhiyun * Step 2. does call .disable_plane() but does not zero the watermarks
6044*4882a593Smuzhiyun * (since we consider an offscreen cursor still active for the purposes
6045*4882a593Smuzhiyun * of watermarks). Step 3. would not normally call .disable_plane()
6046*4882a593Smuzhiyun * because the actual plane visibility isn't changing, and we don't
6047*4882a593Smuzhiyun * deallocate the cursor ddb until the pipe gets disabled. So we must
6048*4882a593Smuzhiyun * force step 3. to call .disable_plane() to update the watermark
6049*4882a593Smuzhiyun * registers properly.
6050*4882a593Smuzhiyun *
6051*4882a593Smuzhiyun * Other planes do not suffer from this issues as their watermarks are
6052*4882a593Smuzhiyun * calculated based on the actual plane visibility. The only time this
6053*4882a593Smuzhiyun * can trigger for the other planes is during the initial readout as the
6054*4882a593Smuzhiyun * default value of the watermarks registers is not zero.
6055*4882a593Smuzhiyun */
skl_wm_add_affected_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)6056*4882a593Smuzhiyun static int skl_wm_add_affected_planes(struct intel_atomic_state *state,
6057*4882a593Smuzhiyun struct intel_crtc *crtc)
6058*4882a593Smuzhiyun {
6059*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6060*4882a593Smuzhiyun const struct intel_crtc_state *old_crtc_state =
6061*4882a593Smuzhiyun intel_atomic_get_old_crtc_state(state, crtc);
6062*4882a593Smuzhiyun struct intel_crtc_state *new_crtc_state =
6063*4882a593Smuzhiyun intel_atomic_get_new_crtc_state(state, crtc);
6064*4882a593Smuzhiyun struct intel_plane *plane;
6065*4882a593Smuzhiyun
6066*4882a593Smuzhiyun for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
6067*4882a593Smuzhiyun struct intel_plane_state *plane_state;
6068*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
6069*4882a593Smuzhiyun
6070*4882a593Smuzhiyun /*
6071*4882a593Smuzhiyun * Force a full wm update for every plane on modeset.
6072*4882a593Smuzhiyun * Required because the reset value of the wm registers
6073*4882a593Smuzhiyun * is non-zero, whereas we want all disabled planes to
6074*4882a593Smuzhiyun * have zero watermarks. So if we turn off the relevant
6075*4882a593Smuzhiyun * power well the hardware state will go out of sync
6076*4882a593Smuzhiyun * with the software state.
6077*4882a593Smuzhiyun */
6078*4882a593Smuzhiyun if (!drm_atomic_crtc_needs_modeset(&new_crtc_state->uapi) &&
6079*4882a593Smuzhiyun skl_plane_wm_equals(dev_priv,
6080*4882a593Smuzhiyun &old_crtc_state->wm.skl.optimal.planes[plane_id],
6081*4882a593Smuzhiyun &new_crtc_state->wm.skl.optimal.planes[plane_id]))
6082*4882a593Smuzhiyun continue;
6083*4882a593Smuzhiyun
6084*4882a593Smuzhiyun plane_state = intel_atomic_get_plane_state(state, plane);
6085*4882a593Smuzhiyun if (IS_ERR(plane_state))
6086*4882a593Smuzhiyun return PTR_ERR(plane_state);
6087*4882a593Smuzhiyun
6088*4882a593Smuzhiyun new_crtc_state->update_planes |= BIT(plane_id);
6089*4882a593Smuzhiyun }
6090*4882a593Smuzhiyun
6091*4882a593Smuzhiyun return 0;
6092*4882a593Smuzhiyun }
6093*4882a593Smuzhiyun
6094*4882a593Smuzhiyun static int
skl_compute_wm(struct intel_atomic_state * state)6095*4882a593Smuzhiyun skl_compute_wm(struct intel_atomic_state *state)
6096*4882a593Smuzhiyun {
6097*4882a593Smuzhiyun struct intel_crtc *crtc;
6098*4882a593Smuzhiyun struct intel_crtc_state *new_crtc_state;
6099*4882a593Smuzhiyun struct intel_crtc_state *old_crtc_state;
6100*4882a593Smuzhiyun int ret, i;
6101*4882a593Smuzhiyun
6102*4882a593Smuzhiyun ret = skl_ddb_add_affected_pipes(state);
6103*4882a593Smuzhiyun if (ret)
6104*4882a593Smuzhiyun return ret;
6105*4882a593Smuzhiyun
6106*4882a593Smuzhiyun /*
6107*4882a593Smuzhiyun * Calculate WM's for all pipes that are part of this transaction.
6108*4882a593Smuzhiyun * Note that skl_ddb_add_affected_pipes may have added more CRTC's that
6109*4882a593Smuzhiyun * weren't otherwise being modified if pipe allocations had to change.
6110*4882a593Smuzhiyun */
6111*4882a593Smuzhiyun for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6112*4882a593Smuzhiyun new_crtc_state, i) {
6113*4882a593Smuzhiyun ret = skl_build_pipe_wm(new_crtc_state);
6114*4882a593Smuzhiyun if (ret)
6115*4882a593Smuzhiyun return ret;
6116*4882a593Smuzhiyun }
6117*4882a593Smuzhiyun
6118*4882a593Smuzhiyun ret = skl_compute_ddb(state);
6119*4882a593Smuzhiyun if (ret)
6120*4882a593Smuzhiyun return ret;
6121*4882a593Smuzhiyun
6122*4882a593Smuzhiyun ret = intel_compute_sagv_mask(state);
6123*4882a593Smuzhiyun if (ret)
6124*4882a593Smuzhiyun return ret;
6125*4882a593Smuzhiyun
6126*4882a593Smuzhiyun /*
6127*4882a593Smuzhiyun * skl_compute_ddb() will have adjusted the final watermarks
6128*4882a593Smuzhiyun * based on how much ddb is available. Now we can actually
6129*4882a593Smuzhiyun * check if the final watermarks changed.
6130*4882a593Smuzhiyun */
6131*4882a593Smuzhiyun for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6132*4882a593Smuzhiyun new_crtc_state, i) {
6133*4882a593Smuzhiyun ret = skl_wm_add_affected_planes(state, crtc);
6134*4882a593Smuzhiyun if (ret)
6135*4882a593Smuzhiyun return ret;
6136*4882a593Smuzhiyun }
6137*4882a593Smuzhiyun
6138*4882a593Smuzhiyun skl_print_wm_changes(state);
6139*4882a593Smuzhiyun
6140*4882a593Smuzhiyun return 0;
6141*4882a593Smuzhiyun }
6142*4882a593Smuzhiyun
ilk_compute_wm_config(struct drm_i915_private * dev_priv,struct intel_wm_config * config)6143*4882a593Smuzhiyun static void ilk_compute_wm_config(struct drm_i915_private *dev_priv,
6144*4882a593Smuzhiyun struct intel_wm_config *config)
6145*4882a593Smuzhiyun {
6146*4882a593Smuzhiyun struct intel_crtc *crtc;
6147*4882a593Smuzhiyun
6148*4882a593Smuzhiyun /* Compute the currently _active_ config */
6149*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
6150*4882a593Smuzhiyun const struct intel_pipe_wm *wm = &crtc->wm.active.ilk;
6151*4882a593Smuzhiyun
6152*4882a593Smuzhiyun if (!wm->pipe_enabled)
6153*4882a593Smuzhiyun continue;
6154*4882a593Smuzhiyun
6155*4882a593Smuzhiyun config->sprites_enabled |= wm->sprites_enabled;
6156*4882a593Smuzhiyun config->sprites_scaled |= wm->sprites_scaled;
6157*4882a593Smuzhiyun config->num_pipes_active++;
6158*4882a593Smuzhiyun }
6159*4882a593Smuzhiyun }
6160*4882a593Smuzhiyun
ilk_program_watermarks(struct drm_i915_private * dev_priv)6161*4882a593Smuzhiyun static void ilk_program_watermarks(struct drm_i915_private *dev_priv)
6162*4882a593Smuzhiyun {
6163*4882a593Smuzhiyun struct intel_pipe_wm lp_wm_1_2 = {}, lp_wm_5_6 = {}, *best_lp_wm;
6164*4882a593Smuzhiyun struct ilk_wm_maximums max;
6165*4882a593Smuzhiyun struct intel_wm_config config = {};
6166*4882a593Smuzhiyun struct ilk_wm_values results = {};
6167*4882a593Smuzhiyun enum intel_ddb_partitioning partitioning;
6168*4882a593Smuzhiyun
6169*4882a593Smuzhiyun ilk_compute_wm_config(dev_priv, &config);
6170*4882a593Smuzhiyun
6171*4882a593Smuzhiyun ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_1_2, &max);
6172*4882a593Smuzhiyun ilk_wm_merge(dev_priv, &config, &max, &lp_wm_1_2);
6173*4882a593Smuzhiyun
6174*4882a593Smuzhiyun /* 5/6 split only in single pipe config on IVB+ */
6175*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 7 &&
6176*4882a593Smuzhiyun config.num_pipes_active == 1 && config.sprites_enabled) {
6177*4882a593Smuzhiyun ilk_compute_wm_maximums(dev_priv, 1, &config, INTEL_DDB_PART_5_6, &max);
6178*4882a593Smuzhiyun ilk_wm_merge(dev_priv, &config, &max, &lp_wm_5_6);
6179*4882a593Smuzhiyun
6180*4882a593Smuzhiyun best_lp_wm = ilk_find_best_result(dev_priv, &lp_wm_1_2, &lp_wm_5_6);
6181*4882a593Smuzhiyun } else {
6182*4882a593Smuzhiyun best_lp_wm = &lp_wm_1_2;
6183*4882a593Smuzhiyun }
6184*4882a593Smuzhiyun
6185*4882a593Smuzhiyun partitioning = (best_lp_wm == &lp_wm_1_2) ?
6186*4882a593Smuzhiyun INTEL_DDB_PART_1_2 : INTEL_DDB_PART_5_6;
6187*4882a593Smuzhiyun
6188*4882a593Smuzhiyun ilk_compute_wm_results(dev_priv, best_lp_wm, partitioning, &results);
6189*4882a593Smuzhiyun
6190*4882a593Smuzhiyun ilk_write_wm_values(dev_priv, &results);
6191*4882a593Smuzhiyun }
6192*4882a593Smuzhiyun
ilk_initial_watermarks(struct intel_atomic_state * state,struct intel_crtc * crtc)6193*4882a593Smuzhiyun static void ilk_initial_watermarks(struct intel_atomic_state *state,
6194*4882a593Smuzhiyun struct intel_crtc *crtc)
6195*4882a593Smuzhiyun {
6196*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6197*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state =
6198*4882a593Smuzhiyun intel_atomic_get_new_crtc_state(state, crtc);
6199*4882a593Smuzhiyun
6200*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
6201*4882a593Smuzhiyun crtc->wm.active.ilk = crtc_state->wm.ilk.intermediate;
6202*4882a593Smuzhiyun ilk_program_watermarks(dev_priv);
6203*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
6204*4882a593Smuzhiyun }
6205*4882a593Smuzhiyun
ilk_optimize_watermarks(struct intel_atomic_state * state,struct intel_crtc * crtc)6206*4882a593Smuzhiyun static void ilk_optimize_watermarks(struct intel_atomic_state *state,
6207*4882a593Smuzhiyun struct intel_crtc *crtc)
6208*4882a593Smuzhiyun {
6209*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6210*4882a593Smuzhiyun const struct intel_crtc_state *crtc_state =
6211*4882a593Smuzhiyun intel_atomic_get_new_crtc_state(state, crtc);
6212*4882a593Smuzhiyun
6213*4882a593Smuzhiyun if (!crtc_state->wm.need_postvbl_update)
6214*4882a593Smuzhiyun return;
6215*4882a593Smuzhiyun
6216*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
6217*4882a593Smuzhiyun crtc->wm.active.ilk = crtc_state->wm.ilk.optimal;
6218*4882a593Smuzhiyun ilk_program_watermarks(dev_priv);
6219*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
6220*4882a593Smuzhiyun }
6221*4882a593Smuzhiyun
skl_wm_level_from_reg_val(u32 val,struct skl_wm_level * level)6222*4882a593Smuzhiyun static void skl_wm_level_from_reg_val(u32 val, struct skl_wm_level *level)
6223*4882a593Smuzhiyun {
6224*4882a593Smuzhiyun level->plane_en = val & PLANE_WM_EN;
6225*4882a593Smuzhiyun level->ignore_lines = val & PLANE_WM_IGNORE_LINES;
6226*4882a593Smuzhiyun level->plane_res_b = val & PLANE_WM_BLOCKS_MASK;
6227*4882a593Smuzhiyun level->plane_res_l = (val >> PLANE_WM_LINES_SHIFT) &
6228*4882a593Smuzhiyun PLANE_WM_LINES_MASK;
6229*4882a593Smuzhiyun }
6230*4882a593Smuzhiyun
skl_pipe_wm_get_hw_state(struct intel_crtc * crtc,struct skl_pipe_wm * out)6231*4882a593Smuzhiyun void skl_pipe_wm_get_hw_state(struct intel_crtc *crtc,
6232*4882a593Smuzhiyun struct skl_pipe_wm *out)
6233*4882a593Smuzhiyun {
6234*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6235*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
6236*4882a593Smuzhiyun int level, max_level;
6237*4882a593Smuzhiyun enum plane_id plane_id;
6238*4882a593Smuzhiyun u32 val;
6239*4882a593Smuzhiyun
6240*4882a593Smuzhiyun max_level = ilk_wm_max_level(dev_priv);
6241*4882a593Smuzhiyun
6242*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
6243*4882a593Smuzhiyun struct skl_plane_wm *wm = &out->planes[plane_id];
6244*4882a593Smuzhiyun
6245*4882a593Smuzhiyun for (level = 0; level <= max_level; level++) {
6246*4882a593Smuzhiyun if (plane_id != PLANE_CURSOR)
6247*4882a593Smuzhiyun val = I915_READ(PLANE_WM(pipe, plane_id, level));
6248*4882a593Smuzhiyun else
6249*4882a593Smuzhiyun val = I915_READ(CUR_WM(pipe, level));
6250*4882a593Smuzhiyun
6251*4882a593Smuzhiyun skl_wm_level_from_reg_val(val, &wm->wm[level]);
6252*4882a593Smuzhiyun }
6253*4882a593Smuzhiyun
6254*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 12)
6255*4882a593Smuzhiyun wm->sagv_wm0 = wm->wm[0];
6256*4882a593Smuzhiyun
6257*4882a593Smuzhiyun if (plane_id != PLANE_CURSOR)
6258*4882a593Smuzhiyun val = I915_READ(PLANE_WM_TRANS(pipe, plane_id));
6259*4882a593Smuzhiyun else
6260*4882a593Smuzhiyun val = I915_READ(CUR_WM_TRANS(pipe));
6261*4882a593Smuzhiyun
6262*4882a593Smuzhiyun skl_wm_level_from_reg_val(val, &wm->trans_wm);
6263*4882a593Smuzhiyun }
6264*4882a593Smuzhiyun
6265*4882a593Smuzhiyun if (!crtc->active)
6266*4882a593Smuzhiyun return;
6267*4882a593Smuzhiyun }
6268*4882a593Smuzhiyun
skl_wm_get_hw_state(struct drm_i915_private * dev_priv)6269*4882a593Smuzhiyun void skl_wm_get_hw_state(struct drm_i915_private *dev_priv)
6270*4882a593Smuzhiyun {
6271*4882a593Smuzhiyun struct intel_crtc *crtc;
6272*4882a593Smuzhiyun struct intel_crtc_state *crtc_state;
6273*4882a593Smuzhiyun
6274*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
6275*4882a593Smuzhiyun crtc_state = to_intel_crtc_state(crtc->base.state);
6276*4882a593Smuzhiyun
6277*4882a593Smuzhiyun skl_pipe_wm_get_hw_state(crtc, &crtc_state->wm.skl.optimal);
6278*4882a593Smuzhiyun }
6279*4882a593Smuzhiyun
6280*4882a593Smuzhiyun if (dev_priv->active_pipes) {
6281*4882a593Smuzhiyun /* Fully recompute DDB on first atomic commit */
6282*4882a593Smuzhiyun dev_priv->wm.distrust_bios_wm = true;
6283*4882a593Smuzhiyun }
6284*4882a593Smuzhiyun }
6285*4882a593Smuzhiyun
ilk_pipe_wm_get_hw_state(struct intel_crtc * crtc)6286*4882a593Smuzhiyun static void ilk_pipe_wm_get_hw_state(struct intel_crtc *crtc)
6287*4882a593Smuzhiyun {
6288*4882a593Smuzhiyun struct drm_device *dev = crtc->base.dev;
6289*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(dev);
6290*4882a593Smuzhiyun struct ilk_wm_values *hw = &dev_priv->wm.hw;
6291*4882a593Smuzhiyun struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
6292*4882a593Smuzhiyun struct intel_pipe_wm *active = &crtc_state->wm.ilk.optimal;
6293*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
6294*4882a593Smuzhiyun static const i915_reg_t wm0_pipe_reg[] = {
6295*4882a593Smuzhiyun [PIPE_A] = WM0_PIPEA_ILK,
6296*4882a593Smuzhiyun [PIPE_B] = WM0_PIPEB_ILK,
6297*4882a593Smuzhiyun [PIPE_C] = WM0_PIPEC_IVB,
6298*4882a593Smuzhiyun };
6299*4882a593Smuzhiyun
6300*4882a593Smuzhiyun hw->wm_pipe[pipe] = I915_READ(wm0_pipe_reg[pipe]);
6301*4882a593Smuzhiyun
6302*4882a593Smuzhiyun memset(active, 0, sizeof(*active));
6303*4882a593Smuzhiyun
6304*4882a593Smuzhiyun active->pipe_enabled = crtc->active;
6305*4882a593Smuzhiyun
6306*4882a593Smuzhiyun if (active->pipe_enabled) {
6307*4882a593Smuzhiyun u32 tmp = hw->wm_pipe[pipe];
6308*4882a593Smuzhiyun
6309*4882a593Smuzhiyun /*
6310*4882a593Smuzhiyun * For active pipes LP0 watermark is marked as
6311*4882a593Smuzhiyun * enabled, and LP1+ watermaks as disabled since
6312*4882a593Smuzhiyun * we can't really reverse compute them in case
6313*4882a593Smuzhiyun * multiple pipes are active.
6314*4882a593Smuzhiyun */
6315*4882a593Smuzhiyun active->wm[0].enable = true;
6316*4882a593Smuzhiyun active->wm[0].pri_val = (tmp & WM0_PIPE_PLANE_MASK) >> WM0_PIPE_PLANE_SHIFT;
6317*4882a593Smuzhiyun active->wm[0].spr_val = (tmp & WM0_PIPE_SPRITE_MASK) >> WM0_PIPE_SPRITE_SHIFT;
6318*4882a593Smuzhiyun active->wm[0].cur_val = tmp & WM0_PIPE_CURSOR_MASK;
6319*4882a593Smuzhiyun } else {
6320*4882a593Smuzhiyun int level, max_level = ilk_wm_max_level(dev_priv);
6321*4882a593Smuzhiyun
6322*4882a593Smuzhiyun /*
6323*4882a593Smuzhiyun * For inactive pipes, all watermark levels
6324*4882a593Smuzhiyun * should be marked as enabled but zeroed,
6325*4882a593Smuzhiyun * which is what we'd compute them to.
6326*4882a593Smuzhiyun */
6327*4882a593Smuzhiyun for (level = 0; level <= max_level; level++)
6328*4882a593Smuzhiyun active->wm[level].enable = true;
6329*4882a593Smuzhiyun }
6330*4882a593Smuzhiyun
6331*4882a593Smuzhiyun crtc->wm.active.ilk = *active;
6332*4882a593Smuzhiyun }
6333*4882a593Smuzhiyun
6334*4882a593Smuzhiyun #define _FW_WM(value, plane) \
6335*4882a593Smuzhiyun (((value) & DSPFW_ ## plane ## _MASK) >> DSPFW_ ## plane ## _SHIFT)
6336*4882a593Smuzhiyun #define _FW_WM_VLV(value, plane) \
6337*4882a593Smuzhiyun (((value) & DSPFW_ ## plane ## _MASK_VLV) >> DSPFW_ ## plane ## _SHIFT)
6338*4882a593Smuzhiyun
g4x_read_wm_values(struct drm_i915_private * dev_priv,struct g4x_wm_values * wm)6339*4882a593Smuzhiyun static void g4x_read_wm_values(struct drm_i915_private *dev_priv,
6340*4882a593Smuzhiyun struct g4x_wm_values *wm)
6341*4882a593Smuzhiyun {
6342*4882a593Smuzhiyun u32 tmp;
6343*4882a593Smuzhiyun
6344*4882a593Smuzhiyun tmp = I915_READ(DSPFW1);
6345*4882a593Smuzhiyun wm->sr.plane = _FW_WM(tmp, SR);
6346*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB);
6347*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEB);
6348*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM(tmp, PLANEA);
6349*4882a593Smuzhiyun
6350*4882a593Smuzhiyun tmp = I915_READ(DSPFW2);
6351*4882a593Smuzhiyun wm->fbc_en = tmp & DSPFW_FBC_SR_EN;
6352*4882a593Smuzhiyun wm->sr.fbc = _FW_WM(tmp, FBC_SR);
6353*4882a593Smuzhiyun wm->hpll.fbc = _FW_WM(tmp, FBC_HPLL_SR);
6354*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEB);
6355*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA);
6356*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM(tmp, SPRITEA);
6357*4882a593Smuzhiyun
6358*4882a593Smuzhiyun tmp = I915_READ(DSPFW3);
6359*4882a593Smuzhiyun wm->hpll_en = tmp & DSPFW_HPLL_SR_EN;
6360*4882a593Smuzhiyun wm->sr.cursor = _FW_WM(tmp, CURSOR_SR);
6361*4882a593Smuzhiyun wm->hpll.cursor = _FW_WM(tmp, HPLL_CURSOR);
6362*4882a593Smuzhiyun wm->hpll.plane = _FW_WM(tmp, HPLL_SR);
6363*4882a593Smuzhiyun }
6364*4882a593Smuzhiyun
vlv_read_wm_values(struct drm_i915_private * dev_priv,struct vlv_wm_values * wm)6365*4882a593Smuzhiyun static void vlv_read_wm_values(struct drm_i915_private *dev_priv,
6366*4882a593Smuzhiyun struct vlv_wm_values *wm)
6367*4882a593Smuzhiyun {
6368*4882a593Smuzhiyun enum pipe pipe;
6369*4882a593Smuzhiyun u32 tmp;
6370*4882a593Smuzhiyun
6371*4882a593Smuzhiyun for_each_pipe(dev_priv, pipe) {
6372*4882a593Smuzhiyun tmp = I915_READ(VLV_DDL(pipe));
6373*4882a593Smuzhiyun
6374*4882a593Smuzhiyun wm->ddl[pipe].plane[PLANE_PRIMARY] =
6375*4882a593Smuzhiyun (tmp >> DDL_PLANE_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
6376*4882a593Smuzhiyun wm->ddl[pipe].plane[PLANE_CURSOR] =
6377*4882a593Smuzhiyun (tmp >> DDL_CURSOR_SHIFT) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
6378*4882a593Smuzhiyun wm->ddl[pipe].plane[PLANE_SPRITE0] =
6379*4882a593Smuzhiyun (tmp >> DDL_SPRITE_SHIFT(0)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
6380*4882a593Smuzhiyun wm->ddl[pipe].plane[PLANE_SPRITE1] =
6381*4882a593Smuzhiyun (tmp >> DDL_SPRITE_SHIFT(1)) & (DDL_PRECISION_HIGH | DRAIN_LATENCY_MASK);
6382*4882a593Smuzhiyun }
6383*4882a593Smuzhiyun
6384*4882a593Smuzhiyun tmp = I915_READ(DSPFW1);
6385*4882a593Smuzhiyun wm->sr.plane = _FW_WM(tmp, SR);
6386*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORB);
6387*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEB);
6388*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEA);
6389*4882a593Smuzhiyun
6390*4882a593Smuzhiyun tmp = I915_READ(DSPFW2);
6391*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEB);
6392*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORA);
6393*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEA);
6394*4882a593Smuzhiyun
6395*4882a593Smuzhiyun tmp = I915_READ(DSPFW3);
6396*4882a593Smuzhiyun wm->sr.cursor = _FW_WM(tmp, CURSOR_SR);
6397*4882a593Smuzhiyun
6398*4882a593Smuzhiyun if (IS_CHERRYVIEW(dev_priv)) {
6399*4882a593Smuzhiyun tmp = I915_READ(DSPFW7_CHV);
6400*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED);
6401*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEC);
6402*4882a593Smuzhiyun
6403*4882a593Smuzhiyun tmp = I915_READ(DSPFW8_CHV);
6404*4882a593Smuzhiyun wm->pipe[PIPE_C].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITEF);
6405*4882a593Smuzhiyun wm->pipe[PIPE_C].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEE);
6406*4882a593Smuzhiyun
6407*4882a593Smuzhiyun tmp = I915_READ(DSPFW9_CHV);
6408*4882a593Smuzhiyun wm->pipe[PIPE_C].plane[PLANE_PRIMARY] = _FW_WM_VLV(tmp, PLANEC);
6409*4882a593Smuzhiyun wm->pipe[PIPE_C].plane[PLANE_CURSOR] = _FW_WM(tmp, CURSORC);
6410*4882a593Smuzhiyun
6411*4882a593Smuzhiyun tmp = I915_READ(DSPHOWM);
6412*4882a593Smuzhiyun wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9;
6413*4882a593Smuzhiyun wm->pipe[PIPE_C].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEF_HI) << 8;
6414*4882a593Smuzhiyun wm->pipe[PIPE_C].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEE_HI) << 8;
6415*4882a593Smuzhiyun wm->pipe[PIPE_C].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEC_HI) << 8;
6416*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8;
6417*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8;
6418*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8;
6419*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8;
6420*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8;
6421*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEA_HI) << 8;
6422*4882a593Smuzhiyun } else {
6423*4882a593Smuzhiyun tmp = I915_READ(DSPFW7);
6424*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE1] = _FW_WM_VLV(tmp, SPRITED);
6425*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE0] = _FW_WM_VLV(tmp, SPRITEC);
6426*4882a593Smuzhiyun
6427*4882a593Smuzhiyun tmp = I915_READ(DSPHOWM);
6428*4882a593Smuzhiyun wm->sr.plane |= _FW_WM(tmp, SR_HI) << 9;
6429*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITED_HI) << 8;
6430*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEC_HI) << 8;
6431*4882a593Smuzhiyun wm->pipe[PIPE_B].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEB_HI) << 8;
6432*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_SPRITE1] |= _FW_WM(tmp, SPRITEB_HI) << 8;
6433*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_SPRITE0] |= _FW_WM(tmp, SPRITEA_HI) << 8;
6434*4882a593Smuzhiyun wm->pipe[PIPE_A].plane[PLANE_PRIMARY] |= _FW_WM(tmp, PLANEA_HI) << 8;
6435*4882a593Smuzhiyun }
6436*4882a593Smuzhiyun }
6437*4882a593Smuzhiyun
6438*4882a593Smuzhiyun #undef _FW_WM
6439*4882a593Smuzhiyun #undef _FW_WM_VLV
6440*4882a593Smuzhiyun
g4x_wm_get_hw_state(struct drm_i915_private * dev_priv)6441*4882a593Smuzhiyun void g4x_wm_get_hw_state(struct drm_i915_private *dev_priv)
6442*4882a593Smuzhiyun {
6443*4882a593Smuzhiyun struct g4x_wm_values *wm = &dev_priv->wm.g4x;
6444*4882a593Smuzhiyun struct intel_crtc *crtc;
6445*4882a593Smuzhiyun
6446*4882a593Smuzhiyun g4x_read_wm_values(dev_priv, wm);
6447*4882a593Smuzhiyun
6448*4882a593Smuzhiyun wm->cxsr = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
6449*4882a593Smuzhiyun
6450*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
6451*4882a593Smuzhiyun struct intel_crtc_state *crtc_state =
6452*4882a593Smuzhiyun to_intel_crtc_state(crtc->base.state);
6453*4882a593Smuzhiyun struct g4x_wm_state *active = &crtc->wm.active.g4x;
6454*4882a593Smuzhiyun struct g4x_pipe_wm *raw;
6455*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
6456*4882a593Smuzhiyun enum plane_id plane_id;
6457*4882a593Smuzhiyun int level, max_level;
6458*4882a593Smuzhiyun
6459*4882a593Smuzhiyun active->cxsr = wm->cxsr;
6460*4882a593Smuzhiyun active->hpll_en = wm->hpll_en;
6461*4882a593Smuzhiyun active->fbc_en = wm->fbc_en;
6462*4882a593Smuzhiyun
6463*4882a593Smuzhiyun active->sr = wm->sr;
6464*4882a593Smuzhiyun active->hpll = wm->hpll;
6465*4882a593Smuzhiyun
6466*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
6467*4882a593Smuzhiyun active->wm.plane[plane_id] =
6468*4882a593Smuzhiyun wm->pipe[pipe].plane[plane_id];
6469*4882a593Smuzhiyun }
6470*4882a593Smuzhiyun
6471*4882a593Smuzhiyun if (wm->cxsr && wm->hpll_en)
6472*4882a593Smuzhiyun max_level = G4X_WM_LEVEL_HPLL;
6473*4882a593Smuzhiyun else if (wm->cxsr)
6474*4882a593Smuzhiyun max_level = G4X_WM_LEVEL_SR;
6475*4882a593Smuzhiyun else
6476*4882a593Smuzhiyun max_level = G4X_WM_LEVEL_NORMAL;
6477*4882a593Smuzhiyun
6478*4882a593Smuzhiyun level = G4X_WM_LEVEL_NORMAL;
6479*4882a593Smuzhiyun raw = &crtc_state->wm.g4x.raw[level];
6480*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id)
6481*4882a593Smuzhiyun raw->plane[plane_id] = active->wm.plane[plane_id];
6482*4882a593Smuzhiyun
6483*4882a593Smuzhiyun if (++level > max_level)
6484*4882a593Smuzhiyun goto out;
6485*4882a593Smuzhiyun
6486*4882a593Smuzhiyun raw = &crtc_state->wm.g4x.raw[level];
6487*4882a593Smuzhiyun raw->plane[PLANE_PRIMARY] = active->sr.plane;
6488*4882a593Smuzhiyun raw->plane[PLANE_CURSOR] = active->sr.cursor;
6489*4882a593Smuzhiyun raw->plane[PLANE_SPRITE0] = 0;
6490*4882a593Smuzhiyun raw->fbc = active->sr.fbc;
6491*4882a593Smuzhiyun
6492*4882a593Smuzhiyun if (++level > max_level)
6493*4882a593Smuzhiyun goto out;
6494*4882a593Smuzhiyun
6495*4882a593Smuzhiyun raw = &crtc_state->wm.g4x.raw[level];
6496*4882a593Smuzhiyun raw->plane[PLANE_PRIMARY] = active->hpll.plane;
6497*4882a593Smuzhiyun raw->plane[PLANE_CURSOR] = active->hpll.cursor;
6498*4882a593Smuzhiyun raw->plane[PLANE_SPRITE0] = 0;
6499*4882a593Smuzhiyun raw->fbc = active->hpll.fbc;
6500*4882a593Smuzhiyun
6501*4882a593Smuzhiyun out:
6502*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id)
6503*4882a593Smuzhiyun g4x_raw_plane_wm_set(crtc_state, level,
6504*4882a593Smuzhiyun plane_id, USHRT_MAX);
6505*4882a593Smuzhiyun g4x_raw_fbc_wm_set(crtc_state, level, USHRT_MAX);
6506*4882a593Smuzhiyun
6507*4882a593Smuzhiyun crtc_state->wm.g4x.optimal = *active;
6508*4882a593Smuzhiyun crtc_state->wm.g4x.intermediate = *active;
6509*4882a593Smuzhiyun
6510*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
6511*4882a593Smuzhiyun "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite=%d\n",
6512*4882a593Smuzhiyun pipe_name(pipe),
6513*4882a593Smuzhiyun wm->pipe[pipe].plane[PLANE_PRIMARY],
6514*4882a593Smuzhiyun wm->pipe[pipe].plane[PLANE_CURSOR],
6515*4882a593Smuzhiyun wm->pipe[pipe].plane[PLANE_SPRITE0]);
6516*4882a593Smuzhiyun }
6517*4882a593Smuzhiyun
6518*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
6519*4882a593Smuzhiyun "Initial SR watermarks: plane=%d, cursor=%d fbc=%d\n",
6520*4882a593Smuzhiyun wm->sr.plane, wm->sr.cursor, wm->sr.fbc);
6521*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
6522*4882a593Smuzhiyun "Initial HPLL watermarks: plane=%d, SR cursor=%d fbc=%d\n",
6523*4882a593Smuzhiyun wm->hpll.plane, wm->hpll.cursor, wm->hpll.fbc);
6524*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm, "Initial SR=%s HPLL=%s FBC=%s\n",
6525*4882a593Smuzhiyun yesno(wm->cxsr), yesno(wm->hpll_en), yesno(wm->fbc_en));
6526*4882a593Smuzhiyun }
6527*4882a593Smuzhiyun
g4x_wm_sanitize(struct drm_i915_private * dev_priv)6528*4882a593Smuzhiyun void g4x_wm_sanitize(struct drm_i915_private *dev_priv)
6529*4882a593Smuzhiyun {
6530*4882a593Smuzhiyun struct intel_plane *plane;
6531*4882a593Smuzhiyun struct intel_crtc *crtc;
6532*4882a593Smuzhiyun
6533*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
6534*4882a593Smuzhiyun
6535*4882a593Smuzhiyun for_each_intel_plane(&dev_priv->drm, plane) {
6536*4882a593Smuzhiyun struct intel_crtc *crtc =
6537*4882a593Smuzhiyun intel_get_crtc_for_pipe(dev_priv, plane->pipe);
6538*4882a593Smuzhiyun struct intel_crtc_state *crtc_state =
6539*4882a593Smuzhiyun to_intel_crtc_state(crtc->base.state);
6540*4882a593Smuzhiyun struct intel_plane_state *plane_state =
6541*4882a593Smuzhiyun to_intel_plane_state(plane->base.state);
6542*4882a593Smuzhiyun struct g4x_wm_state *wm_state = &crtc_state->wm.g4x.optimal;
6543*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
6544*4882a593Smuzhiyun int level;
6545*4882a593Smuzhiyun
6546*4882a593Smuzhiyun if (plane_state->uapi.visible)
6547*4882a593Smuzhiyun continue;
6548*4882a593Smuzhiyun
6549*4882a593Smuzhiyun for (level = 0; level < 3; level++) {
6550*4882a593Smuzhiyun struct g4x_pipe_wm *raw =
6551*4882a593Smuzhiyun &crtc_state->wm.g4x.raw[level];
6552*4882a593Smuzhiyun
6553*4882a593Smuzhiyun raw->plane[plane_id] = 0;
6554*4882a593Smuzhiyun wm_state->wm.plane[plane_id] = 0;
6555*4882a593Smuzhiyun }
6556*4882a593Smuzhiyun
6557*4882a593Smuzhiyun if (plane_id == PLANE_PRIMARY) {
6558*4882a593Smuzhiyun for (level = 0; level < 3; level++) {
6559*4882a593Smuzhiyun struct g4x_pipe_wm *raw =
6560*4882a593Smuzhiyun &crtc_state->wm.g4x.raw[level];
6561*4882a593Smuzhiyun raw->fbc = 0;
6562*4882a593Smuzhiyun }
6563*4882a593Smuzhiyun
6564*4882a593Smuzhiyun wm_state->sr.fbc = 0;
6565*4882a593Smuzhiyun wm_state->hpll.fbc = 0;
6566*4882a593Smuzhiyun wm_state->fbc_en = false;
6567*4882a593Smuzhiyun }
6568*4882a593Smuzhiyun }
6569*4882a593Smuzhiyun
6570*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
6571*4882a593Smuzhiyun struct intel_crtc_state *crtc_state =
6572*4882a593Smuzhiyun to_intel_crtc_state(crtc->base.state);
6573*4882a593Smuzhiyun
6574*4882a593Smuzhiyun crtc_state->wm.g4x.intermediate =
6575*4882a593Smuzhiyun crtc_state->wm.g4x.optimal;
6576*4882a593Smuzhiyun crtc->wm.active.g4x = crtc_state->wm.g4x.optimal;
6577*4882a593Smuzhiyun }
6578*4882a593Smuzhiyun
6579*4882a593Smuzhiyun g4x_program_watermarks(dev_priv);
6580*4882a593Smuzhiyun
6581*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
6582*4882a593Smuzhiyun }
6583*4882a593Smuzhiyun
vlv_wm_get_hw_state(struct drm_i915_private * dev_priv)6584*4882a593Smuzhiyun void vlv_wm_get_hw_state(struct drm_i915_private *dev_priv)
6585*4882a593Smuzhiyun {
6586*4882a593Smuzhiyun struct vlv_wm_values *wm = &dev_priv->wm.vlv;
6587*4882a593Smuzhiyun struct intel_crtc *crtc;
6588*4882a593Smuzhiyun u32 val;
6589*4882a593Smuzhiyun
6590*4882a593Smuzhiyun vlv_read_wm_values(dev_priv, wm);
6591*4882a593Smuzhiyun
6592*4882a593Smuzhiyun wm->cxsr = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
6593*4882a593Smuzhiyun wm->level = VLV_WM_LEVEL_PM2;
6594*4882a593Smuzhiyun
6595*4882a593Smuzhiyun if (IS_CHERRYVIEW(dev_priv)) {
6596*4882a593Smuzhiyun vlv_punit_get(dev_priv);
6597*4882a593Smuzhiyun
6598*4882a593Smuzhiyun val = vlv_punit_read(dev_priv, PUNIT_REG_DSPSSPM);
6599*4882a593Smuzhiyun if (val & DSP_MAXFIFO_PM5_ENABLE)
6600*4882a593Smuzhiyun wm->level = VLV_WM_LEVEL_PM5;
6601*4882a593Smuzhiyun
6602*4882a593Smuzhiyun /*
6603*4882a593Smuzhiyun * If DDR DVFS is disabled in the BIOS, Punit
6604*4882a593Smuzhiyun * will never ack the request. So if that happens
6605*4882a593Smuzhiyun * assume we don't have to enable/disable DDR DVFS
6606*4882a593Smuzhiyun * dynamically. To test that just set the REQ_ACK
6607*4882a593Smuzhiyun * bit to poke the Punit, but don't change the
6608*4882a593Smuzhiyun * HIGH/LOW bits so that we don't actually change
6609*4882a593Smuzhiyun * the current state.
6610*4882a593Smuzhiyun */
6611*4882a593Smuzhiyun val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
6612*4882a593Smuzhiyun val |= FORCE_DDR_FREQ_REQ_ACK;
6613*4882a593Smuzhiyun vlv_punit_write(dev_priv, PUNIT_REG_DDR_SETUP2, val);
6614*4882a593Smuzhiyun
6615*4882a593Smuzhiyun if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2) &
6616*4882a593Smuzhiyun FORCE_DDR_FREQ_REQ_ACK) == 0, 3)) {
6617*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
6618*4882a593Smuzhiyun "Punit not acking DDR DVFS request, "
6619*4882a593Smuzhiyun "assuming DDR DVFS is disabled\n");
6620*4882a593Smuzhiyun dev_priv->wm.max_level = VLV_WM_LEVEL_PM5;
6621*4882a593Smuzhiyun } else {
6622*4882a593Smuzhiyun val = vlv_punit_read(dev_priv, PUNIT_REG_DDR_SETUP2);
6623*4882a593Smuzhiyun if ((val & FORCE_DDR_HIGH_FREQ) == 0)
6624*4882a593Smuzhiyun wm->level = VLV_WM_LEVEL_DDR_DVFS;
6625*4882a593Smuzhiyun }
6626*4882a593Smuzhiyun
6627*4882a593Smuzhiyun vlv_punit_put(dev_priv);
6628*4882a593Smuzhiyun }
6629*4882a593Smuzhiyun
6630*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
6631*4882a593Smuzhiyun struct intel_crtc_state *crtc_state =
6632*4882a593Smuzhiyun to_intel_crtc_state(crtc->base.state);
6633*4882a593Smuzhiyun struct vlv_wm_state *active = &crtc->wm.active.vlv;
6634*4882a593Smuzhiyun const struct vlv_fifo_state *fifo_state =
6635*4882a593Smuzhiyun &crtc_state->wm.vlv.fifo_state;
6636*4882a593Smuzhiyun enum pipe pipe = crtc->pipe;
6637*4882a593Smuzhiyun enum plane_id plane_id;
6638*4882a593Smuzhiyun int level;
6639*4882a593Smuzhiyun
6640*4882a593Smuzhiyun vlv_get_fifo_size(crtc_state);
6641*4882a593Smuzhiyun
6642*4882a593Smuzhiyun active->num_levels = wm->level + 1;
6643*4882a593Smuzhiyun active->cxsr = wm->cxsr;
6644*4882a593Smuzhiyun
6645*4882a593Smuzhiyun for (level = 0; level < active->num_levels; level++) {
6646*4882a593Smuzhiyun struct g4x_pipe_wm *raw =
6647*4882a593Smuzhiyun &crtc_state->wm.vlv.raw[level];
6648*4882a593Smuzhiyun
6649*4882a593Smuzhiyun active->sr[level].plane = wm->sr.plane;
6650*4882a593Smuzhiyun active->sr[level].cursor = wm->sr.cursor;
6651*4882a593Smuzhiyun
6652*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id) {
6653*4882a593Smuzhiyun active->wm[level].plane[plane_id] =
6654*4882a593Smuzhiyun wm->pipe[pipe].plane[plane_id];
6655*4882a593Smuzhiyun
6656*4882a593Smuzhiyun raw->plane[plane_id] =
6657*4882a593Smuzhiyun vlv_invert_wm_value(active->wm[level].plane[plane_id],
6658*4882a593Smuzhiyun fifo_state->plane[plane_id]);
6659*4882a593Smuzhiyun }
6660*4882a593Smuzhiyun }
6661*4882a593Smuzhiyun
6662*4882a593Smuzhiyun for_each_plane_id_on_crtc(crtc, plane_id)
6663*4882a593Smuzhiyun vlv_raw_plane_wm_set(crtc_state, level,
6664*4882a593Smuzhiyun plane_id, USHRT_MAX);
6665*4882a593Smuzhiyun vlv_invalidate_wms(crtc, active, level);
6666*4882a593Smuzhiyun
6667*4882a593Smuzhiyun crtc_state->wm.vlv.optimal = *active;
6668*4882a593Smuzhiyun crtc_state->wm.vlv.intermediate = *active;
6669*4882a593Smuzhiyun
6670*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
6671*4882a593Smuzhiyun "Initial watermarks: pipe %c, plane=%d, cursor=%d, sprite0=%d, sprite1=%d\n",
6672*4882a593Smuzhiyun pipe_name(pipe),
6673*4882a593Smuzhiyun wm->pipe[pipe].plane[PLANE_PRIMARY],
6674*4882a593Smuzhiyun wm->pipe[pipe].plane[PLANE_CURSOR],
6675*4882a593Smuzhiyun wm->pipe[pipe].plane[PLANE_SPRITE0],
6676*4882a593Smuzhiyun wm->pipe[pipe].plane[PLANE_SPRITE1]);
6677*4882a593Smuzhiyun }
6678*4882a593Smuzhiyun
6679*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
6680*4882a593Smuzhiyun "Initial watermarks: SR plane=%d, SR cursor=%d level=%d cxsr=%d\n",
6681*4882a593Smuzhiyun wm->sr.plane, wm->sr.cursor, wm->level, wm->cxsr);
6682*4882a593Smuzhiyun }
6683*4882a593Smuzhiyun
vlv_wm_sanitize(struct drm_i915_private * dev_priv)6684*4882a593Smuzhiyun void vlv_wm_sanitize(struct drm_i915_private *dev_priv)
6685*4882a593Smuzhiyun {
6686*4882a593Smuzhiyun struct intel_plane *plane;
6687*4882a593Smuzhiyun struct intel_crtc *crtc;
6688*4882a593Smuzhiyun
6689*4882a593Smuzhiyun mutex_lock(&dev_priv->wm.wm_mutex);
6690*4882a593Smuzhiyun
6691*4882a593Smuzhiyun for_each_intel_plane(&dev_priv->drm, plane) {
6692*4882a593Smuzhiyun struct intel_crtc *crtc =
6693*4882a593Smuzhiyun intel_get_crtc_for_pipe(dev_priv, plane->pipe);
6694*4882a593Smuzhiyun struct intel_crtc_state *crtc_state =
6695*4882a593Smuzhiyun to_intel_crtc_state(crtc->base.state);
6696*4882a593Smuzhiyun struct intel_plane_state *plane_state =
6697*4882a593Smuzhiyun to_intel_plane_state(plane->base.state);
6698*4882a593Smuzhiyun struct vlv_wm_state *wm_state = &crtc_state->wm.vlv.optimal;
6699*4882a593Smuzhiyun const struct vlv_fifo_state *fifo_state =
6700*4882a593Smuzhiyun &crtc_state->wm.vlv.fifo_state;
6701*4882a593Smuzhiyun enum plane_id plane_id = plane->id;
6702*4882a593Smuzhiyun int level;
6703*4882a593Smuzhiyun
6704*4882a593Smuzhiyun if (plane_state->uapi.visible)
6705*4882a593Smuzhiyun continue;
6706*4882a593Smuzhiyun
6707*4882a593Smuzhiyun for (level = 0; level < wm_state->num_levels; level++) {
6708*4882a593Smuzhiyun struct g4x_pipe_wm *raw =
6709*4882a593Smuzhiyun &crtc_state->wm.vlv.raw[level];
6710*4882a593Smuzhiyun
6711*4882a593Smuzhiyun raw->plane[plane_id] = 0;
6712*4882a593Smuzhiyun
6713*4882a593Smuzhiyun wm_state->wm[level].plane[plane_id] =
6714*4882a593Smuzhiyun vlv_invert_wm_value(raw->plane[plane_id],
6715*4882a593Smuzhiyun fifo_state->plane[plane_id]);
6716*4882a593Smuzhiyun }
6717*4882a593Smuzhiyun }
6718*4882a593Smuzhiyun
6719*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc) {
6720*4882a593Smuzhiyun struct intel_crtc_state *crtc_state =
6721*4882a593Smuzhiyun to_intel_crtc_state(crtc->base.state);
6722*4882a593Smuzhiyun
6723*4882a593Smuzhiyun crtc_state->wm.vlv.intermediate =
6724*4882a593Smuzhiyun crtc_state->wm.vlv.optimal;
6725*4882a593Smuzhiyun crtc->wm.active.vlv = crtc_state->wm.vlv.optimal;
6726*4882a593Smuzhiyun }
6727*4882a593Smuzhiyun
6728*4882a593Smuzhiyun vlv_program_watermarks(dev_priv);
6729*4882a593Smuzhiyun
6730*4882a593Smuzhiyun mutex_unlock(&dev_priv->wm.wm_mutex);
6731*4882a593Smuzhiyun }
6732*4882a593Smuzhiyun
6733*4882a593Smuzhiyun /*
6734*4882a593Smuzhiyun * FIXME should probably kill this and improve
6735*4882a593Smuzhiyun * the real watermark readout/sanitation instead
6736*4882a593Smuzhiyun */
ilk_init_lp_watermarks(struct drm_i915_private * dev_priv)6737*4882a593Smuzhiyun static void ilk_init_lp_watermarks(struct drm_i915_private *dev_priv)
6738*4882a593Smuzhiyun {
6739*4882a593Smuzhiyun I915_WRITE(WM3_LP_ILK, I915_READ(WM3_LP_ILK) & ~WM1_LP_SR_EN);
6740*4882a593Smuzhiyun I915_WRITE(WM2_LP_ILK, I915_READ(WM2_LP_ILK) & ~WM1_LP_SR_EN);
6741*4882a593Smuzhiyun I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN);
6742*4882a593Smuzhiyun
6743*4882a593Smuzhiyun /*
6744*4882a593Smuzhiyun * Don't touch WM1S_LP_EN here.
6745*4882a593Smuzhiyun * Doing so could cause underruns.
6746*4882a593Smuzhiyun */
6747*4882a593Smuzhiyun }
6748*4882a593Smuzhiyun
ilk_wm_get_hw_state(struct drm_i915_private * dev_priv)6749*4882a593Smuzhiyun void ilk_wm_get_hw_state(struct drm_i915_private *dev_priv)
6750*4882a593Smuzhiyun {
6751*4882a593Smuzhiyun struct ilk_wm_values *hw = &dev_priv->wm.hw;
6752*4882a593Smuzhiyun struct intel_crtc *crtc;
6753*4882a593Smuzhiyun
6754*4882a593Smuzhiyun ilk_init_lp_watermarks(dev_priv);
6755*4882a593Smuzhiyun
6756*4882a593Smuzhiyun for_each_intel_crtc(&dev_priv->drm, crtc)
6757*4882a593Smuzhiyun ilk_pipe_wm_get_hw_state(crtc);
6758*4882a593Smuzhiyun
6759*4882a593Smuzhiyun hw->wm_lp[0] = I915_READ(WM1_LP_ILK);
6760*4882a593Smuzhiyun hw->wm_lp[1] = I915_READ(WM2_LP_ILK);
6761*4882a593Smuzhiyun hw->wm_lp[2] = I915_READ(WM3_LP_ILK);
6762*4882a593Smuzhiyun
6763*4882a593Smuzhiyun hw->wm_lp_spr[0] = I915_READ(WM1S_LP_ILK);
6764*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 7) {
6765*4882a593Smuzhiyun hw->wm_lp_spr[1] = I915_READ(WM2S_LP_IVB);
6766*4882a593Smuzhiyun hw->wm_lp_spr[2] = I915_READ(WM3S_LP_IVB);
6767*4882a593Smuzhiyun }
6768*4882a593Smuzhiyun
6769*4882a593Smuzhiyun if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
6770*4882a593Smuzhiyun hw->partitioning = (I915_READ(WM_MISC) & WM_MISC_DATA_PARTITION_5_6) ?
6771*4882a593Smuzhiyun INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
6772*4882a593Smuzhiyun else if (IS_IVYBRIDGE(dev_priv))
6773*4882a593Smuzhiyun hw->partitioning = (I915_READ(DISP_ARB_CTL2) & DISP_DATA_PARTITION_5_6) ?
6774*4882a593Smuzhiyun INTEL_DDB_PART_5_6 : INTEL_DDB_PART_1_2;
6775*4882a593Smuzhiyun
6776*4882a593Smuzhiyun hw->enable_fbc_wm =
6777*4882a593Smuzhiyun !(I915_READ(DISP_ARB_CTL) & DISP_FBC_WM_DIS);
6778*4882a593Smuzhiyun }
6779*4882a593Smuzhiyun
6780*4882a593Smuzhiyun /**
6781*4882a593Smuzhiyun * intel_update_watermarks - update FIFO watermark values based on current modes
6782*4882a593Smuzhiyun * @crtc: the #intel_crtc on which to compute the WM
6783*4882a593Smuzhiyun *
6784*4882a593Smuzhiyun * Calculate watermark values for the various WM regs based on current mode
6785*4882a593Smuzhiyun * and plane configuration.
6786*4882a593Smuzhiyun *
6787*4882a593Smuzhiyun * There are several cases to deal with here:
6788*4882a593Smuzhiyun * - normal (i.e. non-self-refresh)
6789*4882a593Smuzhiyun * - self-refresh (SR) mode
6790*4882a593Smuzhiyun * - lines are large relative to FIFO size (buffer can hold up to 2)
6791*4882a593Smuzhiyun * - lines are small relative to FIFO size (buffer can hold more than 2
6792*4882a593Smuzhiyun * lines), so need to account for TLB latency
6793*4882a593Smuzhiyun *
6794*4882a593Smuzhiyun * The normal calculation is:
6795*4882a593Smuzhiyun * watermark = dotclock * bytes per pixel * latency
6796*4882a593Smuzhiyun * where latency is platform & configuration dependent (we assume pessimal
6797*4882a593Smuzhiyun * values here).
6798*4882a593Smuzhiyun *
6799*4882a593Smuzhiyun * The SR calculation is:
6800*4882a593Smuzhiyun * watermark = (trunc(latency/line time)+1) * surface width *
6801*4882a593Smuzhiyun * bytes per pixel
6802*4882a593Smuzhiyun * where
6803*4882a593Smuzhiyun * line time = htotal / dotclock
6804*4882a593Smuzhiyun * surface width = hdisplay for normal plane and 64 for cursor
6805*4882a593Smuzhiyun * and latency is assumed to be high, as above.
6806*4882a593Smuzhiyun *
6807*4882a593Smuzhiyun * The final value programmed to the register should always be rounded up,
6808*4882a593Smuzhiyun * and include an extra 2 entries to account for clock crossings.
6809*4882a593Smuzhiyun *
6810*4882a593Smuzhiyun * We don't use the sprite, so we can ignore that. And on Crestline we have
6811*4882a593Smuzhiyun * to set the non-SR watermarks to 8.
6812*4882a593Smuzhiyun */
intel_update_watermarks(struct intel_crtc * crtc)6813*4882a593Smuzhiyun void intel_update_watermarks(struct intel_crtc *crtc)
6814*4882a593Smuzhiyun {
6815*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6816*4882a593Smuzhiyun
6817*4882a593Smuzhiyun if (dev_priv->display.update_wm)
6818*4882a593Smuzhiyun dev_priv->display.update_wm(crtc);
6819*4882a593Smuzhiyun }
6820*4882a593Smuzhiyun
intel_enable_ipc(struct drm_i915_private * dev_priv)6821*4882a593Smuzhiyun void intel_enable_ipc(struct drm_i915_private *dev_priv)
6822*4882a593Smuzhiyun {
6823*4882a593Smuzhiyun u32 val;
6824*4882a593Smuzhiyun
6825*4882a593Smuzhiyun if (!HAS_IPC(dev_priv))
6826*4882a593Smuzhiyun return;
6827*4882a593Smuzhiyun
6828*4882a593Smuzhiyun val = I915_READ(DISP_ARB_CTL2);
6829*4882a593Smuzhiyun
6830*4882a593Smuzhiyun if (dev_priv->ipc_enabled)
6831*4882a593Smuzhiyun val |= DISP_IPC_ENABLE;
6832*4882a593Smuzhiyun else
6833*4882a593Smuzhiyun val &= ~DISP_IPC_ENABLE;
6834*4882a593Smuzhiyun
6835*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL2, val);
6836*4882a593Smuzhiyun }
6837*4882a593Smuzhiyun
intel_can_enable_ipc(struct drm_i915_private * dev_priv)6838*4882a593Smuzhiyun static bool intel_can_enable_ipc(struct drm_i915_private *dev_priv)
6839*4882a593Smuzhiyun {
6840*4882a593Smuzhiyun /* Display WA #0477 WaDisableIPC: skl */
6841*4882a593Smuzhiyun if (IS_SKYLAKE(dev_priv))
6842*4882a593Smuzhiyun return false;
6843*4882a593Smuzhiyun
6844*4882a593Smuzhiyun /* Display WA #1141: SKL:all KBL:all CFL */
6845*4882a593Smuzhiyun if (IS_KABYLAKE(dev_priv) ||
6846*4882a593Smuzhiyun IS_COFFEELAKE(dev_priv) ||
6847*4882a593Smuzhiyun IS_COMETLAKE(dev_priv))
6848*4882a593Smuzhiyun return dev_priv->dram_info.symmetric_memory;
6849*4882a593Smuzhiyun
6850*4882a593Smuzhiyun return true;
6851*4882a593Smuzhiyun }
6852*4882a593Smuzhiyun
intel_init_ipc(struct drm_i915_private * dev_priv)6853*4882a593Smuzhiyun void intel_init_ipc(struct drm_i915_private *dev_priv)
6854*4882a593Smuzhiyun {
6855*4882a593Smuzhiyun if (!HAS_IPC(dev_priv))
6856*4882a593Smuzhiyun return;
6857*4882a593Smuzhiyun
6858*4882a593Smuzhiyun dev_priv->ipc_enabled = intel_can_enable_ipc(dev_priv);
6859*4882a593Smuzhiyun
6860*4882a593Smuzhiyun intel_enable_ipc(dev_priv);
6861*4882a593Smuzhiyun }
6862*4882a593Smuzhiyun
ibx_init_clock_gating(struct drm_i915_private * dev_priv)6863*4882a593Smuzhiyun static void ibx_init_clock_gating(struct drm_i915_private *dev_priv)
6864*4882a593Smuzhiyun {
6865*4882a593Smuzhiyun /*
6866*4882a593Smuzhiyun * On Ibex Peak and Cougar Point, we need to disable clock
6867*4882a593Smuzhiyun * gating for the panel power sequencer or it will fail to
6868*4882a593Smuzhiyun * start up when no ports are active.
6869*4882a593Smuzhiyun */
6870*4882a593Smuzhiyun I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE);
6871*4882a593Smuzhiyun }
6872*4882a593Smuzhiyun
g4x_disable_trickle_feed(struct drm_i915_private * dev_priv)6873*4882a593Smuzhiyun static void g4x_disable_trickle_feed(struct drm_i915_private *dev_priv)
6874*4882a593Smuzhiyun {
6875*4882a593Smuzhiyun enum pipe pipe;
6876*4882a593Smuzhiyun
6877*4882a593Smuzhiyun for_each_pipe(dev_priv, pipe) {
6878*4882a593Smuzhiyun I915_WRITE(DSPCNTR(pipe),
6879*4882a593Smuzhiyun I915_READ(DSPCNTR(pipe)) |
6880*4882a593Smuzhiyun DISPPLANE_TRICKLE_FEED_DISABLE);
6881*4882a593Smuzhiyun
6882*4882a593Smuzhiyun I915_WRITE(DSPSURF(pipe), I915_READ(DSPSURF(pipe)));
6883*4882a593Smuzhiyun POSTING_READ(DSPSURF(pipe));
6884*4882a593Smuzhiyun }
6885*4882a593Smuzhiyun }
6886*4882a593Smuzhiyun
ilk_init_clock_gating(struct drm_i915_private * dev_priv)6887*4882a593Smuzhiyun static void ilk_init_clock_gating(struct drm_i915_private *dev_priv)
6888*4882a593Smuzhiyun {
6889*4882a593Smuzhiyun u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
6890*4882a593Smuzhiyun
6891*4882a593Smuzhiyun /*
6892*4882a593Smuzhiyun * Required for FBC
6893*4882a593Smuzhiyun * WaFbcDisableDpfcClockGating:ilk
6894*4882a593Smuzhiyun */
6895*4882a593Smuzhiyun dspclk_gate |= ILK_DPFCRUNIT_CLOCK_GATE_DISABLE |
6896*4882a593Smuzhiyun ILK_DPFCUNIT_CLOCK_GATE_DISABLE |
6897*4882a593Smuzhiyun ILK_DPFDUNIT_CLOCK_GATE_ENABLE;
6898*4882a593Smuzhiyun
6899*4882a593Smuzhiyun I915_WRITE(PCH_3DCGDIS0,
6900*4882a593Smuzhiyun MARIUNIT_CLOCK_GATE_DISABLE |
6901*4882a593Smuzhiyun SVSMUNIT_CLOCK_GATE_DISABLE);
6902*4882a593Smuzhiyun I915_WRITE(PCH_3DCGDIS1,
6903*4882a593Smuzhiyun VFMUNIT_CLOCK_GATE_DISABLE);
6904*4882a593Smuzhiyun
6905*4882a593Smuzhiyun /*
6906*4882a593Smuzhiyun * According to the spec the following bits should be set in
6907*4882a593Smuzhiyun * order to enable memory self-refresh
6908*4882a593Smuzhiyun * The bit 22/21 of 0x42004
6909*4882a593Smuzhiyun * The bit 5 of 0x42020
6910*4882a593Smuzhiyun * The bit 15 of 0x45000
6911*4882a593Smuzhiyun */
6912*4882a593Smuzhiyun I915_WRITE(ILK_DISPLAY_CHICKEN2,
6913*4882a593Smuzhiyun (I915_READ(ILK_DISPLAY_CHICKEN2) |
6914*4882a593Smuzhiyun ILK_DPARB_GATE | ILK_VSDPFD_FULL));
6915*4882a593Smuzhiyun dspclk_gate |= ILK_DPARBUNIT_CLOCK_GATE_ENABLE;
6916*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL,
6917*4882a593Smuzhiyun (I915_READ(DISP_ARB_CTL) |
6918*4882a593Smuzhiyun DISP_FBC_WM_DIS));
6919*4882a593Smuzhiyun
6920*4882a593Smuzhiyun /*
6921*4882a593Smuzhiyun * Based on the document from hardware guys the following bits
6922*4882a593Smuzhiyun * should be set unconditionally in order to enable FBC.
6923*4882a593Smuzhiyun * The bit 22 of 0x42000
6924*4882a593Smuzhiyun * The bit 22 of 0x42004
6925*4882a593Smuzhiyun * The bit 7,8,9 of 0x42020.
6926*4882a593Smuzhiyun */
6927*4882a593Smuzhiyun if (IS_IRONLAKE_M(dev_priv)) {
6928*4882a593Smuzhiyun /* WaFbcAsynchFlipDisableFbcQueue:ilk */
6929*4882a593Smuzhiyun I915_WRITE(ILK_DISPLAY_CHICKEN1,
6930*4882a593Smuzhiyun I915_READ(ILK_DISPLAY_CHICKEN1) |
6931*4882a593Smuzhiyun ILK_FBCQ_DIS);
6932*4882a593Smuzhiyun I915_WRITE(ILK_DISPLAY_CHICKEN2,
6933*4882a593Smuzhiyun I915_READ(ILK_DISPLAY_CHICKEN2) |
6934*4882a593Smuzhiyun ILK_DPARB_GATE);
6935*4882a593Smuzhiyun }
6936*4882a593Smuzhiyun
6937*4882a593Smuzhiyun I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate);
6938*4882a593Smuzhiyun
6939*4882a593Smuzhiyun I915_WRITE(ILK_DISPLAY_CHICKEN2,
6940*4882a593Smuzhiyun I915_READ(ILK_DISPLAY_CHICKEN2) |
6941*4882a593Smuzhiyun ILK_ELPIN_409_SELECT);
6942*4882a593Smuzhiyun
6943*4882a593Smuzhiyun g4x_disable_trickle_feed(dev_priv);
6944*4882a593Smuzhiyun
6945*4882a593Smuzhiyun ibx_init_clock_gating(dev_priv);
6946*4882a593Smuzhiyun }
6947*4882a593Smuzhiyun
cpt_init_clock_gating(struct drm_i915_private * dev_priv)6948*4882a593Smuzhiyun static void cpt_init_clock_gating(struct drm_i915_private *dev_priv)
6949*4882a593Smuzhiyun {
6950*4882a593Smuzhiyun enum pipe pipe;
6951*4882a593Smuzhiyun u32 val;
6952*4882a593Smuzhiyun
6953*4882a593Smuzhiyun /*
6954*4882a593Smuzhiyun * On Ibex Peak and Cougar Point, we need to disable clock
6955*4882a593Smuzhiyun * gating for the panel power sequencer or it will fail to
6956*4882a593Smuzhiyun * start up when no ports are active.
6957*4882a593Smuzhiyun */
6958*4882a593Smuzhiyun I915_WRITE(SOUTH_DSPCLK_GATE_D, PCH_DPLSUNIT_CLOCK_GATE_DISABLE |
6959*4882a593Smuzhiyun PCH_DPLUNIT_CLOCK_GATE_DISABLE |
6960*4882a593Smuzhiyun PCH_CPUNIT_CLOCK_GATE_DISABLE);
6961*4882a593Smuzhiyun I915_WRITE(SOUTH_CHICKEN2, I915_READ(SOUTH_CHICKEN2) |
6962*4882a593Smuzhiyun DPLS_EDP_PPS_FIX_DIS);
6963*4882a593Smuzhiyun /* The below fixes the weird display corruption, a few pixels shifted
6964*4882a593Smuzhiyun * downward, on (only) LVDS of some HP laptops with IVY.
6965*4882a593Smuzhiyun */
6966*4882a593Smuzhiyun for_each_pipe(dev_priv, pipe) {
6967*4882a593Smuzhiyun val = I915_READ(TRANS_CHICKEN2(pipe));
6968*4882a593Smuzhiyun val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
6969*4882a593Smuzhiyun val &= ~TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
6970*4882a593Smuzhiyun if (dev_priv->vbt.fdi_rx_polarity_inverted)
6971*4882a593Smuzhiyun val |= TRANS_CHICKEN2_FDI_POLARITY_REVERSED;
6972*4882a593Smuzhiyun val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_COUNTER;
6973*4882a593Smuzhiyun val &= ~TRANS_CHICKEN2_DISABLE_DEEP_COLOR_MODESWITCH;
6974*4882a593Smuzhiyun I915_WRITE(TRANS_CHICKEN2(pipe), val);
6975*4882a593Smuzhiyun }
6976*4882a593Smuzhiyun /* WADP0ClockGatingDisable */
6977*4882a593Smuzhiyun for_each_pipe(dev_priv, pipe) {
6978*4882a593Smuzhiyun I915_WRITE(TRANS_CHICKEN1(pipe),
6979*4882a593Smuzhiyun TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
6980*4882a593Smuzhiyun }
6981*4882a593Smuzhiyun }
6982*4882a593Smuzhiyun
gen6_check_mch_setup(struct drm_i915_private * dev_priv)6983*4882a593Smuzhiyun static void gen6_check_mch_setup(struct drm_i915_private *dev_priv)
6984*4882a593Smuzhiyun {
6985*4882a593Smuzhiyun u32 tmp;
6986*4882a593Smuzhiyun
6987*4882a593Smuzhiyun tmp = I915_READ(MCH_SSKPD);
6988*4882a593Smuzhiyun if ((tmp & MCH_SSKPD_WM0_MASK) != MCH_SSKPD_WM0_VAL)
6989*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
6990*4882a593Smuzhiyun "Wrong MCH_SSKPD value: 0x%08x This can cause underruns.\n",
6991*4882a593Smuzhiyun tmp);
6992*4882a593Smuzhiyun }
6993*4882a593Smuzhiyun
gen6_init_clock_gating(struct drm_i915_private * dev_priv)6994*4882a593Smuzhiyun static void gen6_init_clock_gating(struct drm_i915_private *dev_priv)
6995*4882a593Smuzhiyun {
6996*4882a593Smuzhiyun u32 dspclk_gate = ILK_VRHUNIT_CLOCK_GATE_DISABLE;
6997*4882a593Smuzhiyun
6998*4882a593Smuzhiyun I915_WRITE(ILK_DSPCLK_GATE_D, dspclk_gate);
6999*4882a593Smuzhiyun
7000*4882a593Smuzhiyun I915_WRITE(ILK_DISPLAY_CHICKEN2,
7001*4882a593Smuzhiyun I915_READ(ILK_DISPLAY_CHICKEN2) |
7002*4882a593Smuzhiyun ILK_ELPIN_409_SELECT);
7003*4882a593Smuzhiyun
7004*4882a593Smuzhiyun I915_WRITE(GEN6_UCGCTL1,
7005*4882a593Smuzhiyun I915_READ(GEN6_UCGCTL1) |
7006*4882a593Smuzhiyun GEN6_BLBUNIT_CLOCK_GATE_DISABLE |
7007*4882a593Smuzhiyun GEN6_CSUNIT_CLOCK_GATE_DISABLE);
7008*4882a593Smuzhiyun
7009*4882a593Smuzhiyun /* According to the BSpec vol1g, bit 12 (RCPBUNIT) clock
7010*4882a593Smuzhiyun * gating disable must be set. Failure to set it results in
7011*4882a593Smuzhiyun * flickering pixels due to Z write ordering failures after
7012*4882a593Smuzhiyun * some amount of runtime in the Mesa "fire" demo, and Unigine
7013*4882a593Smuzhiyun * Sanctuary and Tropics, and apparently anything else with
7014*4882a593Smuzhiyun * alpha test or pixel discard.
7015*4882a593Smuzhiyun *
7016*4882a593Smuzhiyun * According to the spec, bit 11 (RCCUNIT) must also be set,
7017*4882a593Smuzhiyun * but we didn't debug actual testcases to find it out.
7018*4882a593Smuzhiyun *
7019*4882a593Smuzhiyun * WaDisableRCCUnitClockGating:snb
7020*4882a593Smuzhiyun * WaDisableRCPBUnitClockGating:snb
7021*4882a593Smuzhiyun */
7022*4882a593Smuzhiyun I915_WRITE(GEN6_UCGCTL2,
7023*4882a593Smuzhiyun GEN6_RCPBUNIT_CLOCK_GATE_DISABLE |
7024*4882a593Smuzhiyun GEN6_RCCUNIT_CLOCK_GATE_DISABLE);
7025*4882a593Smuzhiyun
7026*4882a593Smuzhiyun /*
7027*4882a593Smuzhiyun * According to the spec the following bits should be
7028*4882a593Smuzhiyun * set in order to enable memory self-refresh and fbc:
7029*4882a593Smuzhiyun * The bit21 and bit22 of 0x42000
7030*4882a593Smuzhiyun * The bit21 and bit22 of 0x42004
7031*4882a593Smuzhiyun * The bit5 and bit7 of 0x42020
7032*4882a593Smuzhiyun * The bit14 of 0x70180
7033*4882a593Smuzhiyun * The bit14 of 0x71180
7034*4882a593Smuzhiyun *
7035*4882a593Smuzhiyun * WaFbcAsynchFlipDisableFbcQueue:snb
7036*4882a593Smuzhiyun */
7037*4882a593Smuzhiyun I915_WRITE(ILK_DISPLAY_CHICKEN1,
7038*4882a593Smuzhiyun I915_READ(ILK_DISPLAY_CHICKEN1) |
7039*4882a593Smuzhiyun ILK_FBCQ_DIS | ILK_PABSTRETCH_DIS);
7040*4882a593Smuzhiyun I915_WRITE(ILK_DISPLAY_CHICKEN2,
7041*4882a593Smuzhiyun I915_READ(ILK_DISPLAY_CHICKEN2) |
7042*4882a593Smuzhiyun ILK_DPARB_GATE | ILK_VSDPFD_FULL);
7043*4882a593Smuzhiyun I915_WRITE(ILK_DSPCLK_GATE_D,
7044*4882a593Smuzhiyun I915_READ(ILK_DSPCLK_GATE_D) |
7045*4882a593Smuzhiyun ILK_DPARBUNIT_CLOCK_GATE_ENABLE |
7046*4882a593Smuzhiyun ILK_DPFDUNIT_CLOCK_GATE_ENABLE);
7047*4882a593Smuzhiyun
7048*4882a593Smuzhiyun g4x_disable_trickle_feed(dev_priv);
7049*4882a593Smuzhiyun
7050*4882a593Smuzhiyun cpt_init_clock_gating(dev_priv);
7051*4882a593Smuzhiyun
7052*4882a593Smuzhiyun gen6_check_mch_setup(dev_priv);
7053*4882a593Smuzhiyun }
7054*4882a593Smuzhiyun
lpt_init_clock_gating(struct drm_i915_private * dev_priv)7055*4882a593Smuzhiyun static void lpt_init_clock_gating(struct drm_i915_private *dev_priv)
7056*4882a593Smuzhiyun {
7057*4882a593Smuzhiyun /*
7058*4882a593Smuzhiyun * TODO: this bit should only be enabled when really needed, then
7059*4882a593Smuzhiyun * disabled when not needed anymore in order to save power.
7060*4882a593Smuzhiyun */
7061*4882a593Smuzhiyun if (HAS_PCH_LPT_LP(dev_priv))
7062*4882a593Smuzhiyun I915_WRITE(SOUTH_DSPCLK_GATE_D,
7063*4882a593Smuzhiyun I915_READ(SOUTH_DSPCLK_GATE_D) |
7064*4882a593Smuzhiyun PCH_LP_PARTITION_LEVEL_DISABLE);
7065*4882a593Smuzhiyun
7066*4882a593Smuzhiyun /* WADPOClockGatingDisable:hsw */
7067*4882a593Smuzhiyun I915_WRITE(TRANS_CHICKEN1(PIPE_A),
7068*4882a593Smuzhiyun I915_READ(TRANS_CHICKEN1(PIPE_A)) |
7069*4882a593Smuzhiyun TRANS_CHICKEN1_DP0UNIT_GC_DISABLE);
7070*4882a593Smuzhiyun }
7071*4882a593Smuzhiyun
lpt_suspend_hw(struct drm_i915_private * dev_priv)7072*4882a593Smuzhiyun static void lpt_suspend_hw(struct drm_i915_private *dev_priv)
7073*4882a593Smuzhiyun {
7074*4882a593Smuzhiyun if (HAS_PCH_LPT_LP(dev_priv)) {
7075*4882a593Smuzhiyun u32 val = I915_READ(SOUTH_DSPCLK_GATE_D);
7076*4882a593Smuzhiyun
7077*4882a593Smuzhiyun val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
7078*4882a593Smuzhiyun I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
7079*4882a593Smuzhiyun }
7080*4882a593Smuzhiyun }
7081*4882a593Smuzhiyun
gen8_set_l3sqc_credits(struct drm_i915_private * dev_priv,int general_prio_credits,int high_prio_credits)7082*4882a593Smuzhiyun static void gen8_set_l3sqc_credits(struct drm_i915_private *dev_priv,
7083*4882a593Smuzhiyun int general_prio_credits,
7084*4882a593Smuzhiyun int high_prio_credits)
7085*4882a593Smuzhiyun {
7086*4882a593Smuzhiyun u32 misccpctl;
7087*4882a593Smuzhiyun u32 val;
7088*4882a593Smuzhiyun
7089*4882a593Smuzhiyun /* WaTempDisableDOPClkGating:bdw */
7090*4882a593Smuzhiyun misccpctl = I915_READ(GEN7_MISCCPCTL);
7091*4882a593Smuzhiyun I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
7092*4882a593Smuzhiyun
7093*4882a593Smuzhiyun val = I915_READ(GEN8_L3SQCREG1);
7094*4882a593Smuzhiyun val &= ~L3_PRIO_CREDITS_MASK;
7095*4882a593Smuzhiyun val |= L3_GENERAL_PRIO_CREDITS(general_prio_credits);
7096*4882a593Smuzhiyun val |= L3_HIGH_PRIO_CREDITS(high_prio_credits);
7097*4882a593Smuzhiyun I915_WRITE(GEN8_L3SQCREG1, val);
7098*4882a593Smuzhiyun
7099*4882a593Smuzhiyun /*
7100*4882a593Smuzhiyun * Wait at least 100 clocks before re-enabling clock gating.
7101*4882a593Smuzhiyun * See the definition of L3SQCREG1 in BSpec.
7102*4882a593Smuzhiyun */
7103*4882a593Smuzhiyun POSTING_READ(GEN8_L3SQCREG1);
7104*4882a593Smuzhiyun udelay(1);
7105*4882a593Smuzhiyun I915_WRITE(GEN7_MISCCPCTL, misccpctl);
7106*4882a593Smuzhiyun }
7107*4882a593Smuzhiyun
icl_init_clock_gating(struct drm_i915_private * dev_priv)7108*4882a593Smuzhiyun static void icl_init_clock_gating(struct drm_i915_private *dev_priv)
7109*4882a593Smuzhiyun {
7110*4882a593Smuzhiyun /* Wa_1409120013:icl,ehl */
7111*4882a593Smuzhiyun I915_WRITE(ILK_DPFC_CHICKEN,
7112*4882a593Smuzhiyun ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL);
7113*4882a593Smuzhiyun
7114*4882a593Smuzhiyun /* This is not an Wa. Enable to reduce Sampler power */
7115*4882a593Smuzhiyun I915_WRITE(GEN10_DFR_RATIO_EN_AND_CHICKEN,
7116*4882a593Smuzhiyun I915_READ(GEN10_DFR_RATIO_EN_AND_CHICKEN) & ~DFR_DISABLE);
7117*4882a593Smuzhiyun
7118*4882a593Smuzhiyun /*Wa_14010594013:icl, ehl */
7119*4882a593Smuzhiyun intel_uncore_rmw(&dev_priv->uncore, GEN8_CHICKEN_DCPR_1,
7120*4882a593Smuzhiyun 0, CNL_DELAY_PMRSP);
7121*4882a593Smuzhiyun }
7122*4882a593Smuzhiyun
tgl_init_clock_gating(struct drm_i915_private * dev_priv)7123*4882a593Smuzhiyun static void tgl_init_clock_gating(struct drm_i915_private *dev_priv)
7124*4882a593Smuzhiyun {
7125*4882a593Smuzhiyun /* Wa_1409120013:tgl */
7126*4882a593Smuzhiyun I915_WRITE(ILK_DPFC_CHICKEN,
7127*4882a593Smuzhiyun ILK_DPFC_CHICKEN_COMP_DUMMY_PIXEL);
7128*4882a593Smuzhiyun
7129*4882a593Smuzhiyun /* Wa_1409825376:tgl (pre-prod)*/
7130*4882a593Smuzhiyun if (IS_TGL_DISP_REVID(dev_priv, TGL_REVID_A0, TGL_REVID_B1))
7131*4882a593Smuzhiyun I915_WRITE(GEN9_CLKGATE_DIS_3, I915_READ(GEN9_CLKGATE_DIS_3) |
7132*4882a593Smuzhiyun TGL_VRH_GATING_DIS);
7133*4882a593Smuzhiyun
7134*4882a593Smuzhiyun /* Wa_14011059788:tgl */
7135*4882a593Smuzhiyun intel_uncore_rmw(&dev_priv->uncore, GEN10_DFR_RATIO_EN_AND_CHICKEN,
7136*4882a593Smuzhiyun 0, DFR_DISABLE);
7137*4882a593Smuzhiyun }
7138*4882a593Smuzhiyun
cnp_init_clock_gating(struct drm_i915_private * dev_priv)7139*4882a593Smuzhiyun static void cnp_init_clock_gating(struct drm_i915_private *dev_priv)
7140*4882a593Smuzhiyun {
7141*4882a593Smuzhiyun if (!HAS_PCH_CNP(dev_priv))
7142*4882a593Smuzhiyun return;
7143*4882a593Smuzhiyun
7144*4882a593Smuzhiyun /* Display WA #1181 WaSouthDisplayDisablePWMCGEGating: cnp */
7145*4882a593Smuzhiyun I915_WRITE(SOUTH_DSPCLK_GATE_D, I915_READ(SOUTH_DSPCLK_GATE_D) |
7146*4882a593Smuzhiyun CNP_PWM_CGE_GATING_DISABLE);
7147*4882a593Smuzhiyun }
7148*4882a593Smuzhiyun
cnl_init_clock_gating(struct drm_i915_private * dev_priv)7149*4882a593Smuzhiyun static void cnl_init_clock_gating(struct drm_i915_private *dev_priv)
7150*4882a593Smuzhiyun {
7151*4882a593Smuzhiyun u32 val;
7152*4882a593Smuzhiyun cnp_init_clock_gating(dev_priv);
7153*4882a593Smuzhiyun
7154*4882a593Smuzhiyun /* This is not an Wa. Enable for better image quality */
7155*4882a593Smuzhiyun I915_WRITE(_3D_CHICKEN3,
7156*4882a593Smuzhiyun _MASKED_BIT_ENABLE(_3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE));
7157*4882a593Smuzhiyun
7158*4882a593Smuzhiyun /* WaEnableChickenDCPR:cnl */
7159*4882a593Smuzhiyun I915_WRITE(GEN8_CHICKEN_DCPR_1,
7160*4882a593Smuzhiyun I915_READ(GEN8_CHICKEN_DCPR_1) | MASK_WAKEMEM);
7161*4882a593Smuzhiyun
7162*4882a593Smuzhiyun /*
7163*4882a593Smuzhiyun * WaFbcWakeMemOn:cnl
7164*4882a593Smuzhiyun * Display WA #0859: cnl
7165*4882a593Smuzhiyun */
7166*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
7167*4882a593Smuzhiyun DISP_FBC_MEMORY_WAKE);
7168*4882a593Smuzhiyun
7169*4882a593Smuzhiyun val = I915_READ(SLICE_UNIT_LEVEL_CLKGATE);
7170*4882a593Smuzhiyun /* ReadHitWriteOnlyDisable:cnl */
7171*4882a593Smuzhiyun val |= RCCUNIT_CLKGATE_DIS;
7172*4882a593Smuzhiyun I915_WRITE(SLICE_UNIT_LEVEL_CLKGATE, val);
7173*4882a593Smuzhiyun
7174*4882a593Smuzhiyun /* Wa_2201832410:cnl */
7175*4882a593Smuzhiyun val = I915_READ(SUBSLICE_UNIT_LEVEL_CLKGATE);
7176*4882a593Smuzhiyun val |= GWUNIT_CLKGATE_DIS;
7177*4882a593Smuzhiyun I915_WRITE(SUBSLICE_UNIT_LEVEL_CLKGATE, val);
7178*4882a593Smuzhiyun
7179*4882a593Smuzhiyun /* WaDisableVFclkgate:cnl */
7180*4882a593Smuzhiyun /* WaVFUnitClockGatingDisable:cnl */
7181*4882a593Smuzhiyun val = I915_READ(UNSLICE_UNIT_LEVEL_CLKGATE);
7182*4882a593Smuzhiyun val |= VFUNIT_CLKGATE_DIS;
7183*4882a593Smuzhiyun I915_WRITE(UNSLICE_UNIT_LEVEL_CLKGATE, val);
7184*4882a593Smuzhiyun }
7185*4882a593Smuzhiyun
cfl_init_clock_gating(struct drm_i915_private * dev_priv)7186*4882a593Smuzhiyun static void cfl_init_clock_gating(struct drm_i915_private *dev_priv)
7187*4882a593Smuzhiyun {
7188*4882a593Smuzhiyun cnp_init_clock_gating(dev_priv);
7189*4882a593Smuzhiyun gen9_init_clock_gating(dev_priv);
7190*4882a593Smuzhiyun
7191*4882a593Smuzhiyun /*
7192*4882a593Smuzhiyun * WaFbcTurnOffFbcWatermark:cfl
7193*4882a593Smuzhiyun * Display WA #0562: cfl
7194*4882a593Smuzhiyun */
7195*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
7196*4882a593Smuzhiyun DISP_FBC_WM_DIS);
7197*4882a593Smuzhiyun
7198*4882a593Smuzhiyun /*
7199*4882a593Smuzhiyun * WaFbcNukeOnHostModify:cfl
7200*4882a593Smuzhiyun * Display WA #0873: cfl
7201*4882a593Smuzhiyun */
7202*4882a593Smuzhiyun I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
7203*4882a593Smuzhiyun ILK_DPFC_NUKE_ON_ANY_MODIFICATION);
7204*4882a593Smuzhiyun }
7205*4882a593Smuzhiyun
kbl_init_clock_gating(struct drm_i915_private * dev_priv)7206*4882a593Smuzhiyun static void kbl_init_clock_gating(struct drm_i915_private *dev_priv)
7207*4882a593Smuzhiyun {
7208*4882a593Smuzhiyun gen9_init_clock_gating(dev_priv);
7209*4882a593Smuzhiyun
7210*4882a593Smuzhiyun /* WaDisableSDEUnitClockGating:kbl */
7211*4882a593Smuzhiyun if (IS_KBL_GT_REVID(dev_priv, 0, KBL_REVID_B0))
7212*4882a593Smuzhiyun I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
7213*4882a593Smuzhiyun GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
7214*4882a593Smuzhiyun
7215*4882a593Smuzhiyun /* WaDisableGamClockGating:kbl */
7216*4882a593Smuzhiyun if (IS_KBL_GT_REVID(dev_priv, 0, KBL_REVID_B0))
7217*4882a593Smuzhiyun I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) |
7218*4882a593Smuzhiyun GEN6_GAMUNIT_CLOCK_GATE_DISABLE);
7219*4882a593Smuzhiyun
7220*4882a593Smuzhiyun /*
7221*4882a593Smuzhiyun * WaFbcTurnOffFbcWatermark:kbl
7222*4882a593Smuzhiyun * Display WA #0562: kbl
7223*4882a593Smuzhiyun */
7224*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
7225*4882a593Smuzhiyun DISP_FBC_WM_DIS);
7226*4882a593Smuzhiyun
7227*4882a593Smuzhiyun /*
7228*4882a593Smuzhiyun * WaFbcNukeOnHostModify:kbl
7229*4882a593Smuzhiyun * Display WA #0873: kbl
7230*4882a593Smuzhiyun */
7231*4882a593Smuzhiyun I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
7232*4882a593Smuzhiyun ILK_DPFC_NUKE_ON_ANY_MODIFICATION);
7233*4882a593Smuzhiyun }
7234*4882a593Smuzhiyun
skl_init_clock_gating(struct drm_i915_private * dev_priv)7235*4882a593Smuzhiyun static void skl_init_clock_gating(struct drm_i915_private *dev_priv)
7236*4882a593Smuzhiyun {
7237*4882a593Smuzhiyun gen9_init_clock_gating(dev_priv);
7238*4882a593Smuzhiyun
7239*4882a593Smuzhiyun /* WaDisableDopClockGating:skl */
7240*4882a593Smuzhiyun I915_WRITE(GEN7_MISCCPCTL, I915_READ(GEN7_MISCCPCTL) &
7241*4882a593Smuzhiyun ~GEN7_DOP_CLOCK_GATE_ENABLE);
7242*4882a593Smuzhiyun
7243*4882a593Smuzhiyun /* WAC6entrylatency:skl */
7244*4882a593Smuzhiyun I915_WRITE(FBC_LLC_READ_CTRL, I915_READ(FBC_LLC_READ_CTRL) |
7245*4882a593Smuzhiyun FBC_LLC_FULLY_OPEN);
7246*4882a593Smuzhiyun
7247*4882a593Smuzhiyun /*
7248*4882a593Smuzhiyun * WaFbcTurnOffFbcWatermark:skl
7249*4882a593Smuzhiyun * Display WA #0562: skl
7250*4882a593Smuzhiyun */
7251*4882a593Smuzhiyun I915_WRITE(DISP_ARB_CTL, I915_READ(DISP_ARB_CTL) |
7252*4882a593Smuzhiyun DISP_FBC_WM_DIS);
7253*4882a593Smuzhiyun
7254*4882a593Smuzhiyun /*
7255*4882a593Smuzhiyun * WaFbcNukeOnHostModify:skl
7256*4882a593Smuzhiyun * Display WA #0873: skl
7257*4882a593Smuzhiyun */
7258*4882a593Smuzhiyun I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
7259*4882a593Smuzhiyun ILK_DPFC_NUKE_ON_ANY_MODIFICATION);
7260*4882a593Smuzhiyun
7261*4882a593Smuzhiyun /*
7262*4882a593Smuzhiyun * WaFbcHighMemBwCorruptionAvoidance:skl
7263*4882a593Smuzhiyun * Display WA #0883: skl
7264*4882a593Smuzhiyun */
7265*4882a593Smuzhiyun I915_WRITE(ILK_DPFC_CHICKEN, I915_READ(ILK_DPFC_CHICKEN) |
7266*4882a593Smuzhiyun ILK_DPFC_DISABLE_DUMMY0);
7267*4882a593Smuzhiyun }
7268*4882a593Smuzhiyun
bdw_init_clock_gating(struct drm_i915_private * dev_priv)7269*4882a593Smuzhiyun static void bdw_init_clock_gating(struct drm_i915_private *dev_priv)
7270*4882a593Smuzhiyun {
7271*4882a593Smuzhiyun enum pipe pipe;
7272*4882a593Smuzhiyun
7273*4882a593Smuzhiyun /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */
7274*4882a593Smuzhiyun I915_WRITE(CHICKEN_PIPESL_1(PIPE_A),
7275*4882a593Smuzhiyun I915_READ(CHICKEN_PIPESL_1(PIPE_A)) |
7276*4882a593Smuzhiyun HSW_FBCQ_DIS);
7277*4882a593Smuzhiyun
7278*4882a593Smuzhiyun /* WaSwitchSolVfFArbitrationPriority:bdw */
7279*4882a593Smuzhiyun I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
7280*4882a593Smuzhiyun
7281*4882a593Smuzhiyun /* WaPsrDPAMaskVBlankInSRD:bdw */
7282*4882a593Smuzhiyun I915_WRITE(CHICKEN_PAR1_1,
7283*4882a593Smuzhiyun I915_READ(CHICKEN_PAR1_1) | DPA_MASK_VBLANK_SRD);
7284*4882a593Smuzhiyun
7285*4882a593Smuzhiyun /* WaPsrDPRSUnmaskVBlankInSRD:bdw */
7286*4882a593Smuzhiyun for_each_pipe(dev_priv, pipe) {
7287*4882a593Smuzhiyun I915_WRITE(CHICKEN_PIPESL_1(pipe),
7288*4882a593Smuzhiyun I915_READ(CHICKEN_PIPESL_1(pipe)) |
7289*4882a593Smuzhiyun BDW_DPRS_MASK_VBLANK_SRD);
7290*4882a593Smuzhiyun }
7291*4882a593Smuzhiyun
7292*4882a593Smuzhiyun /* WaVSRefCountFullforceMissDisable:bdw */
7293*4882a593Smuzhiyun /* WaDSRefCountFullforceMissDisable:bdw */
7294*4882a593Smuzhiyun I915_WRITE(GEN7_FF_THREAD_MODE,
7295*4882a593Smuzhiyun I915_READ(GEN7_FF_THREAD_MODE) &
7296*4882a593Smuzhiyun ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
7297*4882a593Smuzhiyun
7298*4882a593Smuzhiyun I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL,
7299*4882a593Smuzhiyun _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
7300*4882a593Smuzhiyun
7301*4882a593Smuzhiyun /* WaDisableSDEUnitClockGating:bdw */
7302*4882a593Smuzhiyun I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
7303*4882a593Smuzhiyun GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
7304*4882a593Smuzhiyun
7305*4882a593Smuzhiyun /* WaProgramL3SqcReg1Default:bdw */
7306*4882a593Smuzhiyun gen8_set_l3sqc_credits(dev_priv, 30, 2);
7307*4882a593Smuzhiyun
7308*4882a593Smuzhiyun /* WaKVMNotificationOnConfigChange:bdw */
7309*4882a593Smuzhiyun I915_WRITE(CHICKEN_PAR2_1, I915_READ(CHICKEN_PAR2_1)
7310*4882a593Smuzhiyun | KVM_CONFIG_CHANGE_NOTIFICATION_SELECT);
7311*4882a593Smuzhiyun
7312*4882a593Smuzhiyun lpt_init_clock_gating(dev_priv);
7313*4882a593Smuzhiyun
7314*4882a593Smuzhiyun /* WaDisableDopClockGating:bdw
7315*4882a593Smuzhiyun *
7316*4882a593Smuzhiyun * Also see the CHICKEN2 write in bdw_init_workarounds() to disable DOP
7317*4882a593Smuzhiyun * clock gating.
7318*4882a593Smuzhiyun */
7319*4882a593Smuzhiyun I915_WRITE(GEN6_UCGCTL1,
7320*4882a593Smuzhiyun I915_READ(GEN6_UCGCTL1) | GEN6_EU_TCUNIT_CLOCK_GATE_DISABLE);
7321*4882a593Smuzhiyun }
7322*4882a593Smuzhiyun
hsw_init_clock_gating(struct drm_i915_private * dev_priv)7323*4882a593Smuzhiyun static void hsw_init_clock_gating(struct drm_i915_private *dev_priv)
7324*4882a593Smuzhiyun {
7325*4882a593Smuzhiyun /* WaFbcAsynchFlipDisableFbcQueue:hsw,bdw */
7326*4882a593Smuzhiyun I915_WRITE(CHICKEN_PIPESL_1(PIPE_A),
7327*4882a593Smuzhiyun I915_READ(CHICKEN_PIPESL_1(PIPE_A)) |
7328*4882a593Smuzhiyun HSW_FBCQ_DIS);
7329*4882a593Smuzhiyun
7330*4882a593Smuzhiyun /* This is required by WaCatErrorRejectionIssue:hsw */
7331*4882a593Smuzhiyun I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
7332*4882a593Smuzhiyun I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
7333*4882a593Smuzhiyun GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
7334*4882a593Smuzhiyun
7335*4882a593Smuzhiyun /* WaSwitchSolVfFArbitrationPriority:hsw */
7336*4882a593Smuzhiyun I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | HSW_ECOCHK_ARB_PRIO_SOL);
7337*4882a593Smuzhiyun
7338*4882a593Smuzhiyun lpt_init_clock_gating(dev_priv);
7339*4882a593Smuzhiyun }
7340*4882a593Smuzhiyun
ivb_init_clock_gating(struct drm_i915_private * dev_priv)7341*4882a593Smuzhiyun static void ivb_init_clock_gating(struct drm_i915_private *dev_priv)
7342*4882a593Smuzhiyun {
7343*4882a593Smuzhiyun u32 snpcr;
7344*4882a593Smuzhiyun
7345*4882a593Smuzhiyun I915_WRITE(ILK_DSPCLK_GATE_D, ILK_VRHUNIT_CLOCK_GATE_DISABLE);
7346*4882a593Smuzhiyun
7347*4882a593Smuzhiyun /* WaFbcAsynchFlipDisableFbcQueue:ivb */
7348*4882a593Smuzhiyun I915_WRITE(ILK_DISPLAY_CHICKEN1,
7349*4882a593Smuzhiyun I915_READ(ILK_DISPLAY_CHICKEN1) |
7350*4882a593Smuzhiyun ILK_FBCQ_DIS);
7351*4882a593Smuzhiyun
7352*4882a593Smuzhiyun /* WaDisableBackToBackFlipFix:ivb */
7353*4882a593Smuzhiyun I915_WRITE(IVB_CHICKEN3,
7354*4882a593Smuzhiyun CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
7355*4882a593Smuzhiyun CHICKEN3_DGMG_DONE_FIX_DISABLE);
7356*4882a593Smuzhiyun
7357*4882a593Smuzhiyun if (IS_IVB_GT1(dev_priv))
7358*4882a593Smuzhiyun I915_WRITE(GEN7_ROW_CHICKEN2,
7359*4882a593Smuzhiyun _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
7360*4882a593Smuzhiyun else {
7361*4882a593Smuzhiyun /* must write both registers */
7362*4882a593Smuzhiyun I915_WRITE(GEN7_ROW_CHICKEN2,
7363*4882a593Smuzhiyun _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
7364*4882a593Smuzhiyun I915_WRITE(GEN7_ROW_CHICKEN2_GT2,
7365*4882a593Smuzhiyun _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
7366*4882a593Smuzhiyun }
7367*4882a593Smuzhiyun
7368*4882a593Smuzhiyun /*
7369*4882a593Smuzhiyun * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
7370*4882a593Smuzhiyun * This implements the WaDisableRCZUnitClockGating:ivb workaround.
7371*4882a593Smuzhiyun */
7372*4882a593Smuzhiyun I915_WRITE(GEN6_UCGCTL2,
7373*4882a593Smuzhiyun GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
7374*4882a593Smuzhiyun
7375*4882a593Smuzhiyun /* This is required by WaCatErrorRejectionIssue:ivb */
7376*4882a593Smuzhiyun I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
7377*4882a593Smuzhiyun I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
7378*4882a593Smuzhiyun GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
7379*4882a593Smuzhiyun
7380*4882a593Smuzhiyun g4x_disable_trickle_feed(dev_priv);
7381*4882a593Smuzhiyun
7382*4882a593Smuzhiyun snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
7383*4882a593Smuzhiyun snpcr &= ~GEN6_MBC_SNPCR_MASK;
7384*4882a593Smuzhiyun snpcr |= GEN6_MBC_SNPCR_MED;
7385*4882a593Smuzhiyun I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
7386*4882a593Smuzhiyun
7387*4882a593Smuzhiyun if (!HAS_PCH_NOP(dev_priv))
7388*4882a593Smuzhiyun cpt_init_clock_gating(dev_priv);
7389*4882a593Smuzhiyun
7390*4882a593Smuzhiyun gen6_check_mch_setup(dev_priv);
7391*4882a593Smuzhiyun }
7392*4882a593Smuzhiyun
vlv_init_clock_gating(struct drm_i915_private * dev_priv)7393*4882a593Smuzhiyun static void vlv_init_clock_gating(struct drm_i915_private *dev_priv)
7394*4882a593Smuzhiyun {
7395*4882a593Smuzhiyun /* WaDisableBackToBackFlipFix:vlv */
7396*4882a593Smuzhiyun I915_WRITE(IVB_CHICKEN3,
7397*4882a593Smuzhiyun CHICKEN3_DGMG_REQ_OUT_FIX_DISABLE |
7398*4882a593Smuzhiyun CHICKEN3_DGMG_DONE_FIX_DISABLE);
7399*4882a593Smuzhiyun
7400*4882a593Smuzhiyun /* WaDisableDopClockGating:vlv */
7401*4882a593Smuzhiyun I915_WRITE(GEN7_ROW_CHICKEN2,
7402*4882a593Smuzhiyun _MASKED_BIT_ENABLE(DOP_CLOCK_GATING_DISABLE));
7403*4882a593Smuzhiyun
7404*4882a593Smuzhiyun /* This is required by WaCatErrorRejectionIssue:vlv */
7405*4882a593Smuzhiyun I915_WRITE(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG,
7406*4882a593Smuzhiyun I915_READ(GEN7_SQ_CHICKEN_MBCUNIT_CONFIG) |
7407*4882a593Smuzhiyun GEN7_SQ_CHICKEN_MBCUNIT_SQINTMOB);
7408*4882a593Smuzhiyun
7409*4882a593Smuzhiyun /*
7410*4882a593Smuzhiyun * According to the spec, bit 13 (RCZUNIT) must be set on IVB.
7411*4882a593Smuzhiyun * This implements the WaDisableRCZUnitClockGating:vlv workaround.
7412*4882a593Smuzhiyun */
7413*4882a593Smuzhiyun I915_WRITE(GEN6_UCGCTL2,
7414*4882a593Smuzhiyun GEN6_RCZUNIT_CLOCK_GATE_DISABLE);
7415*4882a593Smuzhiyun
7416*4882a593Smuzhiyun /* WaDisableL3Bank2xClockGate:vlv
7417*4882a593Smuzhiyun * Disabling L3 clock gating- MMIO 940c[25] = 1
7418*4882a593Smuzhiyun * Set bit 25, to disable L3_BANK_2x_CLK_GATING */
7419*4882a593Smuzhiyun I915_WRITE(GEN7_UCGCTL4,
7420*4882a593Smuzhiyun I915_READ(GEN7_UCGCTL4) | GEN7_L3BANK2X_CLOCK_GATE_DISABLE);
7421*4882a593Smuzhiyun
7422*4882a593Smuzhiyun /*
7423*4882a593Smuzhiyun * WaDisableVLVClockGating_VBIIssue:vlv
7424*4882a593Smuzhiyun * Disable clock gating on th GCFG unit to prevent a delay
7425*4882a593Smuzhiyun * in the reporting of vblank events.
7426*4882a593Smuzhiyun */
7427*4882a593Smuzhiyun I915_WRITE(VLV_GUNIT_CLOCK_GATE, GCFG_DIS);
7428*4882a593Smuzhiyun }
7429*4882a593Smuzhiyun
chv_init_clock_gating(struct drm_i915_private * dev_priv)7430*4882a593Smuzhiyun static void chv_init_clock_gating(struct drm_i915_private *dev_priv)
7431*4882a593Smuzhiyun {
7432*4882a593Smuzhiyun /* WaVSRefCountFullforceMissDisable:chv */
7433*4882a593Smuzhiyun /* WaDSRefCountFullforceMissDisable:chv */
7434*4882a593Smuzhiyun I915_WRITE(GEN7_FF_THREAD_MODE,
7435*4882a593Smuzhiyun I915_READ(GEN7_FF_THREAD_MODE) &
7436*4882a593Smuzhiyun ~(GEN8_FF_DS_REF_CNT_FFME | GEN7_FF_VS_REF_CNT_FFME));
7437*4882a593Smuzhiyun
7438*4882a593Smuzhiyun /* WaDisableSemaphoreAndSyncFlipWait:chv */
7439*4882a593Smuzhiyun I915_WRITE(GEN6_RC_SLEEP_PSMI_CONTROL,
7440*4882a593Smuzhiyun _MASKED_BIT_ENABLE(GEN8_RC_SEMA_IDLE_MSG_DISABLE));
7441*4882a593Smuzhiyun
7442*4882a593Smuzhiyun /* WaDisableCSUnitClockGating:chv */
7443*4882a593Smuzhiyun I915_WRITE(GEN6_UCGCTL1, I915_READ(GEN6_UCGCTL1) |
7444*4882a593Smuzhiyun GEN6_CSUNIT_CLOCK_GATE_DISABLE);
7445*4882a593Smuzhiyun
7446*4882a593Smuzhiyun /* WaDisableSDEUnitClockGating:chv */
7447*4882a593Smuzhiyun I915_WRITE(GEN8_UCGCTL6, I915_READ(GEN8_UCGCTL6) |
7448*4882a593Smuzhiyun GEN8_SDEUNIT_CLOCK_GATE_DISABLE);
7449*4882a593Smuzhiyun
7450*4882a593Smuzhiyun /*
7451*4882a593Smuzhiyun * WaProgramL3SqcReg1Default:chv
7452*4882a593Smuzhiyun * See gfxspecs/Related Documents/Performance Guide/
7453*4882a593Smuzhiyun * LSQC Setting Recommendations.
7454*4882a593Smuzhiyun */
7455*4882a593Smuzhiyun gen8_set_l3sqc_credits(dev_priv, 38, 2);
7456*4882a593Smuzhiyun }
7457*4882a593Smuzhiyun
g4x_init_clock_gating(struct drm_i915_private * dev_priv)7458*4882a593Smuzhiyun static void g4x_init_clock_gating(struct drm_i915_private *dev_priv)
7459*4882a593Smuzhiyun {
7460*4882a593Smuzhiyun u32 dspclk_gate;
7461*4882a593Smuzhiyun
7462*4882a593Smuzhiyun I915_WRITE(RENCLK_GATE_D1, 0);
7463*4882a593Smuzhiyun I915_WRITE(RENCLK_GATE_D2, VF_UNIT_CLOCK_GATE_DISABLE |
7464*4882a593Smuzhiyun GS_UNIT_CLOCK_GATE_DISABLE |
7465*4882a593Smuzhiyun CL_UNIT_CLOCK_GATE_DISABLE);
7466*4882a593Smuzhiyun I915_WRITE(RAMCLK_GATE_D, 0);
7467*4882a593Smuzhiyun dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE |
7468*4882a593Smuzhiyun OVRUNIT_CLOCK_GATE_DISABLE |
7469*4882a593Smuzhiyun OVCUNIT_CLOCK_GATE_DISABLE;
7470*4882a593Smuzhiyun if (IS_GM45(dev_priv))
7471*4882a593Smuzhiyun dspclk_gate |= DSSUNIT_CLOCK_GATE_DISABLE;
7472*4882a593Smuzhiyun I915_WRITE(DSPCLK_GATE_D, dspclk_gate);
7473*4882a593Smuzhiyun
7474*4882a593Smuzhiyun g4x_disable_trickle_feed(dev_priv);
7475*4882a593Smuzhiyun }
7476*4882a593Smuzhiyun
i965gm_init_clock_gating(struct drm_i915_private * dev_priv)7477*4882a593Smuzhiyun static void i965gm_init_clock_gating(struct drm_i915_private *dev_priv)
7478*4882a593Smuzhiyun {
7479*4882a593Smuzhiyun struct intel_uncore *uncore = &dev_priv->uncore;
7480*4882a593Smuzhiyun
7481*4882a593Smuzhiyun intel_uncore_write(uncore, RENCLK_GATE_D1, I965_RCC_CLOCK_GATE_DISABLE);
7482*4882a593Smuzhiyun intel_uncore_write(uncore, RENCLK_GATE_D2, 0);
7483*4882a593Smuzhiyun intel_uncore_write(uncore, DSPCLK_GATE_D, 0);
7484*4882a593Smuzhiyun intel_uncore_write(uncore, RAMCLK_GATE_D, 0);
7485*4882a593Smuzhiyun intel_uncore_write16(uncore, DEUC, 0);
7486*4882a593Smuzhiyun intel_uncore_write(uncore,
7487*4882a593Smuzhiyun MI_ARB_STATE,
7488*4882a593Smuzhiyun _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
7489*4882a593Smuzhiyun }
7490*4882a593Smuzhiyun
i965g_init_clock_gating(struct drm_i915_private * dev_priv)7491*4882a593Smuzhiyun static void i965g_init_clock_gating(struct drm_i915_private *dev_priv)
7492*4882a593Smuzhiyun {
7493*4882a593Smuzhiyun I915_WRITE(RENCLK_GATE_D1, I965_RCZ_CLOCK_GATE_DISABLE |
7494*4882a593Smuzhiyun I965_RCC_CLOCK_GATE_DISABLE |
7495*4882a593Smuzhiyun I965_RCPB_CLOCK_GATE_DISABLE |
7496*4882a593Smuzhiyun I965_ISC_CLOCK_GATE_DISABLE |
7497*4882a593Smuzhiyun I965_FBC_CLOCK_GATE_DISABLE);
7498*4882a593Smuzhiyun I915_WRITE(RENCLK_GATE_D2, 0);
7499*4882a593Smuzhiyun I915_WRITE(MI_ARB_STATE,
7500*4882a593Smuzhiyun _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
7501*4882a593Smuzhiyun }
7502*4882a593Smuzhiyun
gen3_init_clock_gating(struct drm_i915_private * dev_priv)7503*4882a593Smuzhiyun static void gen3_init_clock_gating(struct drm_i915_private *dev_priv)
7504*4882a593Smuzhiyun {
7505*4882a593Smuzhiyun u32 dstate = I915_READ(D_STATE);
7506*4882a593Smuzhiyun
7507*4882a593Smuzhiyun dstate |= DSTATE_PLL_D3_OFF | DSTATE_GFX_CLOCK_GATING |
7508*4882a593Smuzhiyun DSTATE_DOT_CLOCK_GATING;
7509*4882a593Smuzhiyun I915_WRITE(D_STATE, dstate);
7510*4882a593Smuzhiyun
7511*4882a593Smuzhiyun if (IS_PINEVIEW(dev_priv))
7512*4882a593Smuzhiyun I915_WRITE(ECOSKPD, _MASKED_BIT_ENABLE(ECO_GATING_CX_ONLY));
7513*4882a593Smuzhiyun
7514*4882a593Smuzhiyun /* IIR "flip pending" means done if this bit is set */
7515*4882a593Smuzhiyun I915_WRITE(ECOSKPD, _MASKED_BIT_DISABLE(ECO_FLIP_DONE));
7516*4882a593Smuzhiyun
7517*4882a593Smuzhiyun /* interrupts should cause a wake up from C3 */
7518*4882a593Smuzhiyun I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_INT_EN));
7519*4882a593Smuzhiyun
7520*4882a593Smuzhiyun /* On GEN3 we really need to make sure the ARB C3 LP bit is set */
7521*4882a593Smuzhiyun I915_WRITE(MI_ARB_STATE, _MASKED_BIT_ENABLE(MI_ARB_C3_LP_WRITE_ENABLE));
7522*4882a593Smuzhiyun
7523*4882a593Smuzhiyun I915_WRITE(MI_ARB_STATE,
7524*4882a593Smuzhiyun _MASKED_BIT_ENABLE(MI_ARB_DISPLAY_TRICKLE_FEED_DISABLE));
7525*4882a593Smuzhiyun }
7526*4882a593Smuzhiyun
i85x_init_clock_gating(struct drm_i915_private * dev_priv)7527*4882a593Smuzhiyun static void i85x_init_clock_gating(struct drm_i915_private *dev_priv)
7528*4882a593Smuzhiyun {
7529*4882a593Smuzhiyun I915_WRITE(RENCLK_GATE_D1, SV_CLOCK_GATE_DISABLE);
7530*4882a593Smuzhiyun
7531*4882a593Smuzhiyun /* interrupts should cause a wake up from C3 */
7532*4882a593Smuzhiyun I915_WRITE(MI_STATE, _MASKED_BIT_ENABLE(MI_AGPBUSY_INT_EN) |
7533*4882a593Smuzhiyun _MASKED_BIT_DISABLE(MI_AGPBUSY_830_MODE));
7534*4882a593Smuzhiyun
7535*4882a593Smuzhiyun I915_WRITE(MEM_MODE,
7536*4882a593Smuzhiyun _MASKED_BIT_ENABLE(MEM_DISPLAY_TRICKLE_FEED_DISABLE));
7537*4882a593Smuzhiyun
7538*4882a593Smuzhiyun /*
7539*4882a593Smuzhiyun * Have FBC ignore 3D activity since we use software
7540*4882a593Smuzhiyun * render tracking, and otherwise a pure 3D workload
7541*4882a593Smuzhiyun * (even if it just renders a single frame and then does
7542*4882a593Smuzhiyun * abosultely nothing) would not allow FBC to recompress
7543*4882a593Smuzhiyun * until a 2D blit occurs.
7544*4882a593Smuzhiyun */
7545*4882a593Smuzhiyun I915_WRITE(SCPD0,
7546*4882a593Smuzhiyun _MASKED_BIT_ENABLE(SCPD_FBC_IGNORE_3D));
7547*4882a593Smuzhiyun }
7548*4882a593Smuzhiyun
i830_init_clock_gating(struct drm_i915_private * dev_priv)7549*4882a593Smuzhiyun static void i830_init_clock_gating(struct drm_i915_private *dev_priv)
7550*4882a593Smuzhiyun {
7551*4882a593Smuzhiyun I915_WRITE(MEM_MODE,
7552*4882a593Smuzhiyun _MASKED_BIT_ENABLE(MEM_DISPLAY_A_TRICKLE_FEED_DISABLE) |
7553*4882a593Smuzhiyun _MASKED_BIT_ENABLE(MEM_DISPLAY_B_TRICKLE_FEED_DISABLE));
7554*4882a593Smuzhiyun }
7555*4882a593Smuzhiyun
intel_init_clock_gating(struct drm_i915_private * dev_priv)7556*4882a593Smuzhiyun void intel_init_clock_gating(struct drm_i915_private *dev_priv)
7557*4882a593Smuzhiyun {
7558*4882a593Smuzhiyun dev_priv->display.init_clock_gating(dev_priv);
7559*4882a593Smuzhiyun }
7560*4882a593Smuzhiyun
intel_suspend_hw(struct drm_i915_private * dev_priv)7561*4882a593Smuzhiyun void intel_suspend_hw(struct drm_i915_private *dev_priv)
7562*4882a593Smuzhiyun {
7563*4882a593Smuzhiyun if (HAS_PCH_LPT(dev_priv))
7564*4882a593Smuzhiyun lpt_suspend_hw(dev_priv);
7565*4882a593Smuzhiyun }
7566*4882a593Smuzhiyun
nop_init_clock_gating(struct drm_i915_private * dev_priv)7567*4882a593Smuzhiyun static void nop_init_clock_gating(struct drm_i915_private *dev_priv)
7568*4882a593Smuzhiyun {
7569*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
7570*4882a593Smuzhiyun "No clock gating settings or workarounds applied.\n");
7571*4882a593Smuzhiyun }
7572*4882a593Smuzhiyun
7573*4882a593Smuzhiyun /**
7574*4882a593Smuzhiyun * intel_init_clock_gating_hooks - setup the clock gating hooks
7575*4882a593Smuzhiyun * @dev_priv: device private
7576*4882a593Smuzhiyun *
7577*4882a593Smuzhiyun * Setup the hooks that configure which clocks of a given platform can be
7578*4882a593Smuzhiyun * gated and also apply various GT and display specific workarounds for these
7579*4882a593Smuzhiyun * platforms. Note that some GT specific workarounds are applied separately
7580*4882a593Smuzhiyun * when GPU contexts or batchbuffers start their execution.
7581*4882a593Smuzhiyun */
intel_init_clock_gating_hooks(struct drm_i915_private * dev_priv)7582*4882a593Smuzhiyun void intel_init_clock_gating_hooks(struct drm_i915_private *dev_priv)
7583*4882a593Smuzhiyun {
7584*4882a593Smuzhiyun if (IS_GEN(dev_priv, 12))
7585*4882a593Smuzhiyun dev_priv->display.init_clock_gating = tgl_init_clock_gating;
7586*4882a593Smuzhiyun else if (IS_GEN(dev_priv, 11))
7587*4882a593Smuzhiyun dev_priv->display.init_clock_gating = icl_init_clock_gating;
7588*4882a593Smuzhiyun else if (IS_CANNONLAKE(dev_priv))
7589*4882a593Smuzhiyun dev_priv->display.init_clock_gating = cnl_init_clock_gating;
7590*4882a593Smuzhiyun else if (IS_COFFEELAKE(dev_priv) || IS_COMETLAKE(dev_priv))
7591*4882a593Smuzhiyun dev_priv->display.init_clock_gating = cfl_init_clock_gating;
7592*4882a593Smuzhiyun else if (IS_SKYLAKE(dev_priv))
7593*4882a593Smuzhiyun dev_priv->display.init_clock_gating = skl_init_clock_gating;
7594*4882a593Smuzhiyun else if (IS_KABYLAKE(dev_priv))
7595*4882a593Smuzhiyun dev_priv->display.init_clock_gating = kbl_init_clock_gating;
7596*4882a593Smuzhiyun else if (IS_BROXTON(dev_priv))
7597*4882a593Smuzhiyun dev_priv->display.init_clock_gating = bxt_init_clock_gating;
7598*4882a593Smuzhiyun else if (IS_GEMINILAKE(dev_priv))
7599*4882a593Smuzhiyun dev_priv->display.init_clock_gating = glk_init_clock_gating;
7600*4882a593Smuzhiyun else if (IS_BROADWELL(dev_priv))
7601*4882a593Smuzhiyun dev_priv->display.init_clock_gating = bdw_init_clock_gating;
7602*4882a593Smuzhiyun else if (IS_CHERRYVIEW(dev_priv))
7603*4882a593Smuzhiyun dev_priv->display.init_clock_gating = chv_init_clock_gating;
7604*4882a593Smuzhiyun else if (IS_HASWELL(dev_priv))
7605*4882a593Smuzhiyun dev_priv->display.init_clock_gating = hsw_init_clock_gating;
7606*4882a593Smuzhiyun else if (IS_IVYBRIDGE(dev_priv))
7607*4882a593Smuzhiyun dev_priv->display.init_clock_gating = ivb_init_clock_gating;
7608*4882a593Smuzhiyun else if (IS_VALLEYVIEW(dev_priv))
7609*4882a593Smuzhiyun dev_priv->display.init_clock_gating = vlv_init_clock_gating;
7610*4882a593Smuzhiyun else if (IS_GEN(dev_priv, 6))
7611*4882a593Smuzhiyun dev_priv->display.init_clock_gating = gen6_init_clock_gating;
7612*4882a593Smuzhiyun else if (IS_GEN(dev_priv, 5))
7613*4882a593Smuzhiyun dev_priv->display.init_clock_gating = ilk_init_clock_gating;
7614*4882a593Smuzhiyun else if (IS_G4X(dev_priv))
7615*4882a593Smuzhiyun dev_priv->display.init_clock_gating = g4x_init_clock_gating;
7616*4882a593Smuzhiyun else if (IS_I965GM(dev_priv))
7617*4882a593Smuzhiyun dev_priv->display.init_clock_gating = i965gm_init_clock_gating;
7618*4882a593Smuzhiyun else if (IS_I965G(dev_priv))
7619*4882a593Smuzhiyun dev_priv->display.init_clock_gating = i965g_init_clock_gating;
7620*4882a593Smuzhiyun else if (IS_GEN(dev_priv, 3))
7621*4882a593Smuzhiyun dev_priv->display.init_clock_gating = gen3_init_clock_gating;
7622*4882a593Smuzhiyun else if (IS_I85X(dev_priv) || IS_I865G(dev_priv))
7623*4882a593Smuzhiyun dev_priv->display.init_clock_gating = i85x_init_clock_gating;
7624*4882a593Smuzhiyun else if (IS_GEN(dev_priv, 2))
7625*4882a593Smuzhiyun dev_priv->display.init_clock_gating = i830_init_clock_gating;
7626*4882a593Smuzhiyun else {
7627*4882a593Smuzhiyun MISSING_CASE(INTEL_DEVID(dev_priv));
7628*4882a593Smuzhiyun dev_priv->display.init_clock_gating = nop_init_clock_gating;
7629*4882a593Smuzhiyun }
7630*4882a593Smuzhiyun }
7631*4882a593Smuzhiyun
7632*4882a593Smuzhiyun /* Set up chip specific power management-related functions */
intel_init_pm(struct drm_i915_private * dev_priv)7633*4882a593Smuzhiyun void intel_init_pm(struct drm_i915_private *dev_priv)
7634*4882a593Smuzhiyun {
7635*4882a593Smuzhiyun /* For cxsr */
7636*4882a593Smuzhiyun if (IS_PINEVIEW(dev_priv))
7637*4882a593Smuzhiyun pnv_get_mem_freq(dev_priv);
7638*4882a593Smuzhiyun else if (IS_GEN(dev_priv, 5))
7639*4882a593Smuzhiyun ilk_get_mem_freq(dev_priv);
7640*4882a593Smuzhiyun
7641*4882a593Smuzhiyun if (intel_has_sagv(dev_priv))
7642*4882a593Smuzhiyun skl_setup_sagv_block_time(dev_priv);
7643*4882a593Smuzhiyun
7644*4882a593Smuzhiyun /* For FIFO watermark updates */
7645*4882a593Smuzhiyun if (INTEL_GEN(dev_priv) >= 9) {
7646*4882a593Smuzhiyun skl_setup_wm_latency(dev_priv);
7647*4882a593Smuzhiyun dev_priv->display.compute_global_watermarks = skl_compute_wm;
7648*4882a593Smuzhiyun } else if (HAS_PCH_SPLIT(dev_priv)) {
7649*4882a593Smuzhiyun ilk_setup_wm_latency(dev_priv);
7650*4882a593Smuzhiyun
7651*4882a593Smuzhiyun if ((IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[1] &&
7652*4882a593Smuzhiyun dev_priv->wm.spr_latency[1] && dev_priv->wm.cur_latency[1]) ||
7653*4882a593Smuzhiyun (!IS_GEN(dev_priv, 5) && dev_priv->wm.pri_latency[0] &&
7654*4882a593Smuzhiyun dev_priv->wm.spr_latency[0] && dev_priv->wm.cur_latency[0])) {
7655*4882a593Smuzhiyun dev_priv->display.compute_pipe_wm = ilk_compute_pipe_wm;
7656*4882a593Smuzhiyun dev_priv->display.compute_intermediate_wm =
7657*4882a593Smuzhiyun ilk_compute_intermediate_wm;
7658*4882a593Smuzhiyun dev_priv->display.initial_watermarks =
7659*4882a593Smuzhiyun ilk_initial_watermarks;
7660*4882a593Smuzhiyun dev_priv->display.optimize_watermarks =
7661*4882a593Smuzhiyun ilk_optimize_watermarks;
7662*4882a593Smuzhiyun } else {
7663*4882a593Smuzhiyun drm_dbg_kms(&dev_priv->drm,
7664*4882a593Smuzhiyun "Failed to read display plane latency. "
7665*4882a593Smuzhiyun "Disable CxSR\n");
7666*4882a593Smuzhiyun }
7667*4882a593Smuzhiyun } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
7668*4882a593Smuzhiyun vlv_setup_wm_latency(dev_priv);
7669*4882a593Smuzhiyun dev_priv->display.compute_pipe_wm = vlv_compute_pipe_wm;
7670*4882a593Smuzhiyun dev_priv->display.compute_intermediate_wm = vlv_compute_intermediate_wm;
7671*4882a593Smuzhiyun dev_priv->display.initial_watermarks = vlv_initial_watermarks;
7672*4882a593Smuzhiyun dev_priv->display.optimize_watermarks = vlv_optimize_watermarks;
7673*4882a593Smuzhiyun dev_priv->display.atomic_update_watermarks = vlv_atomic_update_fifo;
7674*4882a593Smuzhiyun } else if (IS_G4X(dev_priv)) {
7675*4882a593Smuzhiyun g4x_setup_wm_latency(dev_priv);
7676*4882a593Smuzhiyun dev_priv->display.compute_pipe_wm = g4x_compute_pipe_wm;
7677*4882a593Smuzhiyun dev_priv->display.compute_intermediate_wm = g4x_compute_intermediate_wm;
7678*4882a593Smuzhiyun dev_priv->display.initial_watermarks = g4x_initial_watermarks;
7679*4882a593Smuzhiyun dev_priv->display.optimize_watermarks = g4x_optimize_watermarks;
7680*4882a593Smuzhiyun } else if (IS_PINEVIEW(dev_priv)) {
7681*4882a593Smuzhiyun if (!intel_get_cxsr_latency(!IS_MOBILE(dev_priv),
7682*4882a593Smuzhiyun dev_priv->is_ddr3,
7683*4882a593Smuzhiyun dev_priv->fsb_freq,
7684*4882a593Smuzhiyun dev_priv->mem_freq)) {
7685*4882a593Smuzhiyun drm_info(&dev_priv->drm,
7686*4882a593Smuzhiyun "failed to find known CxSR latency "
7687*4882a593Smuzhiyun "(found ddr%s fsb freq %d, mem freq %d), "
7688*4882a593Smuzhiyun "disabling CxSR\n",
7689*4882a593Smuzhiyun (dev_priv->is_ddr3 == 1) ? "3" : "2",
7690*4882a593Smuzhiyun dev_priv->fsb_freq, dev_priv->mem_freq);
7691*4882a593Smuzhiyun /* Disable CxSR and never update its watermark again */
7692*4882a593Smuzhiyun intel_set_memory_cxsr(dev_priv, false);
7693*4882a593Smuzhiyun dev_priv->display.update_wm = NULL;
7694*4882a593Smuzhiyun } else
7695*4882a593Smuzhiyun dev_priv->display.update_wm = pnv_update_wm;
7696*4882a593Smuzhiyun } else if (IS_GEN(dev_priv, 4)) {
7697*4882a593Smuzhiyun dev_priv->display.update_wm = i965_update_wm;
7698*4882a593Smuzhiyun } else if (IS_GEN(dev_priv, 3)) {
7699*4882a593Smuzhiyun dev_priv->display.update_wm = i9xx_update_wm;
7700*4882a593Smuzhiyun dev_priv->display.get_fifo_size = i9xx_get_fifo_size;
7701*4882a593Smuzhiyun } else if (IS_GEN(dev_priv, 2)) {
7702*4882a593Smuzhiyun if (INTEL_NUM_PIPES(dev_priv) == 1) {
7703*4882a593Smuzhiyun dev_priv->display.update_wm = i845_update_wm;
7704*4882a593Smuzhiyun dev_priv->display.get_fifo_size = i845_get_fifo_size;
7705*4882a593Smuzhiyun } else {
7706*4882a593Smuzhiyun dev_priv->display.update_wm = i9xx_update_wm;
7707*4882a593Smuzhiyun dev_priv->display.get_fifo_size = i830_get_fifo_size;
7708*4882a593Smuzhiyun }
7709*4882a593Smuzhiyun } else {
7710*4882a593Smuzhiyun drm_err(&dev_priv->drm,
7711*4882a593Smuzhiyun "unexpected fall-through in %s\n", __func__);
7712*4882a593Smuzhiyun }
7713*4882a593Smuzhiyun }
7714*4882a593Smuzhiyun
intel_pm_setup(struct drm_i915_private * dev_priv)7715*4882a593Smuzhiyun void intel_pm_setup(struct drm_i915_private *dev_priv)
7716*4882a593Smuzhiyun {
7717*4882a593Smuzhiyun dev_priv->runtime_pm.suspended = false;
7718*4882a593Smuzhiyun atomic_set(&dev_priv->runtime_pm.wakeref_count, 0);
7719*4882a593Smuzhiyun }
7720*4882a593Smuzhiyun
intel_dbuf_duplicate_state(struct intel_global_obj * obj)7721*4882a593Smuzhiyun static struct intel_global_state *intel_dbuf_duplicate_state(struct intel_global_obj *obj)
7722*4882a593Smuzhiyun {
7723*4882a593Smuzhiyun struct intel_dbuf_state *dbuf_state;
7724*4882a593Smuzhiyun
7725*4882a593Smuzhiyun dbuf_state = kmemdup(obj->state, sizeof(*dbuf_state), GFP_KERNEL);
7726*4882a593Smuzhiyun if (!dbuf_state)
7727*4882a593Smuzhiyun return NULL;
7728*4882a593Smuzhiyun
7729*4882a593Smuzhiyun return &dbuf_state->base;
7730*4882a593Smuzhiyun }
7731*4882a593Smuzhiyun
intel_dbuf_destroy_state(struct intel_global_obj * obj,struct intel_global_state * state)7732*4882a593Smuzhiyun static void intel_dbuf_destroy_state(struct intel_global_obj *obj,
7733*4882a593Smuzhiyun struct intel_global_state *state)
7734*4882a593Smuzhiyun {
7735*4882a593Smuzhiyun kfree(state);
7736*4882a593Smuzhiyun }
7737*4882a593Smuzhiyun
7738*4882a593Smuzhiyun static const struct intel_global_state_funcs intel_dbuf_funcs = {
7739*4882a593Smuzhiyun .atomic_duplicate_state = intel_dbuf_duplicate_state,
7740*4882a593Smuzhiyun .atomic_destroy_state = intel_dbuf_destroy_state,
7741*4882a593Smuzhiyun };
7742*4882a593Smuzhiyun
7743*4882a593Smuzhiyun struct intel_dbuf_state *
intel_atomic_get_dbuf_state(struct intel_atomic_state * state)7744*4882a593Smuzhiyun intel_atomic_get_dbuf_state(struct intel_atomic_state *state)
7745*4882a593Smuzhiyun {
7746*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7747*4882a593Smuzhiyun struct intel_global_state *dbuf_state;
7748*4882a593Smuzhiyun
7749*4882a593Smuzhiyun dbuf_state = intel_atomic_get_global_obj_state(state, &dev_priv->dbuf.obj);
7750*4882a593Smuzhiyun if (IS_ERR(dbuf_state))
7751*4882a593Smuzhiyun return ERR_CAST(dbuf_state);
7752*4882a593Smuzhiyun
7753*4882a593Smuzhiyun return to_intel_dbuf_state(dbuf_state);
7754*4882a593Smuzhiyun }
7755*4882a593Smuzhiyun
intel_dbuf_init(struct drm_i915_private * dev_priv)7756*4882a593Smuzhiyun int intel_dbuf_init(struct drm_i915_private *dev_priv)
7757*4882a593Smuzhiyun {
7758*4882a593Smuzhiyun struct intel_dbuf_state *dbuf_state;
7759*4882a593Smuzhiyun
7760*4882a593Smuzhiyun dbuf_state = kzalloc(sizeof(*dbuf_state), GFP_KERNEL);
7761*4882a593Smuzhiyun if (!dbuf_state)
7762*4882a593Smuzhiyun return -ENOMEM;
7763*4882a593Smuzhiyun
7764*4882a593Smuzhiyun intel_atomic_global_obj_init(dev_priv, &dev_priv->dbuf.obj,
7765*4882a593Smuzhiyun &dbuf_state->base, &intel_dbuf_funcs);
7766*4882a593Smuzhiyun
7767*4882a593Smuzhiyun return 0;
7768*4882a593Smuzhiyun }
7769*4882a593Smuzhiyun
intel_dbuf_pre_plane_update(struct intel_atomic_state * state)7770*4882a593Smuzhiyun void intel_dbuf_pre_plane_update(struct intel_atomic_state *state)
7771*4882a593Smuzhiyun {
7772*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7773*4882a593Smuzhiyun const struct intel_dbuf_state *new_dbuf_state =
7774*4882a593Smuzhiyun intel_atomic_get_new_dbuf_state(state);
7775*4882a593Smuzhiyun const struct intel_dbuf_state *old_dbuf_state =
7776*4882a593Smuzhiyun intel_atomic_get_old_dbuf_state(state);
7777*4882a593Smuzhiyun
7778*4882a593Smuzhiyun if (!new_dbuf_state ||
7779*4882a593Smuzhiyun new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices)
7780*4882a593Smuzhiyun return;
7781*4882a593Smuzhiyun
7782*4882a593Smuzhiyun WARN_ON(!new_dbuf_state->base.changed);
7783*4882a593Smuzhiyun
7784*4882a593Smuzhiyun gen9_dbuf_slices_update(dev_priv,
7785*4882a593Smuzhiyun old_dbuf_state->enabled_slices |
7786*4882a593Smuzhiyun new_dbuf_state->enabled_slices);
7787*4882a593Smuzhiyun }
7788*4882a593Smuzhiyun
intel_dbuf_post_plane_update(struct intel_atomic_state * state)7789*4882a593Smuzhiyun void intel_dbuf_post_plane_update(struct intel_atomic_state *state)
7790*4882a593Smuzhiyun {
7791*4882a593Smuzhiyun struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7792*4882a593Smuzhiyun const struct intel_dbuf_state *new_dbuf_state =
7793*4882a593Smuzhiyun intel_atomic_get_new_dbuf_state(state);
7794*4882a593Smuzhiyun const struct intel_dbuf_state *old_dbuf_state =
7795*4882a593Smuzhiyun intel_atomic_get_old_dbuf_state(state);
7796*4882a593Smuzhiyun
7797*4882a593Smuzhiyun if (!new_dbuf_state ||
7798*4882a593Smuzhiyun new_dbuf_state->enabled_slices == old_dbuf_state->enabled_slices)
7799*4882a593Smuzhiyun return;
7800*4882a593Smuzhiyun
7801*4882a593Smuzhiyun WARN_ON(!new_dbuf_state->base.changed);
7802*4882a593Smuzhiyun
7803*4882a593Smuzhiyun gen9_dbuf_slices_update(dev_priv,
7804*4882a593Smuzhiyun new_dbuf_state->enabled_slices);
7805*4882a593Smuzhiyun }
7806