1 /*
2 * Copyright © 2006-2007 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <[email protected]>
25 */
26
27 #include <linux/dma-resv.h>
28 #include <linux/i2c.h>
29 #include <linux/input.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/string_helpers.h>
34
35 #include <drm/display/drm_dp_helper.h>
36 #include <drm/display/drm_dp_tunnel.h>
37 #include <drm/drm_atomic.h>
38 #include <drm/drm_atomic_helper.h>
39 #include <drm/drm_atomic_uapi.h>
40 #include <drm/drm_damage_helper.h>
41 #include <drm/drm_edid.h>
42 #include <drm/drm_fixed.h>
43 #include <drm/drm_fourcc.h>
44 #include <drm/drm_probe_helper.h>
45 #include <drm/drm_rect.h>
46 #include <drm/drm_vblank.h>
47
48 #include "g4x_dp.h"
49 #include "g4x_hdmi.h"
50 #include "hsw_ips.h"
51 #include "i915_config.h"
52 #include "i915_drv.h"
53 #include "i915_reg.h"
54 #include "i915_utils.h"
55 #include "i9xx_plane.h"
56 #include "i9xx_plane_regs.h"
57 #include "i9xx_wm.h"
58 #include "intel_atomic.h"
59 #include "intel_atomic_plane.h"
60 #include "intel_audio.h"
61 #include "intel_bo.h"
62 #include "intel_bw.h"
63 #include "intel_cdclk.h"
64 #include "intel_clock_gating.h"
65 #include "intel_color.h"
66 #include "intel_crt.h"
67 #include "intel_crtc.h"
68 #include "intel_crtc_state_dump.h"
69 #include "intel_cursor_regs.h"
70 #include "intel_cx0_phy.h"
71 #include "intel_cursor.h"
72 #include "intel_ddi.h"
73 #include "intel_de.h"
74 #include "intel_display_driver.h"
75 #include "intel_display_power.h"
76 #include "intel_display_types.h"
77 #include "intel_dmc.h"
78 #include "intel_dp.h"
79 #include "intel_dp_link_training.h"
80 #include "intel_dp_mst.h"
81 #include "intel_dp_tunnel.h"
82 #include "intel_dpll.h"
83 #include "intel_dpll_mgr.h"
84 #include "intel_dpt.h"
85 #include "intel_dpt_common.h"
86 #include "intel_drrs.h"
87 #include "intel_dsb.h"
88 #include "intel_dsi.h"
89 #include "intel_dvo.h"
90 #include "intel_fb.h"
91 #include "intel_fbc.h"
92 #include "intel_fdi.h"
93 #include "intel_fifo_underrun.h"
94 #include "intel_frontbuffer.h"
95 #include "intel_hdmi.h"
96 #include "intel_hotplug.h"
97 #include "intel_link_bw.h"
98 #include "intel_lvds.h"
99 #include "intel_lvds_regs.h"
100 #include "intel_modeset_setup.h"
101 #include "intel_modeset_verify.h"
102 #include "intel_overlay.h"
103 #include "intel_panel.h"
104 #include "intel_pch_display.h"
105 #include "intel_pch_refclk.h"
106 #include "intel_pcode.h"
107 #include "intel_pipe_crc.h"
108 #include "intel_plane_initial.h"
109 #include "intel_pmdemand.h"
110 #include "intel_pps.h"
111 #include "intel_psr.h"
112 #include "intel_psr_regs.h"
113 #include "intel_sdvo.h"
114 #include "intel_snps_phy.h"
115 #include "intel_tc.h"
116 #include "intel_tdf.h"
117 #include "intel_tv.h"
118 #include "intel_vblank.h"
119 #include "intel_vdsc.h"
120 #include "intel_vdsc_regs.h"
121 #include "intel_vga.h"
122 #include "intel_vrr.h"
123 #include "intel_wm.h"
124 #include "skl_scaler.h"
125 #include "skl_universal_plane.h"
126 #include "skl_universal_plane_regs.h"
127 #include "skl_watermark.h"
128 #include "vlv_dpio_phy_regs.h"
129 #include "vlv_dsi.h"
130 #include "vlv_dsi_pll.h"
131 #include "vlv_dsi_regs.h"
132 #include "vlv_sideband.h"
133
134 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state);
135 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
136 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state);
137 static void bdw_set_pipe_misc(struct intel_dsb *dsb,
138 const struct intel_crtc_state *crtc_state);
139
140 /* returns HPLL frequency in kHz */
vlv_get_hpll_vco(struct drm_i915_private * dev_priv)141 int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
142 {
143 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
144
145 /* Obtain SKU information */
146 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
147 CCK_FUSE_HPLL_FREQ_MASK;
148
149 return vco_freq[hpll_freq] * 1000;
150 }
151
vlv_get_cck_clock(struct drm_i915_private * dev_priv,const char * name,u32 reg,int ref_freq)152 int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
153 const char *name, u32 reg, int ref_freq)
154 {
155 u32 val;
156 int divider;
157
158 val = vlv_cck_read(dev_priv, reg);
159 divider = val & CCK_FREQUENCY_VALUES;
160
161 drm_WARN(&dev_priv->drm, (val & CCK_FREQUENCY_STATUS) !=
162 (divider << CCK_FREQUENCY_STATUS_SHIFT),
163 "%s change in progress\n", name);
164
165 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
166 }
167
vlv_get_cck_clock_hpll(struct drm_i915_private * dev_priv,const char * name,u32 reg)168 int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
169 const char *name, u32 reg)
170 {
171 int hpll;
172
173 vlv_cck_get(dev_priv);
174
175 if (dev_priv->hpll_freq == 0)
176 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
177
178 hpll = vlv_get_cck_clock(dev_priv, name, reg, dev_priv->hpll_freq);
179
180 vlv_cck_put(dev_priv);
181
182 return hpll;
183 }
184
intel_update_czclk(struct drm_i915_private * dev_priv)185 void intel_update_czclk(struct drm_i915_private *dev_priv)
186 {
187 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
188 return;
189
190 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
191 CCK_CZ_CLOCK_CONTROL);
192
193 drm_dbg(&dev_priv->drm, "CZ clock rate: %d kHz\n",
194 dev_priv->czclk_freq);
195 }
196
is_hdr_mode(const struct intel_crtc_state * crtc_state)197 static bool is_hdr_mode(const struct intel_crtc_state *crtc_state)
198 {
199 return (crtc_state->active_planes &
200 ~(icl_hdr_plane_mask() | BIT(PLANE_CURSOR))) == 0;
201 }
202
203 /* WA Display #0827: Gen9:all */
204 static void
skl_wa_827(struct drm_i915_private * dev_priv,enum pipe pipe,bool enable)205 skl_wa_827(struct drm_i915_private *dev_priv, enum pipe pipe, bool enable)
206 {
207 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
208 DUPS1_GATING_DIS | DUPS2_GATING_DIS,
209 enable ? DUPS1_GATING_DIS | DUPS2_GATING_DIS : 0);
210 }
211
212 /* Wa_2006604312:icl,ehl */
213 static void
icl_wa_scalerclkgating(struct drm_i915_private * dev_priv,enum pipe pipe,bool enable)214 icl_wa_scalerclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
215 bool enable)
216 {
217 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
218 DPFR_GATING_DIS,
219 enable ? DPFR_GATING_DIS : 0);
220 }
221
222 /* Wa_1604331009:icl,jsl,ehl */
223 static void
icl_wa_cursorclkgating(struct drm_i915_private * dev_priv,enum pipe pipe,bool enable)224 icl_wa_cursorclkgating(struct drm_i915_private *dev_priv, enum pipe pipe,
225 bool enable)
226 {
227 intel_de_rmw(dev_priv, CLKGATE_DIS_PSL(pipe),
228 CURSOR_GATING_DIS,
229 enable ? CURSOR_GATING_DIS : 0);
230 }
231
232 static bool
is_trans_port_sync_slave(const struct intel_crtc_state * crtc_state)233 is_trans_port_sync_slave(const struct intel_crtc_state *crtc_state)
234 {
235 return crtc_state->master_transcoder != INVALID_TRANSCODER;
236 }
237
238 bool
is_trans_port_sync_master(const struct intel_crtc_state * crtc_state)239 is_trans_port_sync_master(const struct intel_crtc_state *crtc_state)
240 {
241 return crtc_state->sync_mode_slaves_mask != 0;
242 }
243
244 bool
is_trans_port_sync_mode(const struct intel_crtc_state * crtc_state)245 is_trans_port_sync_mode(const struct intel_crtc_state *crtc_state)
246 {
247 return is_trans_port_sync_master(crtc_state) ||
248 is_trans_port_sync_slave(crtc_state);
249 }
250
joiner_primary_pipe(const struct intel_crtc_state * crtc_state)251 static enum pipe joiner_primary_pipe(const struct intel_crtc_state *crtc_state)
252 {
253 return ffs(crtc_state->joiner_pipes) - 1;
254 }
255
256 /*
257 * The following helper functions, despite being named for bigjoiner,
258 * are applicable to both bigjoiner and uncompressed joiner configurations.
259 */
is_bigjoiner(const struct intel_crtc_state * crtc_state)260 static bool is_bigjoiner(const struct intel_crtc_state *crtc_state)
261 {
262 return hweight8(crtc_state->joiner_pipes) >= 2;
263 }
264
bigjoiner_primary_pipes(const struct intel_crtc_state * crtc_state)265 static u8 bigjoiner_primary_pipes(const struct intel_crtc_state *crtc_state)
266 {
267 if (!is_bigjoiner(crtc_state))
268 return 0;
269
270 return crtc_state->joiner_pipes & (0b01010101 << joiner_primary_pipe(crtc_state));
271 }
272
bigjoiner_secondary_pipes(const struct intel_crtc_state * crtc_state)273 static unsigned int bigjoiner_secondary_pipes(const struct intel_crtc_state *crtc_state)
274 {
275 if (!is_bigjoiner(crtc_state))
276 return 0;
277
278 return crtc_state->joiner_pipes & (0b10101010 << joiner_primary_pipe(crtc_state));
279 }
280
intel_crtc_is_bigjoiner_primary(const struct intel_crtc_state * crtc_state)281 bool intel_crtc_is_bigjoiner_primary(const struct intel_crtc_state *crtc_state)
282 {
283 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
284
285 if (!is_bigjoiner(crtc_state))
286 return false;
287
288 return BIT(crtc->pipe) & bigjoiner_primary_pipes(crtc_state);
289 }
290
intel_crtc_is_bigjoiner_secondary(const struct intel_crtc_state * crtc_state)291 bool intel_crtc_is_bigjoiner_secondary(const struct intel_crtc_state *crtc_state)
292 {
293 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
294
295 if (!is_bigjoiner(crtc_state))
296 return false;
297
298 return BIT(crtc->pipe) & bigjoiner_secondary_pipes(crtc_state);
299 }
300
_intel_modeset_primary_pipes(const struct intel_crtc_state * crtc_state)301 u8 _intel_modeset_primary_pipes(const struct intel_crtc_state *crtc_state)
302 {
303 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
304
305 if (!is_bigjoiner(crtc_state))
306 return BIT(crtc->pipe);
307
308 return bigjoiner_primary_pipes(crtc_state);
309 }
310
_intel_modeset_secondary_pipes(const struct intel_crtc_state * crtc_state)311 u8 _intel_modeset_secondary_pipes(const struct intel_crtc_state *crtc_state)
312 {
313 return bigjoiner_secondary_pipes(crtc_state);
314 }
315
intel_crtc_is_ultrajoiner(const struct intel_crtc_state * crtc_state)316 bool intel_crtc_is_ultrajoiner(const struct intel_crtc_state *crtc_state)
317 {
318 return intel_crtc_num_joined_pipes(crtc_state) >= 4;
319 }
320
ultrajoiner_primary_pipes(const struct intel_crtc_state * crtc_state)321 static u8 ultrajoiner_primary_pipes(const struct intel_crtc_state *crtc_state)
322 {
323 if (!intel_crtc_is_ultrajoiner(crtc_state))
324 return 0;
325
326 return crtc_state->joiner_pipes & (0b00010001 << joiner_primary_pipe(crtc_state));
327 }
328
intel_crtc_is_ultrajoiner_primary(const struct intel_crtc_state * crtc_state)329 bool intel_crtc_is_ultrajoiner_primary(const struct intel_crtc_state *crtc_state)
330 {
331 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
332
333 return intel_crtc_is_ultrajoiner(crtc_state) &&
334 BIT(crtc->pipe) & ultrajoiner_primary_pipes(crtc_state);
335 }
336
337 /*
338 * The ultrajoiner enable bit doesn't seem to follow primary/secondary logic or
339 * any other logic, so lets just add helper function to
340 * at least hide this hassle..
341 */
ultrajoiner_enable_pipes(const struct intel_crtc_state * crtc_state)342 static u8 ultrajoiner_enable_pipes(const struct intel_crtc_state *crtc_state)
343 {
344 if (!intel_crtc_is_ultrajoiner(crtc_state))
345 return 0;
346
347 return crtc_state->joiner_pipes & (0b01110111 << joiner_primary_pipe(crtc_state));
348 }
349
intel_crtc_ultrajoiner_enable_needed(const struct intel_crtc_state * crtc_state)350 bool intel_crtc_ultrajoiner_enable_needed(const struct intel_crtc_state *crtc_state)
351 {
352 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
353
354 return intel_crtc_is_ultrajoiner(crtc_state) &&
355 BIT(crtc->pipe) & ultrajoiner_enable_pipes(crtc_state);
356 }
357
intel_crtc_joiner_secondary_pipes(const struct intel_crtc_state * crtc_state)358 u8 intel_crtc_joiner_secondary_pipes(const struct intel_crtc_state *crtc_state)
359 {
360 if (crtc_state->joiner_pipes)
361 return crtc_state->joiner_pipes & ~BIT(joiner_primary_pipe(crtc_state));
362 else
363 return 0;
364 }
365
intel_crtc_is_joiner_secondary(const struct intel_crtc_state * crtc_state)366 bool intel_crtc_is_joiner_secondary(const struct intel_crtc_state *crtc_state)
367 {
368 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
369
370 return crtc_state->joiner_pipes &&
371 crtc->pipe != joiner_primary_pipe(crtc_state);
372 }
373
intel_crtc_is_joiner_primary(const struct intel_crtc_state * crtc_state)374 bool intel_crtc_is_joiner_primary(const struct intel_crtc_state *crtc_state)
375 {
376 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
377
378 return crtc_state->joiner_pipes &&
379 crtc->pipe == joiner_primary_pipe(crtc_state);
380 }
381
intel_crtc_num_joined_pipes(const struct intel_crtc_state * crtc_state)382 int intel_crtc_num_joined_pipes(const struct intel_crtc_state *crtc_state)
383 {
384 return hweight8(intel_crtc_joined_pipe_mask(crtc_state));
385 }
386
intel_crtc_joined_pipe_mask(const struct intel_crtc_state * crtc_state)387 u8 intel_crtc_joined_pipe_mask(const struct intel_crtc_state *crtc_state)
388 {
389 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
390
391 return BIT(crtc->pipe) | crtc_state->joiner_pipes;
392 }
393
intel_primary_crtc(const struct intel_crtc_state * crtc_state)394 struct intel_crtc *intel_primary_crtc(const struct intel_crtc_state *crtc_state)
395 {
396 struct intel_display *display = to_intel_display(crtc_state);
397
398 if (intel_crtc_is_joiner_secondary(crtc_state))
399 return intel_crtc_for_pipe(display, joiner_primary_pipe(crtc_state));
400 else
401 return to_intel_crtc(crtc_state->uapi.crtc);
402 }
403
404 static void
intel_wait_for_pipe_off(const struct intel_crtc_state * old_crtc_state)405 intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
406 {
407 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
408 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
409
410 if (DISPLAY_VER(dev_priv) >= 4) {
411 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
412
413 /* Wait for the Pipe State to go off */
414 if (intel_de_wait_for_clear(dev_priv, TRANSCONF(dev_priv, cpu_transcoder),
415 TRANSCONF_STATE_ENABLE, 100))
416 drm_WARN(&dev_priv->drm, 1, "pipe_off wait timed out\n");
417 } else {
418 intel_wait_for_pipe_scanline_stopped(crtc);
419 }
420 }
421
assert_transcoder(struct drm_i915_private * dev_priv,enum transcoder cpu_transcoder,bool state)422 void assert_transcoder(struct drm_i915_private *dev_priv,
423 enum transcoder cpu_transcoder, bool state)
424 {
425 struct intel_display *display = &dev_priv->display;
426 bool cur_state;
427 enum intel_display_power_domain power_domain;
428 intel_wakeref_t wakeref;
429
430 /* we keep both pipes enabled on 830 */
431 if (IS_I830(dev_priv))
432 state = true;
433
434 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
435 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
436 if (wakeref) {
437 u32 val = intel_de_read(dev_priv,
438 TRANSCONF(dev_priv, cpu_transcoder));
439 cur_state = !!(val & TRANSCONF_ENABLE);
440
441 intel_display_power_put(dev_priv, power_domain, wakeref);
442 } else {
443 cur_state = false;
444 }
445
446 INTEL_DISPLAY_STATE_WARN(display, cur_state != state,
447 "transcoder %s assertion failure (expected %s, current %s)\n",
448 transcoder_name(cpu_transcoder), str_on_off(state),
449 str_on_off(cur_state));
450 }
451
assert_plane(struct intel_plane * plane,bool state)452 static void assert_plane(struct intel_plane *plane, bool state)
453 {
454 struct intel_display *display = to_intel_display(plane->base.dev);
455 enum pipe pipe;
456 bool cur_state;
457
458 cur_state = plane->get_hw_state(plane, &pipe);
459
460 INTEL_DISPLAY_STATE_WARN(display, cur_state != state,
461 "%s assertion failure (expected %s, current %s)\n",
462 plane->base.name, str_on_off(state),
463 str_on_off(cur_state));
464 }
465
466 #define assert_plane_enabled(p) assert_plane(p, true)
467 #define assert_plane_disabled(p) assert_plane(p, false)
468
assert_planes_disabled(struct intel_crtc * crtc)469 static void assert_planes_disabled(struct intel_crtc *crtc)
470 {
471 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
472 struct intel_plane *plane;
473
474 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
475 assert_plane_disabled(plane);
476 }
477
vlv_wait_port_ready(struct intel_display * display,struct intel_digital_port * dig_port,unsigned int expected_mask)478 void vlv_wait_port_ready(struct intel_display *display,
479 struct intel_digital_port *dig_port,
480 unsigned int expected_mask)
481 {
482 u32 port_mask;
483 i915_reg_t dpll_reg;
484
485 switch (dig_port->base.port) {
486 default:
487 MISSING_CASE(dig_port->base.port);
488 fallthrough;
489 case PORT_B:
490 port_mask = DPLL_PORTB_READY_MASK;
491 dpll_reg = DPLL(display, 0);
492 break;
493 case PORT_C:
494 port_mask = DPLL_PORTC_READY_MASK;
495 dpll_reg = DPLL(display, 0);
496 expected_mask <<= 4;
497 break;
498 case PORT_D:
499 port_mask = DPLL_PORTD_READY_MASK;
500 dpll_reg = DPIO_PHY_STATUS;
501 break;
502 }
503
504 if (intel_de_wait(display, dpll_reg, port_mask, expected_mask, 1000))
505 drm_WARN(display->drm, 1,
506 "timed out waiting for [ENCODER:%d:%s] port ready: got 0x%x, expected 0x%x\n",
507 dig_port->base.base.base.id, dig_port->base.base.name,
508 intel_de_read(display, dpll_reg) & port_mask,
509 expected_mask);
510 }
511
intel_enable_transcoder(const struct intel_crtc_state * new_crtc_state)512 void intel_enable_transcoder(const struct intel_crtc_state *new_crtc_state)
513 {
514 struct intel_display *display = to_intel_display(new_crtc_state);
515 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
516 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
517 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
518 enum pipe pipe = crtc->pipe;
519 u32 val;
520
521 drm_dbg_kms(&dev_priv->drm, "enabling pipe %c\n", pipe_name(pipe));
522
523 assert_planes_disabled(crtc);
524
525 /*
526 * A pipe without a PLL won't actually be able to drive bits from
527 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
528 * need the check.
529 */
530 if (HAS_GMCH(dev_priv)) {
531 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
532 assert_dsi_pll_enabled(dev_priv);
533 else
534 assert_pll_enabled(dev_priv, pipe);
535 } else {
536 if (new_crtc_state->has_pch_encoder) {
537 /* if driving the PCH, we need FDI enabled */
538 assert_fdi_rx_pll_enabled(dev_priv,
539 intel_crtc_pch_transcoder(crtc));
540 assert_fdi_tx_pll_enabled(dev_priv,
541 (enum pipe) cpu_transcoder);
542 }
543 /* FIXME: assert CPU port conditions for SNB+ */
544 }
545
546 /* Wa_22012358565:adl-p */
547 if (DISPLAY_VER(dev_priv) == 13)
548 intel_de_rmw(dev_priv, PIPE_ARB_CTL(dev_priv, pipe),
549 0, PIPE_ARB_USE_PROG_SLOTS);
550
551 if (DISPLAY_VER(dev_priv) >= 14) {
552 u32 clear = DP_DSC_INSERT_SF_AT_EOL_WA;
553 u32 set = 0;
554
555 if (DISPLAY_VER(dev_priv) == 14)
556 set |= DP_FEC_BS_JITTER_WA;
557
558 intel_de_rmw(display, CHICKEN_TRANS(display, cpu_transcoder),
559 clear, set);
560 }
561
562 val = intel_de_read(dev_priv, TRANSCONF(dev_priv, cpu_transcoder));
563 if (val & TRANSCONF_ENABLE) {
564 /* we keep both pipes enabled on 830 */
565 drm_WARN_ON(&dev_priv->drm, !IS_I830(dev_priv));
566 return;
567 }
568
569 /* Wa_1409098942:adlp+ */
570 if (DISPLAY_VER(dev_priv) >= 13 &&
571 new_crtc_state->dsc.compression_enable) {
572 val &= ~TRANSCONF_PIXEL_COUNT_SCALING_MASK;
573 val |= REG_FIELD_PREP(TRANSCONF_PIXEL_COUNT_SCALING_MASK,
574 TRANSCONF_PIXEL_COUNT_SCALING_X4);
575 }
576
577 intel_de_write(dev_priv, TRANSCONF(dev_priv, cpu_transcoder),
578 val | TRANSCONF_ENABLE);
579 intel_de_posting_read(dev_priv, TRANSCONF(dev_priv, cpu_transcoder));
580
581 /*
582 * Until the pipe starts PIPEDSL reads will return a stale value,
583 * which causes an apparent vblank timestamp jump when PIPEDSL
584 * resets to its proper value. That also messes up the frame count
585 * when it's derived from the timestamps. So let's wait for the
586 * pipe to start properly before we call drm_crtc_vblank_on()
587 */
588 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
589 intel_wait_for_pipe_scanline_moving(crtc);
590 }
591
intel_disable_transcoder(const struct intel_crtc_state * old_crtc_state)592 void intel_disable_transcoder(const struct intel_crtc_state *old_crtc_state)
593 {
594 struct intel_display *display = to_intel_display(old_crtc_state);
595 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
596 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
597 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
598 enum pipe pipe = crtc->pipe;
599 u32 val;
600
601 drm_dbg_kms(&dev_priv->drm, "disabling pipe %c\n", pipe_name(pipe));
602
603 /*
604 * Make sure planes won't keep trying to pump pixels to us,
605 * or we might hang the display.
606 */
607 assert_planes_disabled(crtc);
608
609 val = intel_de_read(dev_priv, TRANSCONF(dev_priv, cpu_transcoder));
610 if ((val & TRANSCONF_ENABLE) == 0)
611 return;
612
613 /*
614 * Double wide has implications for planes
615 * so best keep it disabled when not needed.
616 */
617 if (old_crtc_state->double_wide)
618 val &= ~TRANSCONF_DOUBLE_WIDE;
619
620 /* Don't disable pipe or pipe PLLs if needed */
621 if (!IS_I830(dev_priv))
622 val &= ~TRANSCONF_ENABLE;
623
624 /* Wa_1409098942:adlp+ */
625 if (DISPLAY_VER(dev_priv) >= 13 &&
626 old_crtc_state->dsc.compression_enable)
627 val &= ~TRANSCONF_PIXEL_COUNT_SCALING_MASK;
628
629 intel_de_write(dev_priv, TRANSCONF(dev_priv, cpu_transcoder), val);
630
631 if (DISPLAY_VER(dev_priv) >= 12)
632 intel_de_rmw(display, CHICKEN_TRANS(display, cpu_transcoder),
633 FECSTALL_DIS_DPTSTREAM_DPTTG, 0);
634
635 if ((val & TRANSCONF_ENABLE) == 0)
636 intel_wait_for_pipe_off(old_crtc_state);
637 }
638
intel_rotation_info_size(const struct intel_rotation_info * rot_info)639 unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
640 {
641 unsigned int size = 0;
642 int i;
643
644 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
645 size += rot_info->plane[i].dst_stride * rot_info->plane[i].width;
646
647 return size;
648 }
649
intel_remapped_info_size(const struct intel_remapped_info * rem_info)650 unsigned int intel_remapped_info_size(const struct intel_remapped_info *rem_info)
651 {
652 unsigned int size = 0;
653 int i;
654
655 for (i = 0 ; i < ARRAY_SIZE(rem_info->plane); i++) {
656 unsigned int plane_size;
657
658 if (rem_info->plane[i].linear)
659 plane_size = rem_info->plane[i].size;
660 else
661 plane_size = rem_info->plane[i].dst_stride * rem_info->plane[i].height;
662
663 if (plane_size == 0)
664 continue;
665
666 if (rem_info->plane_alignment)
667 size = ALIGN(size, rem_info->plane_alignment);
668
669 size += plane_size;
670 }
671
672 return size;
673 }
674
intel_plane_uses_fence(const struct intel_plane_state * plane_state)675 bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
676 {
677 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
678 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
679
680 return DISPLAY_VER(dev_priv) < 4 ||
681 (plane->fbc && !plane_state->no_fbc_reason &&
682 plane_state->view.gtt.type == I915_GTT_VIEW_NORMAL);
683 }
684
685 /*
686 * Convert the x/y offsets into a linear offset.
687 * Only valid with 0/180 degree rotation, which is fine since linear
688 * offset is only used with linear buffers on pre-hsw and tiled buffers
689 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
690 */
intel_fb_xy_to_linear(int x,int y,const struct intel_plane_state * state,int color_plane)691 u32 intel_fb_xy_to_linear(int x, int y,
692 const struct intel_plane_state *state,
693 int color_plane)
694 {
695 const struct drm_framebuffer *fb = state->hw.fb;
696 unsigned int cpp = fb->format->cpp[color_plane];
697 unsigned int pitch = state->view.color_plane[color_plane].mapping_stride;
698
699 return y * pitch + x * cpp;
700 }
701
702 /*
703 * Add the x/y offsets derived from fb->offsets[] to the user
704 * specified plane src x/y offsets. The resulting x/y offsets
705 * specify the start of scanout from the beginning of the gtt mapping.
706 */
intel_add_fb_offsets(int * x,int * y,const struct intel_plane_state * state,int color_plane)707 void intel_add_fb_offsets(int *x, int *y,
708 const struct intel_plane_state *state,
709 int color_plane)
710
711 {
712 *x += state->view.color_plane[color_plane].x;
713 *y += state->view.color_plane[color_plane].y;
714 }
715
intel_plane_fb_max_stride(struct drm_i915_private * dev_priv,u32 pixel_format,u64 modifier)716 u32 intel_plane_fb_max_stride(struct drm_i915_private *dev_priv,
717 u32 pixel_format, u64 modifier)
718 {
719 struct intel_crtc *crtc;
720 struct intel_plane *plane;
721
722 if (!HAS_DISPLAY(dev_priv))
723 return 0;
724
725 /*
726 * We assume the primary plane for pipe A has
727 * the highest stride limits of them all,
728 * if in case pipe A is disabled, use the first pipe from pipe_mask.
729 */
730 crtc = intel_first_crtc(dev_priv);
731 if (!crtc)
732 return 0;
733
734 plane = to_intel_plane(crtc->base.primary);
735
736 return plane->max_stride(plane, pixel_format, modifier,
737 DRM_MODE_ROTATE_0);
738 }
739
intel_set_plane_visible(struct intel_crtc_state * crtc_state,struct intel_plane_state * plane_state,bool visible)740 void intel_set_plane_visible(struct intel_crtc_state *crtc_state,
741 struct intel_plane_state *plane_state,
742 bool visible)
743 {
744 struct intel_plane *plane = to_intel_plane(plane_state->uapi.plane);
745
746 plane_state->uapi.visible = visible;
747
748 if (visible)
749 crtc_state->uapi.plane_mask |= drm_plane_mask(&plane->base);
750 else
751 crtc_state->uapi.plane_mask &= ~drm_plane_mask(&plane->base);
752 }
753
intel_plane_fixup_bitmasks(struct intel_crtc_state * crtc_state)754 void intel_plane_fixup_bitmasks(struct intel_crtc_state *crtc_state)
755 {
756 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
757 struct drm_plane *plane;
758
759 /*
760 * Active_planes aliases if multiple "primary" or cursor planes
761 * have been used on the same (or wrong) pipe. plane_mask uses
762 * unique ids, hence we can use that to reconstruct active_planes.
763 */
764 crtc_state->enabled_planes = 0;
765 crtc_state->active_planes = 0;
766
767 drm_for_each_plane_mask(plane, &dev_priv->drm,
768 crtc_state->uapi.plane_mask) {
769 crtc_state->enabled_planes |= BIT(to_intel_plane(plane)->id);
770 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
771 }
772 }
773
intel_plane_disable_noatomic(struct intel_crtc * crtc,struct intel_plane * plane)774 void intel_plane_disable_noatomic(struct intel_crtc *crtc,
775 struct intel_plane *plane)
776 {
777 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
778 struct intel_crtc_state *crtc_state =
779 to_intel_crtc_state(crtc->base.state);
780 struct intel_plane_state *plane_state =
781 to_intel_plane_state(plane->base.state);
782
783 drm_dbg_kms(&dev_priv->drm,
784 "Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
785 plane->base.base.id, plane->base.name,
786 crtc->base.base.id, crtc->base.name);
787
788 intel_set_plane_visible(crtc_state, plane_state, false);
789 intel_plane_fixup_bitmasks(crtc_state);
790 crtc_state->data_rate[plane->id] = 0;
791 crtc_state->data_rate_y[plane->id] = 0;
792 crtc_state->rel_data_rate[plane->id] = 0;
793 crtc_state->rel_data_rate_y[plane->id] = 0;
794 crtc_state->min_cdclk[plane->id] = 0;
795
796 if ((crtc_state->active_planes & ~BIT(PLANE_CURSOR)) == 0 &&
797 hsw_ips_disable(crtc_state)) {
798 crtc_state->ips_enabled = false;
799 intel_crtc_wait_for_next_vblank(crtc);
800 }
801
802 /*
803 * Vblank time updates from the shadow to live plane control register
804 * are blocked if the memory self-refresh mode is active at that
805 * moment. So to make sure the plane gets truly disabled, disable
806 * first the self-refresh mode. The self-refresh enable bit in turn
807 * will be checked/applied by the HW only at the next frame start
808 * event which is after the vblank start event, so we need to have a
809 * wait-for-vblank between disabling the plane and the pipe.
810 */
811 if (HAS_GMCH(dev_priv) &&
812 intel_set_memory_cxsr(dev_priv, false))
813 intel_crtc_wait_for_next_vblank(crtc);
814
815 /*
816 * Gen2 reports pipe underruns whenever all planes are disabled.
817 * So disable underrun reporting before all the planes get disabled.
818 */
819 if (DISPLAY_VER(dev_priv) == 2 && !crtc_state->active_planes)
820 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
821
822 intel_plane_disable_arm(NULL, plane, crtc_state);
823 intel_crtc_wait_for_next_vblank(crtc);
824 }
825
826 unsigned int
intel_plane_fence_y_offset(const struct intel_plane_state * plane_state)827 intel_plane_fence_y_offset(const struct intel_plane_state *plane_state)
828 {
829 int x = 0, y = 0;
830
831 intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
832 plane_state->view.color_plane[0].offset, 0);
833
834 return y;
835 }
836
icl_set_pipe_chicken(const struct intel_crtc_state * crtc_state)837 static void icl_set_pipe_chicken(const struct intel_crtc_state *crtc_state)
838 {
839 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
840 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
841 enum pipe pipe = crtc->pipe;
842 u32 tmp;
843
844 tmp = intel_de_read(dev_priv, PIPE_CHICKEN(pipe));
845
846 /*
847 * Display WA #1153: icl
848 * enable hardware to bypass the alpha math
849 * and rounding for per-pixel values 00 and 0xff
850 */
851 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
852 /*
853 * Display WA # 1605353570: icl
854 * Set the pixel rounding bit to 1 for allowing
855 * passthrough of Frame buffer pixels unmodified
856 * across pipe
857 */
858 tmp |= PIXEL_ROUNDING_TRUNC_FB_PASSTHRU;
859
860 /*
861 * Underrun recovery must always be disabled on display 13+.
862 * DG2 chicken bit meaning is inverted compared to other platforms.
863 */
864 if (IS_DG2(dev_priv))
865 tmp &= ~UNDERRUN_RECOVERY_ENABLE_DG2;
866 else if ((DISPLAY_VER(dev_priv) >= 13) && (DISPLAY_VER(dev_priv) < 30))
867 tmp |= UNDERRUN_RECOVERY_DISABLE_ADLP;
868
869 /* Wa_14010547955:dg2 */
870 if (IS_DG2(dev_priv))
871 tmp |= DG2_RENDER_CCSTAG_4_3_EN;
872
873 intel_de_write(dev_priv, PIPE_CHICKEN(pipe), tmp);
874 }
875
intel_has_pending_fb_unpin(struct drm_i915_private * dev_priv)876 bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
877 {
878 struct drm_crtc *crtc;
879 bool cleanup_done;
880
881 drm_for_each_crtc(crtc, &dev_priv->drm) {
882 struct drm_crtc_commit *commit;
883 spin_lock(&crtc->commit_lock);
884 commit = list_first_entry_or_null(&crtc->commit_list,
885 struct drm_crtc_commit, commit_entry);
886 cleanup_done = commit ?
887 try_wait_for_completion(&commit->cleanup_done) : true;
888 spin_unlock(&crtc->commit_lock);
889
890 if (cleanup_done)
891 continue;
892
893 intel_crtc_wait_for_next_vblank(to_intel_crtc(crtc));
894
895 return true;
896 }
897
898 return false;
899 }
900
901 /*
902 * Finds the encoder associated with the given CRTC. This can only be
903 * used when we know that the CRTC isn't feeding multiple encoders!
904 */
905 struct intel_encoder *
intel_get_crtc_new_encoder(const struct intel_atomic_state * state,const struct intel_crtc_state * crtc_state)906 intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
907 const struct intel_crtc_state *crtc_state)
908 {
909 const struct drm_connector_state *connector_state;
910 const struct drm_connector *connector;
911 struct intel_encoder *encoder = NULL;
912 struct intel_crtc *primary_crtc;
913 int num_encoders = 0;
914 int i;
915
916 primary_crtc = intel_primary_crtc(crtc_state);
917
918 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
919 if (connector_state->crtc != &primary_crtc->base)
920 continue;
921
922 encoder = to_intel_encoder(connector_state->best_encoder);
923 num_encoders++;
924 }
925
926 drm_WARN(state->base.dev, num_encoders != 1,
927 "%d encoders for pipe %c\n",
928 num_encoders, pipe_name(primary_crtc->pipe));
929
930 return encoder;
931 }
932
ilk_pfit_enable(const struct intel_crtc_state * crtc_state)933 static void ilk_pfit_enable(const struct intel_crtc_state *crtc_state)
934 {
935 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
936 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
937 const struct drm_rect *dst = &crtc_state->pch_pfit.dst;
938 enum pipe pipe = crtc->pipe;
939 int width = drm_rect_width(dst);
940 int height = drm_rect_height(dst);
941 int x = dst->x1;
942 int y = dst->y1;
943
944 if (!crtc_state->pch_pfit.enabled)
945 return;
946
947 /* Force use of hard-coded filter coefficients
948 * as some pre-programmed values are broken,
949 * e.g. x201.
950 */
951 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
952 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
953 PF_FILTER_MED_3x3 | PF_PIPE_SEL_IVB(pipe));
954 else
955 intel_de_write_fw(dev_priv, PF_CTL(pipe), PF_ENABLE |
956 PF_FILTER_MED_3x3);
957 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe),
958 PF_WIN_XPOS(x) | PF_WIN_YPOS(y));
959 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe),
960 PF_WIN_XSIZE(width) | PF_WIN_YSIZE(height));
961 }
962
intel_crtc_dpms_overlay_disable(struct intel_crtc * crtc)963 static void intel_crtc_dpms_overlay_disable(struct intel_crtc *crtc)
964 {
965 if (crtc->overlay)
966 (void) intel_overlay_switch_off(crtc->overlay);
967
968 /* Let userspace switch the overlay on again. In most cases userspace
969 * has to recompute where to put it anyway.
970 */
971 }
972
needs_nv12_wa(const struct intel_crtc_state * crtc_state)973 static bool needs_nv12_wa(const struct intel_crtc_state *crtc_state)
974 {
975 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
976
977 if (!crtc_state->nv12_planes)
978 return false;
979
980 /* WA Display #0827: Gen9:all */
981 if (DISPLAY_VER(dev_priv) == 9)
982 return true;
983
984 return false;
985 }
986
needs_scalerclk_wa(const struct intel_crtc_state * crtc_state)987 static bool needs_scalerclk_wa(const struct intel_crtc_state *crtc_state)
988 {
989 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
990
991 /* Wa_2006604312:icl,ehl */
992 if (crtc_state->scaler_state.scaler_users > 0 && DISPLAY_VER(dev_priv) == 11)
993 return true;
994
995 return false;
996 }
997
needs_cursorclk_wa(const struct intel_crtc_state * crtc_state)998 static bool needs_cursorclk_wa(const struct intel_crtc_state *crtc_state)
999 {
1000 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
1001
1002 /* Wa_1604331009:icl,jsl,ehl */
1003 if (is_hdr_mode(crtc_state) &&
1004 crtc_state->active_planes & BIT(PLANE_CURSOR) &&
1005 DISPLAY_VER(dev_priv) == 11)
1006 return true;
1007
1008 return false;
1009 }
1010
intel_async_flip_vtd_wa(struct drm_i915_private * i915,enum pipe pipe,bool enable)1011 static void intel_async_flip_vtd_wa(struct drm_i915_private *i915,
1012 enum pipe pipe, bool enable)
1013 {
1014 if (DISPLAY_VER(i915) == 9) {
1015 /*
1016 * "Plane N strech max must be programmed to 11b (x1)
1017 * when Async flips are enabled on that plane."
1018 */
1019 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
1020 SKL_PLANE1_STRETCH_MAX_MASK,
1021 enable ? SKL_PLANE1_STRETCH_MAX_X1 : SKL_PLANE1_STRETCH_MAX_X8);
1022 } else {
1023 /* Also needed on HSW/BDW albeit undocumented */
1024 intel_de_rmw(i915, CHICKEN_PIPESL_1(pipe),
1025 HSW_PRI_STRETCH_MAX_MASK,
1026 enable ? HSW_PRI_STRETCH_MAX_X1 : HSW_PRI_STRETCH_MAX_X8);
1027 }
1028 }
1029
needs_async_flip_vtd_wa(const struct intel_crtc_state * crtc_state)1030 static bool needs_async_flip_vtd_wa(const struct intel_crtc_state *crtc_state)
1031 {
1032 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
1033
1034 return crtc_state->uapi.async_flip && i915_vtd_active(i915) &&
1035 (DISPLAY_VER(i915) == 9 || IS_BROADWELL(i915) || IS_HASWELL(i915));
1036 }
1037
intel_encoders_audio_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1038 static void intel_encoders_audio_enable(struct intel_atomic_state *state,
1039 struct intel_crtc *crtc)
1040 {
1041 const struct intel_crtc_state *crtc_state =
1042 intel_atomic_get_new_crtc_state(state, crtc);
1043 const struct drm_connector_state *conn_state;
1044 struct drm_connector *conn;
1045 int i;
1046
1047 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1048 struct intel_encoder *encoder =
1049 to_intel_encoder(conn_state->best_encoder);
1050
1051 if (conn_state->crtc != &crtc->base)
1052 continue;
1053
1054 if (encoder->audio_enable)
1055 encoder->audio_enable(encoder, crtc_state, conn_state);
1056 }
1057 }
1058
intel_encoders_audio_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1059 static void intel_encoders_audio_disable(struct intel_atomic_state *state,
1060 struct intel_crtc *crtc)
1061 {
1062 const struct intel_crtc_state *old_crtc_state =
1063 intel_atomic_get_old_crtc_state(state, crtc);
1064 const struct drm_connector_state *old_conn_state;
1065 struct drm_connector *conn;
1066 int i;
1067
1068 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1069 struct intel_encoder *encoder =
1070 to_intel_encoder(old_conn_state->best_encoder);
1071
1072 if (old_conn_state->crtc != &crtc->base)
1073 continue;
1074
1075 if (encoder->audio_disable)
1076 encoder->audio_disable(encoder, old_crtc_state, old_conn_state);
1077 }
1078 }
1079
1080 #define is_enabling(feature, old_crtc_state, new_crtc_state) \
1081 ((!(old_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)) && \
1082 (new_crtc_state)->feature)
1083 #define is_disabling(feature, old_crtc_state, new_crtc_state) \
1084 ((old_crtc_state)->feature && \
1085 (!(new_crtc_state)->feature || intel_crtc_needs_modeset(new_crtc_state)))
1086
planes_enabling(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)1087 static bool planes_enabling(const struct intel_crtc_state *old_crtc_state,
1088 const struct intel_crtc_state *new_crtc_state)
1089 {
1090 if (!new_crtc_state->hw.active)
1091 return false;
1092
1093 return is_enabling(active_planes, old_crtc_state, new_crtc_state);
1094 }
1095
planes_disabling(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)1096 static bool planes_disabling(const struct intel_crtc_state *old_crtc_state,
1097 const struct intel_crtc_state *new_crtc_state)
1098 {
1099 if (!old_crtc_state->hw.active)
1100 return false;
1101
1102 return is_disabling(active_planes, old_crtc_state, new_crtc_state);
1103 }
1104
vrr_params_changed(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)1105 static bool vrr_params_changed(const struct intel_crtc_state *old_crtc_state,
1106 const struct intel_crtc_state *new_crtc_state)
1107 {
1108 return old_crtc_state->vrr.flipline != new_crtc_state->vrr.flipline ||
1109 old_crtc_state->vrr.vmin != new_crtc_state->vrr.vmin ||
1110 old_crtc_state->vrr.vmax != new_crtc_state->vrr.vmax ||
1111 old_crtc_state->vrr.guardband != new_crtc_state->vrr.guardband ||
1112 old_crtc_state->vrr.pipeline_full != new_crtc_state->vrr.pipeline_full ||
1113 old_crtc_state->vrr.vsync_start != new_crtc_state->vrr.vsync_start ||
1114 old_crtc_state->vrr.vsync_end != new_crtc_state->vrr.vsync_end;
1115 }
1116
cmrr_params_changed(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)1117 static bool cmrr_params_changed(const struct intel_crtc_state *old_crtc_state,
1118 const struct intel_crtc_state *new_crtc_state)
1119 {
1120 return old_crtc_state->cmrr.cmrr_m != new_crtc_state->cmrr.cmrr_m ||
1121 old_crtc_state->cmrr.cmrr_n != new_crtc_state->cmrr.cmrr_n;
1122 }
1123
intel_crtc_vrr_enabling(struct intel_atomic_state * state,struct intel_crtc * crtc)1124 static bool intel_crtc_vrr_enabling(struct intel_atomic_state *state,
1125 struct intel_crtc *crtc)
1126 {
1127 const struct intel_crtc_state *old_crtc_state =
1128 intel_atomic_get_old_crtc_state(state, crtc);
1129 const struct intel_crtc_state *new_crtc_state =
1130 intel_atomic_get_new_crtc_state(state, crtc);
1131
1132 if (!new_crtc_state->hw.active)
1133 return false;
1134
1135 return is_enabling(vrr.enable, old_crtc_state, new_crtc_state) ||
1136 (new_crtc_state->vrr.enable &&
1137 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
1138 vrr_params_changed(old_crtc_state, new_crtc_state)));
1139 }
1140
intel_crtc_vrr_disabling(struct intel_atomic_state * state,struct intel_crtc * crtc)1141 bool intel_crtc_vrr_disabling(struct intel_atomic_state *state,
1142 struct intel_crtc *crtc)
1143 {
1144 const struct intel_crtc_state *old_crtc_state =
1145 intel_atomic_get_old_crtc_state(state, crtc);
1146 const struct intel_crtc_state *new_crtc_state =
1147 intel_atomic_get_new_crtc_state(state, crtc);
1148
1149 if (!old_crtc_state->hw.active)
1150 return false;
1151
1152 return is_disabling(vrr.enable, old_crtc_state, new_crtc_state) ||
1153 (old_crtc_state->vrr.enable &&
1154 (new_crtc_state->update_m_n || new_crtc_state->update_lrr ||
1155 vrr_params_changed(old_crtc_state, new_crtc_state)));
1156 }
1157
audio_enabling(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)1158 static bool audio_enabling(const struct intel_crtc_state *old_crtc_state,
1159 const struct intel_crtc_state *new_crtc_state)
1160 {
1161 if (!new_crtc_state->hw.active)
1162 return false;
1163
1164 return is_enabling(has_audio, old_crtc_state, new_crtc_state) ||
1165 (new_crtc_state->has_audio &&
1166 memcmp(old_crtc_state->eld, new_crtc_state->eld, MAX_ELD_BYTES) != 0);
1167 }
1168
audio_disabling(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)1169 static bool audio_disabling(const struct intel_crtc_state *old_crtc_state,
1170 const struct intel_crtc_state *new_crtc_state)
1171 {
1172 if (!old_crtc_state->hw.active)
1173 return false;
1174
1175 return is_disabling(has_audio, old_crtc_state, new_crtc_state) ||
1176 (old_crtc_state->has_audio &&
1177 memcmp(old_crtc_state->eld, new_crtc_state->eld, MAX_ELD_BYTES) != 0);
1178 }
1179
1180 #undef is_disabling
1181 #undef is_enabling
1182
intel_post_plane_update(struct intel_atomic_state * state,struct intel_crtc * crtc)1183 static void intel_post_plane_update(struct intel_atomic_state *state,
1184 struct intel_crtc *crtc)
1185 {
1186 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1187 const struct intel_crtc_state *old_crtc_state =
1188 intel_atomic_get_old_crtc_state(state, crtc);
1189 const struct intel_crtc_state *new_crtc_state =
1190 intel_atomic_get_new_crtc_state(state, crtc);
1191 enum pipe pipe = crtc->pipe;
1192
1193 intel_psr_post_plane_update(state, crtc);
1194
1195 intel_frontbuffer_flip(dev_priv, new_crtc_state->fb_bits);
1196
1197 if (new_crtc_state->update_wm_post && new_crtc_state->hw.active)
1198 intel_update_watermarks(dev_priv);
1199
1200 intel_fbc_post_update(state, crtc);
1201
1202 if (needs_async_flip_vtd_wa(old_crtc_state) &&
1203 !needs_async_flip_vtd_wa(new_crtc_state))
1204 intel_async_flip_vtd_wa(dev_priv, pipe, false);
1205
1206 if (needs_nv12_wa(old_crtc_state) &&
1207 !needs_nv12_wa(new_crtc_state))
1208 skl_wa_827(dev_priv, pipe, false);
1209
1210 if (needs_scalerclk_wa(old_crtc_state) &&
1211 !needs_scalerclk_wa(new_crtc_state))
1212 icl_wa_scalerclkgating(dev_priv, pipe, false);
1213
1214 if (needs_cursorclk_wa(old_crtc_state) &&
1215 !needs_cursorclk_wa(new_crtc_state))
1216 icl_wa_cursorclkgating(dev_priv, pipe, false);
1217
1218 if (intel_crtc_needs_color_update(new_crtc_state))
1219 intel_color_post_update(new_crtc_state);
1220
1221 if (audio_enabling(old_crtc_state, new_crtc_state))
1222 intel_encoders_audio_enable(state, crtc);
1223 }
1224
intel_post_plane_update_after_readout(struct intel_atomic_state * state,struct intel_crtc * crtc)1225 static void intel_post_plane_update_after_readout(struct intel_atomic_state *state,
1226 struct intel_crtc *crtc)
1227 {
1228 const struct intel_crtc_state *new_crtc_state =
1229 intel_atomic_get_new_crtc_state(state, crtc);
1230
1231 /* Must be done after gamma readout due to HSW split gamma vs. IPS w/a */
1232 hsw_ips_post_update(state, crtc);
1233
1234 /*
1235 * Activate DRRS after state readout to avoid
1236 * dp_m_n vs. dp_m2_n2 confusion on BDW+.
1237 */
1238 intel_drrs_activate(new_crtc_state);
1239 }
1240
intel_crtc_enable_flip_done(struct intel_atomic_state * state,struct intel_crtc * crtc)1241 static void intel_crtc_enable_flip_done(struct intel_atomic_state *state,
1242 struct intel_crtc *crtc)
1243 {
1244 const struct intel_crtc_state *crtc_state =
1245 intel_atomic_get_new_crtc_state(state, crtc);
1246 u8 update_planes = crtc_state->update_planes;
1247 const struct intel_plane_state __maybe_unused *plane_state;
1248 struct intel_plane *plane;
1249 int i;
1250
1251 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1252 if (plane->pipe == crtc->pipe &&
1253 update_planes & BIT(plane->id))
1254 plane->enable_flip_done(plane);
1255 }
1256 }
1257
intel_crtc_disable_flip_done(struct intel_atomic_state * state,struct intel_crtc * crtc)1258 static void intel_crtc_disable_flip_done(struct intel_atomic_state *state,
1259 struct intel_crtc *crtc)
1260 {
1261 const struct intel_crtc_state *crtc_state =
1262 intel_atomic_get_new_crtc_state(state, crtc);
1263 u8 update_planes = crtc_state->update_planes;
1264 const struct intel_plane_state __maybe_unused *plane_state;
1265 struct intel_plane *plane;
1266 int i;
1267
1268 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
1269 if (plane->pipe == crtc->pipe &&
1270 update_planes & BIT(plane->id))
1271 plane->disable_flip_done(plane);
1272 }
1273 }
1274
intel_crtc_async_flip_disable_wa(struct intel_atomic_state * state,struct intel_crtc * crtc)1275 static void intel_crtc_async_flip_disable_wa(struct intel_atomic_state *state,
1276 struct intel_crtc *crtc)
1277 {
1278 const struct intel_crtc_state *old_crtc_state =
1279 intel_atomic_get_old_crtc_state(state, crtc);
1280 const struct intel_crtc_state *new_crtc_state =
1281 intel_atomic_get_new_crtc_state(state, crtc);
1282 u8 disable_async_flip_planes = old_crtc_state->async_flip_planes &
1283 ~new_crtc_state->async_flip_planes;
1284 const struct intel_plane_state *old_plane_state;
1285 struct intel_plane *plane;
1286 bool need_vbl_wait = false;
1287 int i;
1288
1289 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1290 if (plane->need_async_flip_toggle_wa &&
1291 plane->pipe == crtc->pipe &&
1292 disable_async_flip_planes & BIT(plane->id)) {
1293 /*
1294 * Apart from the async flip bit we want to
1295 * preserve the old state for the plane.
1296 */
1297 intel_plane_async_flip(NULL, plane,
1298 old_crtc_state, old_plane_state, false);
1299 need_vbl_wait = true;
1300 }
1301 }
1302
1303 if (need_vbl_wait)
1304 intel_crtc_wait_for_next_vblank(crtc);
1305 }
1306
intel_pre_plane_update(struct intel_atomic_state * state,struct intel_crtc * crtc)1307 static void intel_pre_plane_update(struct intel_atomic_state *state,
1308 struct intel_crtc *crtc)
1309 {
1310 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
1311 const struct intel_crtc_state *old_crtc_state =
1312 intel_atomic_get_old_crtc_state(state, crtc);
1313 const struct intel_crtc_state *new_crtc_state =
1314 intel_atomic_get_new_crtc_state(state, crtc);
1315 enum pipe pipe = crtc->pipe;
1316
1317 if (intel_crtc_vrr_disabling(state, crtc)) {
1318 intel_vrr_disable(old_crtc_state);
1319 intel_crtc_update_active_timings(old_crtc_state, false);
1320 }
1321
1322 if (audio_disabling(old_crtc_state, new_crtc_state))
1323 intel_encoders_audio_disable(state, crtc);
1324
1325 intel_drrs_deactivate(old_crtc_state);
1326
1327 intel_psr_pre_plane_update(state, crtc);
1328
1329 if (hsw_ips_pre_update(state, crtc))
1330 intel_crtc_wait_for_next_vblank(crtc);
1331
1332 if (intel_fbc_pre_update(state, crtc))
1333 intel_crtc_wait_for_next_vblank(crtc);
1334
1335 if (!needs_async_flip_vtd_wa(old_crtc_state) &&
1336 needs_async_flip_vtd_wa(new_crtc_state))
1337 intel_async_flip_vtd_wa(dev_priv, pipe, true);
1338
1339 /* Display WA 827 */
1340 if (!needs_nv12_wa(old_crtc_state) &&
1341 needs_nv12_wa(new_crtc_state))
1342 skl_wa_827(dev_priv, pipe, true);
1343
1344 /* Wa_2006604312:icl,ehl */
1345 if (!needs_scalerclk_wa(old_crtc_state) &&
1346 needs_scalerclk_wa(new_crtc_state))
1347 icl_wa_scalerclkgating(dev_priv, pipe, true);
1348
1349 /* Wa_1604331009:icl,jsl,ehl */
1350 if (!needs_cursorclk_wa(old_crtc_state) &&
1351 needs_cursorclk_wa(new_crtc_state))
1352 icl_wa_cursorclkgating(dev_priv, pipe, true);
1353
1354 /*
1355 * Vblank time updates from the shadow to live plane control register
1356 * are blocked if the memory self-refresh mode is active at that
1357 * moment. So to make sure the plane gets truly disabled, disable
1358 * first the self-refresh mode. The self-refresh enable bit in turn
1359 * will be checked/applied by the HW only at the next frame start
1360 * event which is after the vblank start event, so we need to have a
1361 * wait-for-vblank between disabling the plane and the pipe.
1362 */
1363 if (HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
1364 new_crtc_state->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
1365 intel_crtc_wait_for_next_vblank(crtc);
1366
1367 /*
1368 * IVB workaround: must disable low power watermarks for at least
1369 * one frame before enabling scaling. LP watermarks can be re-enabled
1370 * when scaling is disabled.
1371 *
1372 * WaCxSRDisabledForSpriteScaling:ivb
1373 */
1374 if (!HAS_GMCH(dev_priv) && old_crtc_state->hw.active &&
1375 new_crtc_state->disable_cxsr && ilk_disable_cxsr(dev_priv))
1376 intel_crtc_wait_for_next_vblank(crtc);
1377
1378 /*
1379 * If we're doing a modeset we don't need to do any
1380 * pre-vblank watermark programming here.
1381 */
1382 if (!intel_crtc_needs_modeset(new_crtc_state)) {
1383 /*
1384 * For platforms that support atomic watermarks, program the
1385 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
1386 * will be the intermediate values that are safe for both pre- and
1387 * post- vblank; when vblank happens, the 'active' values will be set
1388 * to the final 'target' values and we'll do this again to get the
1389 * optimal watermarks. For gen9+ platforms, the values we program here
1390 * will be the final target values which will get automatically latched
1391 * at vblank time; no further programming will be necessary.
1392 *
1393 * If a platform hasn't been transitioned to atomic watermarks yet,
1394 * we'll continue to update watermarks the old way, if flags tell
1395 * us to.
1396 */
1397 if (!intel_initial_watermarks(state, crtc))
1398 if (new_crtc_state->update_wm_pre)
1399 intel_update_watermarks(dev_priv);
1400 }
1401
1402 /*
1403 * Gen2 reports pipe underruns whenever all planes are disabled.
1404 * So disable underrun reporting before all the planes get disabled.
1405 *
1406 * We do this after .initial_watermarks() so that we have a
1407 * chance of catching underruns with the intermediate watermarks
1408 * vs. the old plane configuration.
1409 */
1410 if (DISPLAY_VER(dev_priv) == 2 && planes_disabling(old_crtc_state, new_crtc_state))
1411 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1412
1413 /*
1414 * WA for platforms where async address update enable bit
1415 * is double buffered and only latched at start of vblank.
1416 */
1417 if (old_crtc_state->async_flip_planes & ~new_crtc_state->async_flip_planes)
1418 intel_crtc_async_flip_disable_wa(state, crtc);
1419 }
1420
intel_crtc_disable_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)1421 static void intel_crtc_disable_planes(struct intel_atomic_state *state,
1422 struct intel_crtc *crtc)
1423 {
1424 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1425 const struct intel_crtc_state *new_crtc_state =
1426 intel_atomic_get_new_crtc_state(state, crtc);
1427 unsigned int update_mask = new_crtc_state->update_planes;
1428 const struct intel_plane_state *old_plane_state;
1429 struct intel_plane *plane;
1430 unsigned fb_bits = 0;
1431 int i;
1432
1433 intel_crtc_dpms_overlay_disable(crtc);
1434
1435 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
1436 if (crtc->pipe != plane->pipe ||
1437 !(update_mask & BIT(plane->id)))
1438 continue;
1439
1440 intel_plane_disable_arm(NULL, plane, new_crtc_state);
1441
1442 if (old_plane_state->uapi.visible)
1443 fb_bits |= plane->frontbuffer_bit;
1444 }
1445
1446 intel_frontbuffer_flip(dev_priv, fb_bits);
1447 }
1448
intel_encoders_update_prepare(struct intel_atomic_state * state)1449 static void intel_encoders_update_prepare(struct intel_atomic_state *state)
1450 {
1451 struct drm_i915_private *i915 = to_i915(state->base.dev);
1452 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
1453 struct intel_crtc *crtc;
1454 int i;
1455
1456 /*
1457 * Make sure the DPLL state is up-to-date for fastset TypeC ports after non-blocking commits.
1458 * TODO: Update the DPLL state for all cases in the encoder->update_prepare() hook.
1459 */
1460 if (i915->display.dpll.mgr) {
1461 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1462 if (intel_crtc_needs_modeset(new_crtc_state))
1463 continue;
1464
1465 new_crtc_state->shared_dpll = old_crtc_state->shared_dpll;
1466 new_crtc_state->dpll_hw_state = old_crtc_state->dpll_hw_state;
1467 }
1468 }
1469 }
1470
intel_encoders_pre_pll_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1471 static void intel_encoders_pre_pll_enable(struct intel_atomic_state *state,
1472 struct intel_crtc *crtc)
1473 {
1474 const struct intel_crtc_state *crtc_state =
1475 intel_atomic_get_new_crtc_state(state, crtc);
1476 const struct drm_connector_state *conn_state;
1477 struct drm_connector *conn;
1478 int i;
1479
1480 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1481 struct intel_encoder *encoder =
1482 to_intel_encoder(conn_state->best_encoder);
1483
1484 if (conn_state->crtc != &crtc->base)
1485 continue;
1486
1487 if (encoder->pre_pll_enable)
1488 encoder->pre_pll_enable(state, encoder,
1489 crtc_state, conn_state);
1490 }
1491 }
1492
intel_encoders_pre_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1493 static void intel_encoders_pre_enable(struct intel_atomic_state *state,
1494 struct intel_crtc *crtc)
1495 {
1496 const struct intel_crtc_state *crtc_state =
1497 intel_atomic_get_new_crtc_state(state, crtc);
1498 const struct drm_connector_state *conn_state;
1499 struct drm_connector *conn;
1500 int i;
1501
1502 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1503 struct intel_encoder *encoder =
1504 to_intel_encoder(conn_state->best_encoder);
1505
1506 if (conn_state->crtc != &crtc->base)
1507 continue;
1508
1509 if (encoder->pre_enable)
1510 encoder->pre_enable(state, encoder,
1511 crtc_state, conn_state);
1512 }
1513 }
1514
intel_encoders_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1515 static void intel_encoders_enable(struct intel_atomic_state *state,
1516 struct intel_crtc *crtc)
1517 {
1518 const struct intel_crtc_state *crtc_state =
1519 intel_atomic_get_new_crtc_state(state, crtc);
1520 const struct drm_connector_state *conn_state;
1521 struct drm_connector *conn;
1522 int i;
1523
1524 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1525 struct intel_encoder *encoder =
1526 to_intel_encoder(conn_state->best_encoder);
1527
1528 if (conn_state->crtc != &crtc->base)
1529 continue;
1530
1531 if (encoder->enable)
1532 encoder->enable(state, encoder,
1533 crtc_state, conn_state);
1534 intel_opregion_notify_encoder(encoder, true);
1535 }
1536 }
1537
intel_encoders_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1538 static void intel_encoders_disable(struct intel_atomic_state *state,
1539 struct intel_crtc *crtc)
1540 {
1541 const struct intel_crtc_state *old_crtc_state =
1542 intel_atomic_get_old_crtc_state(state, crtc);
1543 const struct drm_connector_state *old_conn_state;
1544 struct drm_connector *conn;
1545 int i;
1546
1547 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1548 struct intel_encoder *encoder =
1549 to_intel_encoder(old_conn_state->best_encoder);
1550
1551 if (old_conn_state->crtc != &crtc->base)
1552 continue;
1553
1554 intel_opregion_notify_encoder(encoder, false);
1555 if (encoder->disable)
1556 encoder->disable(state, encoder,
1557 old_crtc_state, old_conn_state);
1558 }
1559 }
1560
intel_encoders_post_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1561 static void intel_encoders_post_disable(struct intel_atomic_state *state,
1562 struct intel_crtc *crtc)
1563 {
1564 const struct intel_crtc_state *old_crtc_state =
1565 intel_atomic_get_old_crtc_state(state, crtc);
1566 const struct drm_connector_state *old_conn_state;
1567 struct drm_connector *conn;
1568 int i;
1569
1570 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1571 struct intel_encoder *encoder =
1572 to_intel_encoder(old_conn_state->best_encoder);
1573
1574 if (old_conn_state->crtc != &crtc->base)
1575 continue;
1576
1577 if (encoder->post_disable)
1578 encoder->post_disable(state, encoder,
1579 old_crtc_state, old_conn_state);
1580 }
1581 }
1582
intel_encoders_post_pll_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1583 static void intel_encoders_post_pll_disable(struct intel_atomic_state *state,
1584 struct intel_crtc *crtc)
1585 {
1586 const struct intel_crtc_state *old_crtc_state =
1587 intel_atomic_get_old_crtc_state(state, crtc);
1588 const struct drm_connector_state *old_conn_state;
1589 struct drm_connector *conn;
1590 int i;
1591
1592 for_each_old_connector_in_state(&state->base, conn, old_conn_state, i) {
1593 struct intel_encoder *encoder =
1594 to_intel_encoder(old_conn_state->best_encoder);
1595
1596 if (old_conn_state->crtc != &crtc->base)
1597 continue;
1598
1599 if (encoder->post_pll_disable)
1600 encoder->post_pll_disable(state, encoder,
1601 old_crtc_state, old_conn_state);
1602 }
1603 }
1604
intel_encoders_update_pipe(struct intel_atomic_state * state,struct intel_crtc * crtc)1605 static void intel_encoders_update_pipe(struct intel_atomic_state *state,
1606 struct intel_crtc *crtc)
1607 {
1608 const struct intel_crtc_state *crtc_state =
1609 intel_atomic_get_new_crtc_state(state, crtc);
1610 const struct drm_connector_state *conn_state;
1611 struct drm_connector *conn;
1612 int i;
1613
1614 for_each_new_connector_in_state(&state->base, conn, conn_state, i) {
1615 struct intel_encoder *encoder =
1616 to_intel_encoder(conn_state->best_encoder);
1617
1618 if (conn_state->crtc != &crtc->base)
1619 continue;
1620
1621 if (encoder->update_pipe)
1622 encoder->update_pipe(state, encoder,
1623 crtc_state, conn_state);
1624 }
1625 }
1626
ilk_configure_cpu_transcoder(const struct intel_crtc_state * crtc_state)1627 static void ilk_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1628 {
1629 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1630 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1631
1632 if (crtc_state->has_pch_encoder) {
1633 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1634 &crtc_state->fdi_m_n);
1635 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1636 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1637 &crtc_state->dp_m_n);
1638 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1639 &crtc_state->dp_m2_n2);
1640 }
1641
1642 intel_set_transcoder_timings(crtc_state);
1643
1644 ilk_set_pipeconf(crtc_state);
1645 }
1646
ilk_crtc_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1647 static void ilk_crtc_enable(struct intel_atomic_state *state,
1648 struct intel_crtc *crtc)
1649 {
1650 const struct intel_crtc_state *new_crtc_state =
1651 intel_atomic_get_new_crtc_state(state, crtc);
1652 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1653 enum pipe pipe = crtc->pipe;
1654
1655 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1656 return;
1657
1658 /*
1659 * Sometimes spurious CPU pipe underruns happen during FDI
1660 * training, at least with VGA+HDMI cloning. Suppress them.
1661 *
1662 * On ILK we get an occasional spurious CPU pipe underruns
1663 * between eDP port A enable and vdd enable. Also PCH port
1664 * enable seems to result in the occasional CPU pipe underrun.
1665 *
1666 * Spurious PCH underruns also occur during PCH enabling.
1667 */
1668 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1669 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1670
1671 ilk_configure_cpu_transcoder(new_crtc_state);
1672
1673 intel_set_pipe_src_size(new_crtc_state);
1674
1675 crtc->active = true;
1676
1677 intel_encoders_pre_enable(state, crtc);
1678
1679 if (new_crtc_state->has_pch_encoder) {
1680 ilk_pch_pre_enable(state, crtc);
1681 } else {
1682 assert_fdi_tx_disabled(dev_priv, pipe);
1683 assert_fdi_rx_disabled(dev_priv, pipe);
1684 }
1685
1686 ilk_pfit_enable(new_crtc_state);
1687
1688 /*
1689 * On ILK+ LUT must be loaded before the pipe is running but with
1690 * clocks enabled
1691 */
1692 intel_color_modeset(new_crtc_state);
1693
1694 intel_initial_watermarks(state, crtc);
1695 intel_enable_transcoder(new_crtc_state);
1696
1697 if (new_crtc_state->has_pch_encoder)
1698 ilk_pch_enable(state, crtc);
1699
1700 intel_crtc_vblank_on(new_crtc_state);
1701
1702 intel_encoders_enable(state, crtc);
1703
1704 if (HAS_PCH_CPT(dev_priv))
1705 intel_wait_for_pipe_scanline_moving(crtc);
1706
1707 /*
1708 * Must wait for vblank to avoid spurious PCH FIFO underruns.
1709 * And a second vblank wait is needed at least on ILK with
1710 * some interlaced HDMI modes. Let's do the double wait always
1711 * in case there are more corner cases we don't know about.
1712 */
1713 if (new_crtc_state->has_pch_encoder) {
1714 intel_crtc_wait_for_next_vblank(crtc);
1715 intel_crtc_wait_for_next_vblank(crtc);
1716 }
1717 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1718 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1719 }
1720
1721 /* Display WA #1180: WaDisableScalarClockGating: glk */
glk_need_scaler_clock_gating_wa(const struct intel_crtc_state * crtc_state)1722 static bool glk_need_scaler_clock_gating_wa(const struct intel_crtc_state *crtc_state)
1723 {
1724 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
1725
1726 return DISPLAY_VER(i915) == 10 && crtc_state->pch_pfit.enabled;
1727 }
1728
glk_pipe_scaler_clock_gating_wa(struct intel_crtc * crtc,bool enable)1729 static void glk_pipe_scaler_clock_gating_wa(struct intel_crtc *crtc, bool enable)
1730 {
1731 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
1732 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
1733
1734 intel_de_rmw(i915, CLKGATE_DIS_PSL(crtc->pipe),
1735 mask, enable ? mask : 0);
1736 }
1737
hsw_set_linetime_wm(const struct intel_crtc_state * crtc_state)1738 static void hsw_set_linetime_wm(const struct intel_crtc_state *crtc_state)
1739 {
1740 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1741 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1742
1743 intel_de_write(dev_priv, WM_LINETIME(crtc->pipe),
1744 HSW_LINETIME(crtc_state->linetime) |
1745 HSW_IPS_LINETIME(crtc_state->ips_linetime));
1746 }
1747
hsw_set_frame_start_delay(const struct intel_crtc_state * crtc_state)1748 static void hsw_set_frame_start_delay(const struct intel_crtc_state *crtc_state)
1749 {
1750 struct intel_display *display = to_intel_display(crtc_state);
1751
1752 intel_de_rmw(display, CHICKEN_TRANS(display, crtc_state->cpu_transcoder),
1753 HSW_FRAME_START_DELAY_MASK,
1754 HSW_FRAME_START_DELAY(crtc_state->framestart_delay - 1));
1755 }
1756
hsw_configure_cpu_transcoder(const struct intel_crtc_state * crtc_state)1757 static void hsw_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
1758 {
1759 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1760 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1761 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
1762
1763 if (crtc_state->has_pch_encoder) {
1764 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1765 &crtc_state->fdi_m_n);
1766 } else if (intel_crtc_has_dp_encoder(crtc_state)) {
1767 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
1768 &crtc_state->dp_m_n);
1769 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
1770 &crtc_state->dp_m2_n2);
1771 }
1772
1773 intel_set_transcoder_timings(crtc_state);
1774 if (HAS_VRR(dev_priv))
1775 intel_vrr_set_transcoder_timings(crtc_state);
1776
1777 if (cpu_transcoder != TRANSCODER_EDP)
1778 intel_de_write(dev_priv, TRANS_MULT(dev_priv, cpu_transcoder),
1779 crtc_state->pixel_multiplier - 1);
1780
1781 hsw_set_frame_start_delay(crtc_state);
1782
1783 hsw_set_transconf(crtc_state);
1784 }
1785
hsw_crtc_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)1786 static void hsw_crtc_enable(struct intel_atomic_state *state,
1787 struct intel_crtc *crtc)
1788 {
1789 struct intel_display *display = to_intel_display(state);
1790 const struct intel_crtc_state *new_crtc_state =
1791 intel_atomic_get_new_crtc_state(state, crtc);
1792 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1793 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
1794 struct intel_crtc *pipe_crtc;
1795 int i;
1796
1797 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
1798 return;
1799 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i)
1800 intel_dmc_enable_pipe(display, pipe_crtc->pipe);
1801
1802 intel_encoders_pre_pll_enable(state, crtc);
1803
1804 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) {
1805 const struct intel_crtc_state *pipe_crtc_state =
1806 intel_atomic_get_new_crtc_state(state, pipe_crtc);
1807
1808 if (pipe_crtc_state->shared_dpll)
1809 intel_enable_shared_dpll(pipe_crtc_state);
1810 }
1811
1812 intel_encoders_pre_enable(state, crtc);
1813
1814 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) {
1815 const struct intel_crtc_state *pipe_crtc_state =
1816 intel_atomic_get_new_crtc_state(state, pipe_crtc);
1817
1818 intel_dsc_enable(pipe_crtc_state);
1819
1820 if (HAS_UNCOMPRESSED_JOINER(dev_priv))
1821 intel_uncompressed_joiner_enable(pipe_crtc_state);
1822
1823 intel_set_pipe_src_size(pipe_crtc_state);
1824
1825 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
1826 bdw_set_pipe_misc(NULL, pipe_crtc_state);
1827 }
1828
1829 if (!transcoder_is_dsi(cpu_transcoder))
1830 hsw_configure_cpu_transcoder(new_crtc_state);
1831
1832 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) {
1833 const struct intel_crtc_state *pipe_crtc_state =
1834 intel_atomic_get_new_crtc_state(state, pipe_crtc);
1835
1836 pipe_crtc->active = true;
1837
1838 if (glk_need_scaler_clock_gating_wa(pipe_crtc_state))
1839 glk_pipe_scaler_clock_gating_wa(pipe_crtc, true);
1840
1841 if (DISPLAY_VER(dev_priv) >= 9)
1842 skl_pfit_enable(pipe_crtc_state);
1843 else
1844 ilk_pfit_enable(pipe_crtc_state);
1845
1846 /*
1847 * On ILK+ LUT must be loaded before the pipe is running but with
1848 * clocks enabled
1849 */
1850 intel_color_modeset(pipe_crtc_state);
1851
1852 hsw_set_linetime_wm(pipe_crtc_state);
1853
1854 if (DISPLAY_VER(dev_priv) >= 11)
1855 icl_set_pipe_chicken(pipe_crtc_state);
1856
1857 intel_initial_watermarks(state, pipe_crtc);
1858 }
1859
1860 intel_encoders_enable(state, crtc);
1861
1862 for_each_pipe_crtc_modeset_enable(display, pipe_crtc, new_crtc_state, i) {
1863 const struct intel_crtc_state *pipe_crtc_state =
1864 intel_atomic_get_new_crtc_state(state, pipe_crtc);
1865 enum pipe hsw_workaround_pipe;
1866
1867 if (glk_need_scaler_clock_gating_wa(pipe_crtc_state)) {
1868 intel_crtc_wait_for_next_vblank(pipe_crtc);
1869 glk_pipe_scaler_clock_gating_wa(pipe_crtc, false);
1870 }
1871
1872 /*
1873 * If we change the relative order between pipe/planes
1874 * enabling, we need to change the workaround.
1875 */
1876 hsw_workaround_pipe = pipe_crtc_state->hsw_workaround_pipe;
1877 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
1878 struct intel_crtc *wa_crtc =
1879 intel_crtc_for_pipe(display, hsw_workaround_pipe);
1880
1881 intel_crtc_wait_for_next_vblank(wa_crtc);
1882 intel_crtc_wait_for_next_vblank(wa_crtc);
1883 }
1884 }
1885 }
1886
ilk_pfit_disable(const struct intel_crtc_state * old_crtc_state)1887 void ilk_pfit_disable(const struct intel_crtc_state *old_crtc_state)
1888 {
1889 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
1890 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1891 enum pipe pipe = crtc->pipe;
1892
1893 /* To avoid upsetting the power well on haswell only disable the pfit if
1894 * it's in use. The hw state code will make sure we get this right. */
1895 if (!old_crtc_state->pch_pfit.enabled)
1896 return;
1897
1898 intel_de_write_fw(dev_priv, PF_CTL(pipe), 0);
1899 intel_de_write_fw(dev_priv, PF_WIN_POS(pipe), 0);
1900 intel_de_write_fw(dev_priv, PF_WIN_SZ(pipe), 0);
1901 }
1902
ilk_crtc_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1903 static void ilk_crtc_disable(struct intel_atomic_state *state,
1904 struct intel_crtc *crtc)
1905 {
1906 const struct intel_crtc_state *old_crtc_state =
1907 intel_atomic_get_old_crtc_state(state, crtc);
1908 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1909 enum pipe pipe = crtc->pipe;
1910
1911 /*
1912 * Sometimes spurious CPU pipe underruns happen when the
1913 * pipe is already disabled, but FDI RX/TX is still enabled.
1914 * Happens at least with VGA+HDMI cloning. Suppress them.
1915 */
1916 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
1917 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
1918
1919 intel_encoders_disable(state, crtc);
1920
1921 intel_crtc_vblank_off(old_crtc_state);
1922
1923 intel_disable_transcoder(old_crtc_state);
1924
1925 ilk_pfit_disable(old_crtc_state);
1926
1927 if (old_crtc_state->has_pch_encoder)
1928 ilk_pch_disable(state, crtc);
1929
1930 intel_encoders_post_disable(state, crtc);
1931
1932 if (old_crtc_state->has_pch_encoder)
1933 ilk_pch_post_disable(state, crtc);
1934
1935 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
1936 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
1937
1938 intel_disable_shared_dpll(old_crtc_state);
1939 }
1940
hsw_crtc_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)1941 static void hsw_crtc_disable(struct intel_atomic_state *state,
1942 struct intel_crtc *crtc)
1943 {
1944 struct intel_display *display = to_intel_display(state);
1945 const struct intel_crtc_state *old_crtc_state =
1946 intel_atomic_get_old_crtc_state(state, crtc);
1947 struct intel_crtc *pipe_crtc;
1948 int i;
1949
1950 /*
1951 * FIXME collapse everything to one hook.
1952 * Need care with mst->ddi interactions.
1953 */
1954 intel_encoders_disable(state, crtc);
1955 intel_encoders_post_disable(state, crtc);
1956
1957 for_each_pipe_crtc_modeset_disable(display, pipe_crtc, old_crtc_state, i) {
1958 const struct intel_crtc_state *old_pipe_crtc_state =
1959 intel_atomic_get_old_crtc_state(state, pipe_crtc);
1960
1961 intel_disable_shared_dpll(old_pipe_crtc_state);
1962 }
1963
1964 intel_encoders_post_pll_disable(state, crtc);
1965
1966 for_each_pipe_crtc_modeset_disable(display, pipe_crtc, old_crtc_state, i)
1967 intel_dmc_disable_pipe(display, pipe_crtc->pipe);
1968 }
1969
i9xx_pfit_enable(const struct intel_crtc_state * crtc_state)1970 static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
1971 {
1972 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
1973 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1974
1975 if (!crtc_state->gmch_pfit.control)
1976 return;
1977
1978 /*
1979 * The panel fitter should only be adjusted whilst the pipe is disabled,
1980 * according to register description and PRM.
1981 */
1982 drm_WARN_ON(&dev_priv->drm,
1983 intel_de_read(dev_priv, PFIT_CONTROL(dev_priv)) & PFIT_ENABLE);
1984 assert_transcoder_disabled(dev_priv, crtc_state->cpu_transcoder);
1985
1986 intel_de_write(dev_priv, PFIT_PGM_RATIOS(dev_priv),
1987 crtc_state->gmch_pfit.pgm_ratios);
1988 intel_de_write(dev_priv, PFIT_CONTROL(dev_priv),
1989 crtc_state->gmch_pfit.control);
1990
1991 /* Border color in case we don't scale up to the full screen. Black by
1992 * default, change to something else for debugging. */
1993 intel_de_write(dev_priv, BCLRPAT(dev_priv, crtc->pipe), 0);
1994 }
1995
1996 /* Prefer intel_encoder_is_combo() */
intel_phy_is_combo(struct drm_i915_private * dev_priv,enum phy phy)1997 bool intel_phy_is_combo(struct drm_i915_private *dev_priv, enum phy phy)
1998 {
1999 if (phy == PHY_NONE)
2000 return false;
2001 else if (IS_ALDERLAKE_S(dev_priv))
2002 return phy <= PHY_E;
2003 else if (IS_DG1(dev_priv) || IS_ROCKETLAKE(dev_priv))
2004 return phy <= PHY_D;
2005 else if (IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv))
2006 return phy <= PHY_C;
2007 else if (IS_ALDERLAKE_P(dev_priv) || IS_DISPLAY_VER(dev_priv, 11, 12))
2008 return phy <= PHY_B;
2009 else
2010 /*
2011 * DG2 outputs labelled as "combo PHY" in the bspec use
2012 * SNPS PHYs with completely different programming,
2013 * hence we always return false here.
2014 */
2015 return false;
2016 }
2017
2018 /* Prefer intel_encoder_is_tc() */
intel_phy_is_tc(struct drm_i915_private * dev_priv,enum phy phy)2019 bool intel_phy_is_tc(struct drm_i915_private *dev_priv, enum phy phy)
2020 {
2021 /*
2022 * Discrete GPU phy's are not attached to FIA's to support TC
2023 * subsystem Legacy or non-legacy, and only support native DP/HDMI
2024 */
2025 if (IS_DGFX(dev_priv))
2026 return false;
2027
2028 if (DISPLAY_VER(dev_priv) >= 13)
2029 return phy >= PHY_F && phy <= PHY_I;
2030 else if (IS_TIGERLAKE(dev_priv))
2031 return phy >= PHY_D && phy <= PHY_I;
2032 else if (IS_ICELAKE(dev_priv))
2033 return phy >= PHY_C && phy <= PHY_F;
2034
2035 return false;
2036 }
2037
2038 /* Prefer intel_encoder_is_snps() */
intel_phy_is_snps(struct drm_i915_private * dev_priv,enum phy phy)2039 bool intel_phy_is_snps(struct drm_i915_private *dev_priv, enum phy phy)
2040 {
2041 /*
2042 * For DG2, and for DG2 only, all four "combo" ports and the TC1 port
2043 * (PHY E) use Synopsis PHYs. See intel_phy_is_tc().
2044 */
2045 return IS_DG2(dev_priv) && phy > PHY_NONE && phy <= PHY_E;
2046 }
2047
2048 /* Prefer intel_encoder_to_phy() */
intel_port_to_phy(struct drm_i915_private * i915,enum port port)2049 enum phy intel_port_to_phy(struct drm_i915_private *i915, enum port port)
2050 {
2051 if (DISPLAY_VER(i915) >= 13 && port >= PORT_D_XELPD)
2052 return PHY_D + port - PORT_D_XELPD;
2053 else if (DISPLAY_VER(i915) >= 13 && port >= PORT_TC1)
2054 return PHY_F + port - PORT_TC1;
2055 else if (IS_ALDERLAKE_S(i915) && port >= PORT_TC1)
2056 return PHY_B + port - PORT_TC1;
2057 else if ((IS_DG1(i915) || IS_ROCKETLAKE(i915)) && port >= PORT_TC1)
2058 return PHY_C + port - PORT_TC1;
2059 else if ((IS_JASPERLAKE(i915) || IS_ELKHARTLAKE(i915)) &&
2060 port == PORT_D)
2061 return PHY_A;
2062
2063 return PHY_A + port - PORT_A;
2064 }
2065
2066 /* Prefer intel_encoder_to_tc() */
intel_port_to_tc(struct drm_i915_private * dev_priv,enum port port)2067 enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
2068 {
2069 if (!intel_phy_is_tc(dev_priv, intel_port_to_phy(dev_priv, port)))
2070 return TC_PORT_NONE;
2071
2072 if (DISPLAY_VER(dev_priv) >= 12)
2073 return TC_PORT_1 + port - PORT_TC1;
2074 else
2075 return TC_PORT_1 + port - PORT_C;
2076 }
2077
intel_encoder_to_phy(struct intel_encoder * encoder)2078 enum phy intel_encoder_to_phy(struct intel_encoder *encoder)
2079 {
2080 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2081
2082 return intel_port_to_phy(i915, encoder->port);
2083 }
2084
intel_encoder_is_combo(struct intel_encoder * encoder)2085 bool intel_encoder_is_combo(struct intel_encoder *encoder)
2086 {
2087 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2088
2089 return intel_phy_is_combo(i915, intel_encoder_to_phy(encoder));
2090 }
2091
intel_encoder_is_snps(struct intel_encoder * encoder)2092 bool intel_encoder_is_snps(struct intel_encoder *encoder)
2093 {
2094 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2095
2096 return intel_phy_is_snps(i915, intel_encoder_to_phy(encoder));
2097 }
2098
intel_encoder_is_tc(struct intel_encoder * encoder)2099 bool intel_encoder_is_tc(struct intel_encoder *encoder)
2100 {
2101 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2102
2103 return intel_phy_is_tc(i915, intel_encoder_to_phy(encoder));
2104 }
2105
intel_encoder_to_tc(struct intel_encoder * encoder)2106 enum tc_port intel_encoder_to_tc(struct intel_encoder *encoder)
2107 {
2108 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2109
2110 return intel_port_to_tc(i915, encoder->port);
2111 }
2112
2113 enum intel_display_power_domain
intel_aux_power_domain(struct intel_digital_port * dig_port)2114 intel_aux_power_domain(struct intel_digital_port *dig_port)
2115 {
2116 struct drm_i915_private *i915 = to_i915(dig_port->base.base.dev);
2117
2118 if (intel_tc_port_in_tbt_alt_mode(dig_port))
2119 return intel_display_power_tbt_aux_domain(i915, dig_port->aux_ch);
2120
2121 return intel_display_power_legacy_aux_domain(i915, dig_port->aux_ch);
2122 }
2123
get_crtc_power_domains(struct intel_crtc_state * crtc_state,struct intel_power_domain_mask * mask)2124 static void get_crtc_power_domains(struct intel_crtc_state *crtc_state,
2125 struct intel_power_domain_mask *mask)
2126 {
2127 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2128 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2129 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2130 struct drm_encoder *encoder;
2131 enum pipe pipe = crtc->pipe;
2132
2133 bitmap_zero(mask->bits, POWER_DOMAIN_NUM);
2134
2135 if (!crtc_state->hw.active)
2136 return;
2137
2138 set_bit(POWER_DOMAIN_PIPE(pipe), mask->bits);
2139 set_bit(POWER_DOMAIN_TRANSCODER(cpu_transcoder), mask->bits);
2140 if (crtc_state->pch_pfit.enabled ||
2141 crtc_state->pch_pfit.force_thru)
2142 set_bit(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe), mask->bits);
2143
2144 drm_for_each_encoder_mask(encoder, &dev_priv->drm,
2145 crtc_state->uapi.encoder_mask) {
2146 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2147
2148 set_bit(intel_encoder->power_domain, mask->bits);
2149 }
2150
2151 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
2152 set_bit(POWER_DOMAIN_AUDIO_MMIO, mask->bits);
2153
2154 if (crtc_state->shared_dpll)
2155 set_bit(POWER_DOMAIN_DISPLAY_CORE, mask->bits);
2156
2157 if (crtc_state->dsc.compression_enable)
2158 set_bit(intel_dsc_power_domain(crtc, cpu_transcoder), mask->bits);
2159 }
2160
intel_modeset_get_crtc_power_domains(struct intel_crtc_state * crtc_state,struct intel_power_domain_mask * old_domains)2161 void intel_modeset_get_crtc_power_domains(struct intel_crtc_state *crtc_state,
2162 struct intel_power_domain_mask *old_domains)
2163 {
2164 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2165 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2166 enum intel_display_power_domain domain;
2167 struct intel_power_domain_mask domains, new_domains;
2168
2169 get_crtc_power_domains(crtc_state, &domains);
2170
2171 bitmap_andnot(new_domains.bits,
2172 domains.bits,
2173 crtc->enabled_power_domains.mask.bits,
2174 POWER_DOMAIN_NUM);
2175 bitmap_andnot(old_domains->bits,
2176 crtc->enabled_power_domains.mask.bits,
2177 domains.bits,
2178 POWER_DOMAIN_NUM);
2179
2180 for_each_power_domain(domain, &new_domains)
2181 intel_display_power_get_in_set(dev_priv,
2182 &crtc->enabled_power_domains,
2183 domain);
2184 }
2185
intel_modeset_put_crtc_power_domains(struct intel_crtc * crtc,struct intel_power_domain_mask * domains)2186 void intel_modeset_put_crtc_power_domains(struct intel_crtc *crtc,
2187 struct intel_power_domain_mask *domains)
2188 {
2189 intel_display_power_put_mask_in_set(to_i915(crtc->base.dev),
2190 &crtc->enabled_power_domains,
2191 domains);
2192 }
2193
i9xx_configure_cpu_transcoder(const struct intel_crtc_state * crtc_state)2194 static void i9xx_configure_cpu_transcoder(const struct intel_crtc_state *crtc_state)
2195 {
2196 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2197 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2198
2199 if (intel_crtc_has_dp_encoder(crtc_state)) {
2200 intel_cpu_transcoder_set_m1_n1(crtc, cpu_transcoder,
2201 &crtc_state->dp_m_n);
2202 intel_cpu_transcoder_set_m2_n2(crtc, cpu_transcoder,
2203 &crtc_state->dp_m2_n2);
2204 }
2205
2206 intel_set_transcoder_timings(crtc_state);
2207
2208 i9xx_set_pipeconf(crtc_state);
2209 }
2210
valleyview_crtc_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)2211 static void valleyview_crtc_enable(struct intel_atomic_state *state,
2212 struct intel_crtc *crtc)
2213 {
2214 const struct intel_crtc_state *new_crtc_state =
2215 intel_atomic_get_new_crtc_state(state, crtc);
2216 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2217 enum pipe pipe = crtc->pipe;
2218
2219 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2220 return;
2221
2222 i9xx_configure_cpu_transcoder(new_crtc_state);
2223
2224 intel_set_pipe_src_size(new_crtc_state);
2225
2226 intel_de_write(dev_priv, VLV_PIPE_MSA_MISC(pipe), 0);
2227
2228 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
2229 intel_de_write(dev_priv, CHV_BLEND(dev_priv, pipe),
2230 CHV_BLEND_LEGACY);
2231 intel_de_write(dev_priv, CHV_CANVAS(dev_priv, pipe), 0);
2232 }
2233
2234 crtc->active = true;
2235
2236 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2237
2238 intel_encoders_pre_pll_enable(state, crtc);
2239
2240 if (IS_CHERRYVIEW(dev_priv))
2241 chv_enable_pll(new_crtc_state);
2242 else
2243 vlv_enable_pll(new_crtc_state);
2244
2245 intel_encoders_pre_enable(state, crtc);
2246
2247 i9xx_pfit_enable(new_crtc_state);
2248
2249 intel_color_modeset(new_crtc_state);
2250
2251 intel_initial_watermarks(state, crtc);
2252 intel_enable_transcoder(new_crtc_state);
2253
2254 intel_crtc_vblank_on(new_crtc_state);
2255
2256 intel_encoders_enable(state, crtc);
2257 }
2258
i9xx_crtc_enable(struct intel_atomic_state * state,struct intel_crtc * crtc)2259 static void i9xx_crtc_enable(struct intel_atomic_state *state,
2260 struct intel_crtc *crtc)
2261 {
2262 const struct intel_crtc_state *new_crtc_state =
2263 intel_atomic_get_new_crtc_state(state, crtc);
2264 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2265 enum pipe pipe = crtc->pipe;
2266
2267 if (drm_WARN_ON(&dev_priv->drm, crtc->active))
2268 return;
2269
2270 i9xx_configure_cpu_transcoder(new_crtc_state);
2271
2272 intel_set_pipe_src_size(new_crtc_state);
2273
2274 crtc->active = true;
2275
2276 if (DISPLAY_VER(dev_priv) != 2)
2277 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
2278
2279 intel_encoders_pre_enable(state, crtc);
2280
2281 i9xx_enable_pll(new_crtc_state);
2282
2283 i9xx_pfit_enable(new_crtc_state);
2284
2285 intel_color_modeset(new_crtc_state);
2286
2287 if (!intel_initial_watermarks(state, crtc))
2288 intel_update_watermarks(dev_priv);
2289 intel_enable_transcoder(new_crtc_state);
2290
2291 intel_crtc_vblank_on(new_crtc_state);
2292
2293 intel_encoders_enable(state, crtc);
2294
2295 /* prevents spurious underruns */
2296 if (DISPLAY_VER(dev_priv) == 2)
2297 intel_crtc_wait_for_next_vblank(crtc);
2298 }
2299
i9xx_pfit_disable(const struct intel_crtc_state * old_crtc_state)2300 static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
2301 {
2302 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc);
2303 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2304
2305 if (!old_crtc_state->gmch_pfit.control)
2306 return;
2307
2308 assert_transcoder_disabled(dev_priv, old_crtc_state->cpu_transcoder);
2309
2310 drm_dbg_kms(&dev_priv->drm, "disabling pfit, current: 0x%08x\n",
2311 intel_de_read(dev_priv, PFIT_CONTROL(dev_priv)));
2312 intel_de_write(dev_priv, PFIT_CONTROL(dev_priv), 0);
2313 }
2314
i9xx_crtc_disable(struct intel_atomic_state * state,struct intel_crtc * crtc)2315 static void i9xx_crtc_disable(struct intel_atomic_state *state,
2316 struct intel_crtc *crtc)
2317 {
2318 struct intel_display *display = to_intel_display(state);
2319 struct drm_i915_private *dev_priv = to_i915(display->drm);
2320 struct intel_crtc_state *old_crtc_state =
2321 intel_atomic_get_old_crtc_state(state, crtc);
2322 enum pipe pipe = crtc->pipe;
2323
2324 /*
2325 * On gen2 planes are double buffered but the pipe isn't, so we must
2326 * wait for planes to fully turn off before disabling the pipe.
2327 */
2328 if (DISPLAY_VER(dev_priv) == 2)
2329 intel_crtc_wait_for_next_vblank(crtc);
2330
2331 intel_encoders_disable(state, crtc);
2332
2333 intel_crtc_vblank_off(old_crtc_state);
2334
2335 intel_disable_transcoder(old_crtc_state);
2336
2337 i9xx_pfit_disable(old_crtc_state);
2338
2339 intel_encoders_post_disable(state, crtc);
2340
2341 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
2342 if (IS_CHERRYVIEW(dev_priv))
2343 chv_disable_pll(dev_priv, pipe);
2344 else if (IS_VALLEYVIEW(dev_priv))
2345 vlv_disable_pll(dev_priv, pipe);
2346 else
2347 i9xx_disable_pll(old_crtc_state);
2348 }
2349
2350 intel_encoders_post_pll_disable(state, crtc);
2351
2352 if (DISPLAY_VER(dev_priv) != 2)
2353 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
2354
2355 if (!dev_priv->display.funcs.wm->initial_watermarks)
2356 intel_update_watermarks(dev_priv);
2357
2358 /* clock the pipe down to 640x480@60 to potentially save power */
2359 if (IS_I830(dev_priv))
2360 i830_enable_pipe(display, pipe);
2361 }
2362
intel_encoder_destroy(struct drm_encoder * encoder)2363 void intel_encoder_destroy(struct drm_encoder *encoder)
2364 {
2365 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
2366
2367 drm_encoder_cleanup(encoder);
2368 kfree(intel_encoder);
2369 }
2370
intel_crtc_supports_double_wide(const struct intel_crtc * crtc)2371 static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
2372 {
2373 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2374
2375 /* GDG double wide on either pipe, otherwise pipe A only */
2376 return HAS_DOUBLE_WIDE(dev_priv) &&
2377 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
2378 }
2379
ilk_pipe_pixel_rate(const struct intel_crtc_state * crtc_state)2380 static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *crtc_state)
2381 {
2382 u32 pixel_rate = crtc_state->hw.pipe_mode.crtc_clock;
2383 struct drm_rect src;
2384
2385 /*
2386 * We only use IF-ID interlacing. If we ever use
2387 * PF-ID we'll need to adjust the pixel_rate here.
2388 */
2389
2390 if (!crtc_state->pch_pfit.enabled)
2391 return pixel_rate;
2392
2393 drm_rect_init(&src, 0, 0,
2394 drm_rect_width(&crtc_state->pipe_src) << 16,
2395 drm_rect_height(&crtc_state->pipe_src) << 16);
2396
2397 return intel_adjusted_rate(&src, &crtc_state->pch_pfit.dst,
2398 pixel_rate);
2399 }
2400
intel_mode_from_crtc_timings(struct drm_display_mode * mode,const struct drm_display_mode * timings)2401 static void intel_mode_from_crtc_timings(struct drm_display_mode *mode,
2402 const struct drm_display_mode *timings)
2403 {
2404 mode->hdisplay = timings->crtc_hdisplay;
2405 mode->htotal = timings->crtc_htotal;
2406 mode->hsync_start = timings->crtc_hsync_start;
2407 mode->hsync_end = timings->crtc_hsync_end;
2408
2409 mode->vdisplay = timings->crtc_vdisplay;
2410 mode->vtotal = timings->crtc_vtotal;
2411 mode->vsync_start = timings->crtc_vsync_start;
2412 mode->vsync_end = timings->crtc_vsync_end;
2413
2414 mode->flags = timings->flags;
2415 mode->type = DRM_MODE_TYPE_DRIVER;
2416
2417 mode->clock = timings->crtc_clock;
2418
2419 drm_mode_set_name(mode);
2420 }
2421
intel_crtc_compute_pixel_rate(struct intel_crtc_state * crtc_state)2422 static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
2423 {
2424 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2425
2426 if (HAS_GMCH(dev_priv))
2427 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
2428 crtc_state->pixel_rate =
2429 crtc_state->hw.pipe_mode.crtc_clock;
2430 else
2431 crtc_state->pixel_rate =
2432 ilk_pipe_pixel_rate(crtc_state);
2433 }
2434
intel_joiner_adjust_timings(const struct intel_crtc_state * crtc_state,struct drm_display_mode * mode)2435 static void intel_joiner_adjust_timings(const struct intel_crtc_state *crtc_state,
2436 struct drm_display_mode *mode)
2437 {
2438 int num_pipes = intel_crtc_num_joined_pipes(crtc_state);
2439
2440 if (num_pipes == 1)
2441 return;
2442
2443 mode->crtc_clock /= num_pipes;
2444 mode->crtc_hdisplay /= num_pipes;
2445 mode->crtc_hblank_start /= num_pipes;
2446 mode->crtc_hblank_end /= num_pipes;
2447 mode->crtc_hsync_start /= num_pipes;
2448 mode->crtc_hsync_end /= num_pipes;
2449 mode->crtc_htotal /= num_pipes;
2450 }
2451
intel_splitter_adjust_timings(const struct intel_crtc_state * crtc_state,struct drm_display_mode * mode)2452 static void intel_splitter_adjust_timings(const struct intel_crtc_state *crtc_state,
2453 struct drm_display_mode *mode)
2454 {
2455 int overlap = crtc_state->splitter.pixel_overlap;
2456 int n = crtc_state->splitter.link_count;
2457
2458 if (!crtc_state->splitter.enable)
2459 return;
2460
2461 /*
2462 * eDP MSO uses segment timings from EDID for transcoder
2463 * timings, but full mode for everything else.
2464 *
2465 * h_full = (h_segment - pixel_overlap) * link_count
2466 */
2467 mode->crtc_hdisplay = (mode->crtc_hdisplay - overlap) * n;
2468 mode->crtc_hblank_start = (mode->crtc_hblank_start - overlap) * n;
2469 mode->crtc_hblank_end = (mode->crtc_hblank_end - overlap) * n;
2470 mode->crtc_hsync_start = (mode->crtc_hsync_start - overlap) * n;
2471 mode->crtc_hsync_end = (mode->crtc_hsync_end - overlap) * n;
2472 mode->crtc_htotal = (mode->crtc_htotal - overlap) * n;
2473 mode->crtc_clock *= n;
2474 }
2475
intel_crtc_readout_derived_state(struct intel_crtc_state * crtc_state)2476 static void intel_crtc_readout_derived_state(struct intel_crtc_state *crtc_state)
2477 {
2478 struct drm_display_mode *mode = &crtc_state->hw.mode;
2479 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2480 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2481
2482 /*
2483 * Start with the adjusted_mode crtc timings, which
2484 * have been filled with the transcoder timings.
2485 */
2486 drm_mode_copy(pipe_mode, adjusted_mode);
2487
2488 /* Expand MSO per-segment transcoder timings to full */
2489 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2490
2491 /*
2492 * We want the full numbers in adjusted_mode normal timings,
2493 * adjusted_mode crtc timings are left with the raw transcoder
2494 * timings.
2495 */
2496 intel_mode_from_crtc_timings(adjusted_mode, pipe_mode);
2497
2498 /* Populate the "user" mode with full numbers */
2499 drm_mode_copy(mode, pipe_mode);
2500 intel_mode_from_crtc_timings(mode, mode);
2501 mode->hdisplay = drm_rect_width(&crtc_state->pipe_src) *
2502 intel_crtc_num_joined_pipes(crtc_state);
2503 mode->vdisplay = drm_rect_height(&crtc_state->pipe_src);
2504
2505 /* Derive per-pipe timings in case joiner is used */
2506 intel_joiner_adjust_timings(crtc_state, pipe_mode);
2507 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2508
2509 intel_crtc_compute_pixel_rate(crtc_state);
2510 }
2511
intel_encoder_get_config(struct intel_encoder * encoder,struct intel_crtc_state * crtc_state)2512 void intel_encoder_get_config(struct intel_encoder *encoder,
2513 struct intel_crtc_state *crtc_state)
2514 {
2515 encoder->get_config(encoder, crtc_state);
2516
2517 intel_crtc_readout_derived_state(crtc_state);
2518 }
2519
intel_joiner_compute_pipe_src(struct intel_crtc_state * crtc_state)2520 static void intel_joiner_compute_pipe_src(struct intel_crtc_state *crtc_state)
2521 {
2522 int num_pipes = intel_crtc_num_joined_pipes(crtc_state);
2523 int width, height;
2524
2525 if (num_pipes == 1)
2526 return;
2527
2528 width = drm_rect_width(&crtc_state->pipe_src);
2529 height = drm_rect_height(&crtc_state->pipe_src);
2530
2531 drm_rect_init(&crtc_state->pipe_src, 0, 0,
2532 width / num_pipes, height);
2533 }
2534
intel_crtc_compute_pipe_src(struct intel_crtc_state * crtc_state)2535 static int intel_crtc_compute_pipe_src(struct intel_crtc_state *crtc_state)
2536 {
2537 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2538 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2539
2540 intel_joiner_compute_pipe_src(crtc_state);
2541
2542 /*
2543 * Pipe horizontal size must be even in:
2544 * - DVO ganged mode
2545 * - LVDS dual channel mode
2546 * - Double wide pipe
2547 */
2548 if (drm_rect_width(&crtc_state->pipe_src) & 1) {
2549 if (crtc_state->double_wide) {
2550 drm_dbg_kms(&i915->drm,
2551 "[CRTC:%d:%s] Odd pipe source width not supported with double wide pipe\n",
2552 crtc->base.base.id, crtc->base.name);
2553 return -EINVAL;
2554 }
2555
2556 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
2557 intel_is_dual_link_lvds(i915)) {
2558 drm_dbg_kms(&i915->drm,
2559 "[CRTC:%d:%s] Odd pipe source width not supported with dual link LVDS\n",
2560 crtc->base.base.id, crtc->base.name);
2561 return -EINVAL;
2562 }
2563 }
2564
2565 return 0;
2566 }
2567
intel_crtc_compute_pipe_mode(struct intel_crtc_state * crtc_state)2568 static int intel_crtc_compute_pipe_mode(struct intel_crtc_state *crtc_state)
2569 {
2570 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2571 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
2572 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2573 struct drm_display_mode *pipe_mode = &crtc_state->hw.pipe_mode;
2574 int clock_limit = i915->display.cdclk.max_dotclk_freq;
2575
2576 /*
2577 * Start with the adjusted_mode crtc timings, which
2578 * have been filled with the transcoder timings.
2579 */
2580 drm_mode_copy(pipe_mode, adjusted_mode);
2581
2582 /* Expand MSO per-segment transcoder timings to full */
2583 intel_splitter_adjust_timings(crtc_state, pipe_mode);
2584
2585 /* Derive per-pipe timings in case joiner is used */
2586 intel_joiner_adjust_timings(crtc_state, pipe_mode);
2587 intel_mode_from_crtc_timings(pipe_mode, pipe_mode);
2588
2589 if (DISPLAY_VER(i915) < 4) {
2590 clock_limit = i915->display.cdclk.max_cdclk_freq * 9 / 10;
2591
2592 /*
2593 * Enable double wide mode when the dot clock
2594 * is > 90% of the (display) core speed.
2595 */
2596 if (intel_crtc_supports_double_wide(crtc) &&
2597 pipe_mode->crtc_clock > clock_limit) {
2598 clock_limit = i915->display.cdclk.max_dotclk_freq;
2599 crtc_state->double_wide = true;
2600 }
2601 }
2602
2603 if (pipe_mode->crtc_clock > clock_limit) {
2604 drm_dbg_kms(&i915->drm,
2605 "[CRTC:%d:%s] requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
2606 crtc->base.base.id, crtc->base.name,
2607 pipe_mode->crtc_clock, clock_limit,
2608 str_yes_no(crtc_state->double_wide));
2609 return -EINVAL;
2610 }
2611
2612 return 0;
2613 }
2614
intel_crtc_needs_wa_14015401596(struct intel_crtc_state * crtc_state)2615 static bool intel_crtc_needs_wa_14015401596(struct intel_crtc_state *crtc_state)
2616 {
2617 struct intel_display *display = to_intel_display(crtc_state);
2618 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2619
2620 return intel_vrr_possible(crtc_state) && crtc_state->has_psr &&
2621 adjusted_mode->crtc_vblank_start == adjusted_mode->crtc_vdisplay &&
2622 IS_DISPLAY_VER(display, 13, 14);
2623 }
2624
intel_crtc_compute_config(struct intel_atomic_state * state,struct intel_crtc * crtc)2625 static int intel_crtc_compute_config(struct intel_atomic_state *state,
2626 struct intel_crtc *crtc)
2627 {
2628 struct intel_crtc_state *crtc_state =
2629 intel_atomic_get_new_crtc_state(state, crtc);
2630 struct drm_display_mode *adjusted_mode =
2631 &crtc_state->hw.adjusted_mode;
2632 int ret;
2633
2634 /* Wa_14015401596 */
2635 if (intel_crtc_needs_wa_14015401596(crtc_state))
2636 adjusted_mode->crtc_vblank_start += 1;
2637
2638 ret = intel_dpll_crtc_compute_clock(state, crtc);
2639 if (ret)
2640 return ret;
2641
2642 ret = intel_crtc_compute_pipe_src(crtc_state);
2643 if (ret)
2644 return ret;
2645
2646 ret = intel_crtc_compute_pipe_mode(crtc_state);
2647 if (ret)
2648 return ret;
2649
2650 intel_crtc_compute_pixel_rate(crtc_state);
2651
2652 if (crtc_state->has_pch_encoder)
2653 return ilk_fdi_compute_config(crtc, crtc_state);
2654
2655 return 0;
2656 }
2657
2658 static void
intel_reduce_m_n_ratio(u32 * num,u32 * den)2659 intel_reduce_m_n_ratio(u32 *num, u32 *den)
2660 {
2661 while (*num > DATA_LINK_M_N_MASK ||
2662 *den > DATA_LINK_M_N_MASK) {
2663 *num >>= 1;
2664 *den >>= 1;
2665 }
2666 }
2667
compute_m_n(u32 * ret_m,u32 * ret_n,u32 m,u32 n,u32 constant_n)2668 static void compute_m_n(u32 *ret_m, u32 *ret_n,
2669 u32 m, u32 n, u32 constant_n)
2670 {
2671 if (constant_n)
2672 *ret_n = constant_n;
2673 else
2674 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
2675
2676 *ret_m = div_u64(mul_u32_u32(m, *ret_n), n);
2677 intel_reduce_m_n_ratio(ret_m, ret_n);
2678 }
2679
2680 void
intel_link_compute_m_n(u16 bits_per_pixel_x16,int nlanes,int pixel_clock,int link_clock,int bw_overhead,struct intel_link_m_n * m_n)2681 intel_link_compute_m_n(u16 bits_per_pixel_x16, int nlanes,
2682 int pixel_clock, int link_clock,
2683 int bw_overhead,
2684 struct intel_link_m_n *m_n)
2685 {
2686 u32 link_symbol_clock = intel_dp_link_symbol_clock(link_clock);
2687 u32 data_m = intel_dp_effective_data_rate(pixel_clock, bits_per_pixel_x16,
2688 bw_overhead);
2689 u32 data_n = drm_dp_max_dprx_data_rate(link_clock, nlanes);
2690
2691 /*
2692 * Windows/BIOS uses fixed M/N values always. Follow suit.
2693 *
2694 * Also several DP dongles in particular seem to be fussy
2695 * about too large link M/N values. Presumably the 20bit
2696 * value used by Windows/BIOS is acceptable to everyone.
2697 */
2698 m_n->tu = 64;
2699 compute_m_n(&m_n->data_m, &m_n->data_n,
2700 data_m, data_n,
2701 0x8000000);
2702
2703 compute_m_n(&m_n->link_m, &m_n->link_n,
2704 pixel_clock, link_symbol_clock,
2705 0x80000);
2706 }
2707
intel_panel_sanitize_ssc(struct drm_i915_private * dev_priv)2708 void intel_panel_sanitize_ssc(struct drm_i915_private *dev_priv)
2709 {
2710 /*
2711 * There may be no VBT; and if the BIOS enabled SSC we can
2712 * just keep using it to avoid unnecessary flicker. Whereas if the
2713 * BIOS isn't using it, don't assume it will work even if the VBT
2714 * indicates as much.
2715 */
2716 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
2717 bool bios_lvds_use_ssc = intel_de_read(dev_priv,
2718 PCH_DREF_CONTROL) &
2719 DREF_SSC1_ENABLE;
2720
2721 if (dev_priv->display.vbt.lvds_use_ssc != bios_lvds_use_ssc) {
2722 drm_dbg_kms(&dev_priv->drm,
2723 "SSC %s by BIOS, overriding VBT which says %s\n",
2724 str_enabled_disabled(bios_lvds_use_ssc),
2725 str_enabled_disabled(dev_priv->display.vbt.lvds_use_ssc));
2726 dev_priv->display.vbt.lvds_use_ssc = bios_lvds_use_ssc;
2727 }
2728 }
2729 }
2730
intel_zero_m_n(struct intel_link_m_n * m_n)2731 void intel_zero_m_n(struct intel_link_m_n *m_n)
2732 {
2733 /* corresponds to 0 register value */
2734 memset(m_n, 0, sizeof(*m_n));
2735 m_n->tu = 1;
2736 }
2737
intel_set_m_n(struct drm_i915_private * i915,const struct intel_link_m_n * m_n,i915_reg_t data_m_reg,i915_reg_t data_n_reg,i915_reg_t link_m_reg,i915_reg_t link_n_reg)2738 void intel_set_m_n(struct drm_i915_private *i915,
2739 const struct intel_link_m_n *m_n,
2740 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
2741 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
2742 {
2743 intel_de_write(i915, data_m_reg, TU_SIZE(m_n->tu) | m_n->data_m);
2744 intel_de_write(i915, data_n_reg, m_n->data_n);
2745 intel_de_write(i915, link_m_reg, m_n->link_m);
2746 /*
2747 * On BDW+ writing LINK_N arms the double buffered update
2748 * of all the M/N registers, so it must be written last.
2749 */
2750 intel_de_write(i915, link_n_reg, m_n->link_n);
2751 }
2752
intel_cpu_transcoder_has_m2_n2(struct drm_i915_private * dev_priv,enum transcoder transcoder)2753 bool intel_cpu_transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
2754 enum transcoder transcoder)
2755 {
2756 if (IS_HASWELL(dev_priv))
2757 return transcoder == TRANSCODER_EDP;
2758
2759 return IS_DISPLAY_VER(dev_priv, 5, 7) || IS_CHERRYVIEW(dev_priv);
2760 }
2761
intel_cpu_transcoder_set_m1_n1(struct intel_crtc * crtc,enum transcoder transcoder,const struct intel_link_m_n * m_n)2762 void intel_cpu_transcoder_set_m1_n1(struct intel_crtc *crtc,
2763 enum transcoder transcoder,
2764 const struct intel_link_m_n *m_n)
2765 {
2766 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2767 enum pipe pipe = crtc->pipe;
2768
2769 if (DISPLAY_VER(dev_priv) >= 5)
2770 intel_set_m_n(dev_priv, m_n,
2771 PIPE_DATA_M1(dev_priv, transcoder),
2772 PIPE_DATA_N1(dev_priv, transcoder),
2773 PIPE_LINK_M1(dev_priv, transcoder),
2774 PIPE_LINK_N1(dev_priv, transcoder));
2775 else
2776 intel_set_m_n(dev_priv, m_n,
2777 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
2778 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
2779 }
2780
intel_cpu_transcoder_set_m2_n2(struct intel_crtc * crtc,enum transcoder transcoder,const struct intel_link_m_n * m_n)2781 void intel_cpu_transcoder_set_m2_n2(struct intel_crtc *crtc,
2782 enum transcoder transcoder,
2783 const struct intel_link_m_n *m_n)
2784 {
2785 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2786
2787 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
2788 return;
2789
2790 intel_set_m_n(dev_priv, m_n,
2791 PIPE_DATA_M2(dev_priv, transcoder),
2792 PIPE_DATA_N2(dev_priv, transcoder),
2793 PIPE_LINK_M2(dev_priv, transcoder),
2794 PIPE_LINK_N2(dev_priv, transcoder));
2795 }
2796
intel_set_transcoder_timings(const struct intel_crtc_state * crtc_state)2797 static void intel_set_transcoder_timings(const struct intel_crtc_state *crtc_state)
2798 {
2799 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2800 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2801 enum pipe pipe = crtc->pipe;
2802 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2803 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2804 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2805 int vsyncshift = 0;
2806
2807 /* We need to be careful not to changed the adjusted mode, for otherwise
2808 * the hw state checker will get angry at the mismatch. */
2809 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2810 crtc_vtotal = adjusted_mode->crtc_vtotal;
2811 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2812 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2813
2814 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
2815 /* the chip adds 2 halflines automatically */
2816 crtc_vtotal -= 1;
2817 crtc_vblank_end -= 1;
2818
2819 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
2820 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
2821 else
2822 vsyncshift = adjusted_mode->crtc_hsync_start -
2823 adjusted_mode->crtc_htotal / 2;
2824 if (vsyncshift < 0)
2825 vsyncshift += adjusted_mode->crtc_htotal;
2826 }
2827
2828 /*
2829 * VBLANK_START no longer works on ADL+, instead we must use
2830 * TRANS_SET_CONTEXT_LATENCY to configure the pipe vblank start.
2831 */
2832 if (DISPLAY_VER(dev_priv) >= 13) {
2833 intel_de_write(dev_priv,
2834 TRANS_SET_CONTEXT_LATENCY(dev_priv, cpu_transcoder),
2835 crtc_vblank_start - crtc_vdisplay);
2836
2837 /*
2838 * VBLANK_START not used by hw, just clear it
2839 * to make it stand out in register dumps.
2840 */
2841 crtc_vblank_start = 1;
2842 }
2843
2844 if (DISPLAY_VER(dev_priv) >= 4)
2845 intel_de_write(dev_priv,
2846 TRANS_VSYNCSHIFT(dev_priv, cpu_transcoder),
2847 vsyncshift);
2848
2849 intel_de_write(dev_priv, TRANS_HTOTAL(dev_priv, cpu_transcoder),
2850 HACTIVE(adjusted_mode->crtc_hdisplay - 1) |
2851 HTOTAL(adjusted_mode->crtc_htotal - 1));
2852 intel_de_write(dev_priv, TRANS_HBLANK(dev_priv, cpu_transcoder),
2853 HBLANK_START(adjusted_mode->crtc_hblank_start - 1) |
2854 HBLANK_END(adjusted_mode->crtc_hblank_end - 1));
2855 intel_de_write(dev_priv, TRANS_HSYNC(dev_priv, cpu_transcoder),
2856 HSYNC_START(adjusted_mode->crtc_hsync_start - 1) |
2857 HSYNC_END(adjusted_mode->crtc_hsync_end - 1));
2858
2859 intel_de_write(dev_priv, TRANS_VTOTAL(dev_priv, cpu_transcoder),
2860 VACTIVE(crtc_vdisplay - 1) |
2861 VTOTAL(crtc_vtotal - 1));
2862 intel_de_write(dev_priv, TRANS_VBLANK(dev_priv, cpu_transcoder),
2863 VBLANK_START(crtc_vblank_start - 1) |
2864 VBLANK_END(crtc_vblank_end - 1));
2865 intel_de_write(dev_priv, TRANS_VSYNC(dev_priv, cpu_transcoder),
2866 VSYNC_START(adjusted_mode->crtc_vsync_start - 1) |
2867 VSYNC_END(adjusted_mode->crtc_vsync_end - 1));
2868
2869 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
2870 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
2871 * documented on the DDI_FUNC_CTL register description, EDP Input Select
2872 * bits. */
2873 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
2874 (pipe == PIPE_B || pipe == PIPE_C))
2875 intel_de_write(dev_priv, TRANS_VTOTAL(dev_priv, pipe),
2876 VACTIVE(crtc_vdisplay - 1) |
2877 VTOTAL(crtc_vtotal - 1));
2878 }
2879
intel_set_transcoder_timings_lrr(const struct intel_crtc_state * crtc_state)2880 static void intel_set_transcoder_timings_lrr(const struct intel_crtc_state *crtc_state)
2881 {
2882 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2883 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2884 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2885 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
2886 u32 crtc_vdisplay, crtc_vtotal, crtc_vblank_start, crtc_vblank_end;
2887
2888 crtc_vdisplay = adjusted_mode->crtc_vdisplay;
2889 crtc_vtotal = adjusted_mode->crtc_vtotal;
2890 crtc_vblank_start = adjusted_mode->crtc_vblank_start;
2891 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
2892
2893 drm_WARN_ON(&dev_priv->drm, adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE);
2894
2895 /*
2896 * The hardware actually ignores TRANS_VBLANK.VBLANK_END in DP mode.
2897 * But let's write it anyway to keep the state checker happy.
2898 */
2899 intel_de_write(dev_priv, TRANS_VBLANK(dev_priv, cpu_transcoder),
2900 VBLANK_START(crtc_vblank_start - 1) |
2901 VBLANK_END(crtc_vblank_end - 1));
2902 /*
2903 * The double buffer latch point for TRANS_VTOTAL
2904 * is the transcoder's undelayed vblank.
2905 */
2906 intel_de_write(dev_priv, TRANS_VTOTAL(dev_priv, cpu_transcoder),
2907 VACTIVE(crtc_vdisplay - 1) |
2908 VTOTAL(crtc_vtotal - 1));
2909 }
2910
intel_set_pipe_src_size(const struct intel_crtc_state * crtc_state)2911 static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
2912 {
2913 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2914 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2915 int width = drm_rect_width(&crtc_state->pipe_src);
2916 int height = drm_rect_height(&crtc_state->pipe_src);
2917 enum pipe pipe = crtc->pipe;
2918
2919 /* pipesrc controls the size that is scaled from, which should
2920 * always be the user's requested size.
2921 */
2922 intel_de_write(dev_priv, PIPESRC(dev_priv, pipe),
2923 PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1));
2924 }
2925
intel_pipe_is_interlaced(const struct intel_crtc_state * crtc_state)2926 static bool intel_pipe_is_interlaced(const struct intel_crtc_state *crtc_state)
2927 {
2928 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2929 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2930
2931 if (DISPLAY_VER(dev_priv) == 2)
2932 return false;
2933
2934 if (DISPLAY_VER(dev_priv) >= 9 ||
2935 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
2936 return intel_de_read(dev_priv,
2937 TRANSCONF(dev_priv, cpu_transcoder)) & TRANSCONF_INTERLACE_MASK_HSW;
2938 else
2939 return intel_de_read(dev_priv,
2940 TRANSCONF(dev_priv, cpu_transcoder)) & TRANSCONF_INTERLACE_MASK;
2941 }
2942
intel_get_transcoder_timings(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)2943 static void intel_get_transcoder_timings(struct intel_crtc *crtc,
2944 struct intel_crtc_state *pipe_config)
2945 {
2946 struct drm_device *dev = crtc->base.dev;
2947 struct drm_i915_private *dev_priv = to_i915(dev);
2948 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
2949 struct drm_display_mode *adjusted_mode = &pipe_config->hw.adjusted_mode;
2950 u32 tmp;
2951
2952 tmp = intel_de_read(dev_priv, TRANS_HTOTAL(dev_priv, cpu_transcoder));
2953 adjusted_mode->crtc_hdisplay = REG_FIELD_GET(HACTIVE_MASK, tmp) + 1;
2954 adjusted_mode->crtc_htotal = REG_FIELD_GET(HTOTAL_MASK, tmp) + 1;
2955
2956 if (!transcoder_is_dsi(cpu_transcoder)) {
2957 tmp = intel_de_read(dev_priv,
2958 TRANS_HBLANK(dev_priv, cpu_transcoder));
2959 adjusted_mode->crtc_hblank_start = REG_FIELD_GET(HBLANK_START_MASK, tmp) + 1;
2960 adjusted_mode->crtc_hblank_end = REG_FIELD_GET(HBLANK_END_MASK, tmp) + 1;
2961 }
2962
2963 tmp = intel_de_read(dev_priv, TRANS_HSYNC(dev_priv, cpu_transcoder));
2964 adjusted_mode->crtc_hsync_start = REG_FIELD_GET(HSYNC_START_MASK, tmp) + 1;
2965 adjusted_mode->crtc_hsync_end = REG_FIELD_GET(HSYNC_END_MASK, tmp) + 1;
2966
2967 tmp = intel_de_read(dev_priv, TRANS_VTOTAL(dev_priv, cpu_transcoder));
2968 adjusted_mode->crtc_vdisplay = REG_FIELD_GET(VACTIVE_MASK, tmp) + 1;
2969 adjusted_mode->crtc_vtotal = REG_FIELD_GET(VTOTAL_MASK, tmp) + 1;
2970
2971 /* FIXME TGL+ DSI transcoders have this! */
2972 if (!transcoder_is_dsi(cpu_transcoder)) {
2973 tmp = intel_de_read(dev_priv,
2974 TRANS_VBLANK(dev_priv, cpu_transcoder));
2975 adjusted_mode->crtc_vblank_start = REG_FIELD_GET(VBLANK_START_MASK, tmp) + 1;
2976 adjusted_mode->crtc_vblank_end = REG_FIELD_GET(VBLANK_END_MASK, tmp) + 1;
2977 }
2978 tmp = intel_de_read(dev_priv, TRANS_VSYNC(dev_priv, cpu_transcoder));
2979 adjusted_mode->crtc_vsync_start = REG_FIELD_GET(VSYNC_START_MASK, tmp) + 1;
2980 adjusted_mode->crtc_vsync_end = REG_FIELD_GET(VSYNC_END_MASK, tmp) + 1;
2981
2982 if (intel_pipe_is_interlaced(pipe_config)) {
2983 adjusted_mode->flags |= DRM_MODE_FLAG_INTERLACE;
2984 adjusted_mode->crtc_vtotal += 1;
2985 adjusted_mode->crtc_vblank_end += 1;
2986 }
2987
2988 if (DISPLAY_VER(dev_priv) >= 13 && !transcoder_is_dsi(cpu_transcoder))
2989 adjusted_mode->crtc_vblank_start =
2990 adjusted_mode->crtc_vdisplay +
2991 intel_de_read(dev_priv,
2992 TRANS_SET_CONTEXT_LATENCY(dev_priv, cpu_transcoder));
2993 }
2994
intel_joiner_adjust_pipe_src(struct intel_crtc_state * crtc_state)2995 static void intel_joiner_adjust_pipe_src(struct intel_crtc_state *crtc_state)
2996 {
2997 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2998 int num_pipes = intel_crtc_num_joined_pipes(crtc_state);
2999 enum pipe primary_pipe, pipe = crtc->pipe;
3000 int width;
3001
3002 if (num_pipes == 1)
3003 return;
3004
3005 primary_pipe = joiner_primary_pipe(crtc_state);
3006 width = drm_rect_width(&crtc_state->pipe_src);
3007
3008 drm_rect_translate_to(&crtc_state->pipe_src,
3009 (pipe - primary_pipe) * width, 0);
3010 }
3011
intel_get_pipe_src_size(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)3012 static void intel_get_pipe_src_size(struct intel_crtc *crtc,
3013 struct intel_crtc_state *pipe_config)
3014 {
3015 struct drm_device *dev = crtc->base.dev;
3016 struct drm_i915_private *dev_priv = to_i915(dev);
3017 u32 tmp;
3018
3019 tmp = intel_de_read(dev_priv, PIPESRC(dev_priv, crtc->pipe));
3020
3021 drm_rect_init(&pipe_config->pipe_src, 0, 0,
3022 REG_FIELD_GET(PIPESRC_WIDTH_MASK, tmp) + 1,
3023 REG_FIELD_GET(PIPESRC_HEIGHT_MASK, tmp) + 1);
3024
3025 intel_joiner_adjust_pipe_src(pipe_config);
3026 }
3027
i9xx_set_pipeconf(const struct intel_crtc_state * crtc_state)3028 void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
3029 {
3030 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3031 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3032 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3033 u32 val = 0;
3034
3035 /*
3036 * - We keep both pipes enabled on 830
3037 * - During modeset the pipe is still disabled and must remain so
3038 * - During fastset the pipe is already enabled and must remain so
3039 */
3040 if (IS_I830(dev_priv) || !intel_crtc_needs_modeset(crtc_state))
3041 val |= TRANSCONF_ENABLE;
3042
3043 if (crtc_state->double_wide)
3044 val |= TRANSCONF_DOUBLE_WIDE;
3045
3046 /* only g4x and later have fancy bpc/dither controls */
3047 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
3048 IS_CHERRYVIEW(dev_priv)) {
3049 /* Bspec claims that we can't use dithering for 30bpp pipes. */
3050 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
3051 val |= TRANSCONF_DITHER_EN |
3052 TRANSCONF_DITHER_TYPE_SP;
3053
3054 switch (crtc_state->pipe_bpp) {
3055 default:
3056 /* Case prevented by intel_choose_pipe_bpp_dither. */
3057 MISSING_CASE(crtc_state->pipe_bpp);
3058 fallthrough;
3059 case 18:
3060 val |= TRANSCONF_BPC_6;
3061 break;
3062 case 24:
3063 val |= TRANSCONF_BPC_8;
3064 break;
3065 case 30:
3066 val |= TRANSCONF_BPC_10;
3067 break;
3068 }
3069 }
3070
3071 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
3072 if (DISPLAY_VER(dev_priv) < 4 ||
3073 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3074 val |= TRANSCONF_INTERLACE_W_FIELD_INDICATION;
3075 else
3076 val |= TRANSCONF_INTERLACE_W_SYNC_SHIFT;
3077 } else {
3078 val |= TRANSCONF_INTERLACE_PROGRESSIVE;
3079 }
3080
3081 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
3082 crtc_state->limited_color_range)
3083 val |= TRANSCONF_COLOR_RANGE_SELECT;
3084
3085 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
3086
3087 if (crtc_state->wgc_enable)
3088 val |= TRANSCONF_WGC_ENABLE;
3089
3090 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3091
3092 intel_de_write(dev_priv, TRANSCONF(dev_priv, cpu_transcoder), val);
3093 intel_de_posting_read(dev_priv, TRANSCONF(dev_priv, cpu_transcoder));
3094 }
3095
i9xx_has_pfit(struct drm_i915_private * dev_priv)3096 static bool i9xx_has_pfit(struct drm_i915_private *dev_priv)
3097 {
3098 if (IS_I830(dev_priv))
3099 return false;
3100
3101 return DISPLAY_VER(dev_priv) >= 4 ||
3102 IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
3103 }
3104
i9xx_get_pfit_config(struct intel_crtc_state * crtc_state)3105 static void i9xx_get_pfit_config(struct intel_crtc_state *crtc_state)
3106 {
3107 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3108 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3109 enum pipe pipe;
3110 u32 tmp;
3111
3112 if (!i9xx_has_pfit(dev_priv))
3113 return;
3114
3115 tmp = intel_de_read(dev_priv, PFIT_CONTROL(dev_priv));
3116 if (!(tmp & PFIT_ENABLE))
3117 return;
3118
3119 /* Check whether the pfit is attached to our pipe. */
3120 if (DISPLAY_VER(dev_priv) >= 4)
3121 pipe = REG_FIELD_GET(PFIT_PIPE_MASK, tmp);
3122 else
3123 pipe = PIPE_B;
3124
3125 if (pipe != crtc->pipe)
3126 return;
3127
3128 crtc_state->gmch_pfit.control = tmp;
3129 crtc_state->gmch_pfit.pgm_ratios =
3130 intel_de_read(dev_priv, PFIT_PGM_RATIOS(dev_priv));
3131 }
3132
3133 static enum intel_output_format
bdw_get_pipe_misc_output_format(struct intel_crtc * crtc)3134 bdw_get_pipe_misc_output_format(struct intel_crtc *crtc)
3135 {
3136 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3137 u32 tmp;
3138
3139 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
3140
3141 if (tmp & PIPE_MISC_YUV420_ENABLE) {
3142 /*
3143 * We support 4:2:0 in full blend mode only.
3144 * For xe3_lpd+ this is implied in YUV420 Enable bit.
3145 * Ensure the same for prior platforms in YUV420 Mode bit.
3146 */
3147 if (DISPLAY_VER(dev_priv) < 30)
3148 drm_WARN_ON(&dev_priv->drm,
3149 (tmp & PIPE_MISC_YUV420_MODE_FULL_BLEND) == 0);
3150
3151 return INTEL_OUTPUT_FORMAT_YCBCR420;
3152 } else if (tmp & PIPE_MISC_OUTPUT_COLORSPACE_YUV) {
3153 return INTEL_OUTPUT_FORMAT_YCBCR444;
3154 } else {
3155 return INTEL_OUTPUT_FORMAT_RGB;
3156 }
3157 }
3158
i9xx_get_pipe_config(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)3159 static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
3160 struct intel_crtc_state *pipe_config)
3161 {
3162 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3163 enum intel_display_power_domain power_domain;
3164 intel_wakeref_t wakeref;
3165 u32 tmp;
3166 bool ret;
3167
3168 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3169 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3170 if (!wakeref)
3171 return false;
3172
3173 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3174 pipe_config->sink_format = pipe_config->output_format;
3175 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3176 pipe_config->shared_dpll = NULL;
3177
3178 ret = false;
3179
3180 tmp = intel_de_read(dev_priv,
3181 TRANSCONF(dev_priv, pipe_config->cpu_transcoder));
3182 if (!(tmp & TRANSCONF_ENABLE))
3183 goto out;
3184
3185 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
3186 IS_CHERRYVIEW(dev_priv)) {
3187 switch (tmp & TRANSCONF_BPC_MASK) {
3188 case TRANSCONF_BPC_6:
3189 pipe_config->pipe_bpp = 18;
3190 break;
3191 case TRANSCONF_BPC_8:
3192 pipe_config->pipe_bpp = 24;
3193 break;
3194 case TRANSCONF_BPC_10:
3195 pipe_config->pipe_bpp = 30;
3196 break;
3197 default:
3198 MISSING_CASE(tmp);
3199 break;
3200 }
3201 }
3202
3203 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
3204 (tmp & TRANSCONF_COLOR_RANGE_SELECT))
3205 pipe_config->limited_color_range = true;
3206
3207 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_I9XX, tmp);
3208
3209 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
3210
3211 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
3212 (tmp & TRANSCONF_WGC_ENABLE))
3213 pipe_config->wgc_enable = true;
3214
3215 intel_color_get_config(pipe_config);
3216
3217 if (HAS_DOUBLE_WIDE(dev_priv))
3218 pipe_config->double_wide = tmp & TRANSCONF_DOUBLE_WIDE;
3219
3220 intel_get_transcoder_timings(crtc, pipe_config);
3221 intel_get_pipe_src_size(crtc, pipe_config);
3222
3223 i9xx_get_pfit_config(pipe_config);
3224
3225 i9xx_dpll_get_hw_state(crtc, &pipe_config->dpll_hw_state);
3226
3227 if (DISPLAY_VER(dev_priv) >= 4) {
3228 tmp = pipe_config->dpll_hw_state.i9xx.dpll_md;
3229 pipe_config->pixel_multiplier =
3230 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
3231 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
3232 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
3233 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
3234 tmp = pipe_config->dpll_hw_state.i9xx.dpll;
3235 pipe_config->pixel_multiplier =
3236 ((tmp & SDVO_MULTIPLIER_MASK)
3237 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
3238 } else {
3239 /* Note that on i915G/GM the pixel multiplier is in the sdvo
3240 * port and will be fixed up in the encoder->get_config
3241 * function. */
3242 pipe_config->pixel_multiplier = 1;
3243 }
3244
3245 if (IS_CHERRYVIEW(dev_priv))
3246 chv_crtc_clock_get(pipe_config);
3247 else if (IS_VALLEYVIEW(dev_priv))
3248 vlv_crtc_clock_get(pipe_config);
3249 else
3250 i9xx_crtc_clock_get(pipe_config);
3251
3252 /*
3253 * Normally the dotclock is filled in by the encoder .get_config()
3254 * but in case the pipe is enabled w/o any ports we need a sane
3255 * default.
3256 */
3257 pipe_config->hw.adjusted_mode.crtc_clock =
3258 pipe_config->port_clock / pipe_config->pixel_multiplier;
3259
3260 ret = true;
3261
3262 out:
3263 intel_display_power_put(dev_priv, power_domain, wakeref);
3264
3265 return ret;
3266 }
3267
ilk_set_pipeconf(const struct intel_crtc_state * crtc_state)3268 void ilk_set_pipeconf(const struct intel_crtc_state *crtc_state)
3269 {
3270 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3271 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3272 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3273 u32 val = 0;
3274
3275 /*
3276 * - During modeset the pipe is still disabled and must remain so
3277 * - During fastset the pipe is already enabled and must remain so
3278 */
3279 if (!intel_crtc_needs_modeset(crtc_state))
3280 val |= TRANSCONF_ENABLE;
3281
3282 switch (crtc_state->pipe_bpp) {
3283 default:
3284 /* Case prevented by intel_choose_pipe_bpp_dither. */
3285 MISSING_CASE(crtc_state->pipe_bpp);
3286 fallthrough;
3287 case 18:
3288 val |= TRANSCONF_BPC_6;
3289 break;
3290 case 24:
3291 val |= TRANSCONF_BPC_8;
3292 break;
3293 case 30:
3294 val |= TRANSCONF_BPC_10;
3295 break;
3296 case 36:
3297 val |= TRANSCONF_BPC_12;
3298 break;
3299 }
3300
3301 if (crtc_state->dither)
3302 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3303
3304 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3305 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3306 else
3307 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3308
3309 /*
3310 * This would end up with an odd purple hue over
3311 * the entire display. Make sure we don't do it.
3312 */
3313 drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range &&
3314 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB);
3315
3316 if (crtc_state->limited_color_range &&
3317 !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
3318 val |= TRANSCONF_COLOR_RANGE_SELECT;
3319
3320 if (crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3321 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV709;
3322
3323 val |= TRANSCONF_GAMMA_MODE(crtc_state->gamma_mode);
3324
3325 val |= TRANSCONF_FRAME_START_DELAY(crtc_state->framestart_delay - 1);
3326 val |= TRANSCONF_MSA_TIMING_DELAY(crtc_state->msa_timing_delay);
3327
3328 intel_de_write(dev_priv, TRANSCONF(dev_priv, cpu_transcoder), val);
3329 intel_de_posting_read(dev_priv, TRANSCONF(dev_priv, cpu_transcoder));
3330 }
3331
hsw_set_transconf(const struct intel_crtc_state * crtc_state)3332 static void hsw_set_transconf(const struct intel_crtc_state *crtc_state)
3333 {
3334 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3335 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3336 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
3337 u32 val = 0;
3338
3339 /*
3340 * - During modeset the pipe is still disabled and must remain so
3341 * - During fastset the pipe is already enabled and must remain so
3342 */
3343 if (!intel_crtc_needs_modeset(crtc_state))
3344 val |= TRANSCONF_ENABLE;
3345
3346 if (IS_HASWELL(dev_priv) && crtc_state->dither)
3347 val |= TRANSCONF_DITHER_EN | TRANSCONF_DITHER_TYPE_SP;
3348
3349 if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
3350 val |= TRANSCONF_INTERLACE_IF_ID_ILK;
3351 else
3352 val |= TRANSCONF_INTERLACE_PF_PD_ILK;
3353
3354 if (IS_HASWELL(dev_priv) &&
3355 crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB)
3356 val |= TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW;
3357
3358 intel_de_write(dev_priv, TRANSCONF(dev_priv, cpu_transcoder), val);
3359 intel_de_posting_read(dev_priv, TRANSCONF(dev_priv, cpu_transcoder));
3360 }
3361
bdw_set_pipe_misc(struct intel_dsb * dsb,const struct intel_crtc_state * crtc_state)3362 static void bdw_set_pipe_misc(struct intel_dsb *dsb,
3363 const struct intel_crtc_state *crtc_state)
3364 {
3365 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3366 struct intel_display *display = to_intel_display(crtc->base.dev);
3367 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3368 u32 val = 0;
3369
3370 switch (crtc_state->pipe_bpp) {
3371 case 18:
3372 val |= PIPE_MISC_BPC_6;
3373 break;
3374 case 24:
3375 val |= PIPE_MISC_BPC_8;
3376 break;
3377 case 30:
3378 val |= PIPE_MISC_BPC_10;
3379 break;
3380 case 36:
3381 /* Port output 12BPC defined for ADLP+ */
3382 if (DISPLAY_VER(dev_priv) >= 13)
3383 val |= PIPE_MISC_BPC_12_ADLP;
3384 break;
3385 default:
3386 MISSING_CASE(crtc_state->pipe_bpp);
3387 break;
3388 }
3389
3390 if (crtc_state->dither)
3391 val |= PIPE_MISC_DITHER_ENABLE | PIPE_MISC_DITHER_TYPE_SP;
3392
3393 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
3394 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
3395 val |= PIPE_MISC_OUTPUT_COLORSPACE_YUV;
3396
3397 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
3398 val |= DISPLAY_VER(display) >= 30 ? PIPE_MISC_YUV420_ENABLE :
3399 PIPE_MISC_YUV420_ENABLE | PIPE_MISC_YUV420_MODE_FULL_BLEND;
3400
3401 if (DISPLAY_VER(dev_priv) >= 11 && is_hdr_mode(crtc_state))
3402 val |= PIPE_MISC_HDR_MODE_PRECISION;
3403
3404 if (DISPLAY_VER(dev_priv) >= 12)
3405 val |= PIPE_MISC_PIXEL_ROUNDING_TRUNC;
3406
3407 /* allow PSR with sprite enabled */
3408 if (IS_BROADWELL(dev_priv))
3409 val |= PIPE_MISC_PSR_MASK_SPRITE_ENABLE;
3410
3411 intel_de_write_dsb(display, dsb, PIPE_MISC(crtc->pipe), val);
3412 }
3413
bdw_get_pipe_misc_bpp(struct intel_crtc * crtc)3414 int bdw_get_pipe_misc_bpp(struct intel_crtc *crtc)
3415 {
3416 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3417 u32 tmp;
3418
3419 tmp = intel_de_read(dev_priv, PIPE_MISC(crtc->pipe));
3420
3421 switch (tmp & PIPE_MISC_BPC_MASK) {
3422 case PIPE_MISC_BPC_6:
3423 return 18;
3424 case PIPE_MISC_BPC_8:
3425 return 24;
3426 case PIPE_MISC_BPC_10:
3427 return 30;
3428 /*
3429 * PORT OUTPUT 12 BPC defined for ADLP+.
3430 *
3431 * TODO:
3432 * For previous platforms with DSI interface, bits 5:7
3433 * are used for storing pipe_bpp irrespective of dithering.
3434 * Since the value of 12 BPC is not defined for these bits
3435 * on older platforms, need to find a workaround for 12 BPC
3436 * MIPI DSI HW readout.
3437 */
3438 case PIPE_MISC_BPC_12_ADLP:
3439 if (DISPLAY_VER(dev_priv) >= 13)
3440 return 36;
3441 fallthrough;
3442 default:
3443 MISSING_CASE(tmp);
3444 return 0;
3445 }
3446 }
3447
ilk_get_lanes_required(int target_clock,int link_bw,int bpp)3448 int ilk_get_lanes_required(int target_clock, int link_bw, int bpp)
3449 {
3450 /*
3451 * Account for spread spectrum to avoid
3452 * oversubscribing the link. Max center spread
3453 * is 2.5%; use 5% for safety's sake.
3454 */
3455 u32 bps = target_clock * bpp * 21 / 20;
3456 return DIV_ROUND_UP(bps, link_bw * 8);
3457 }
3458
intel_get_m_n(struct drm_i915_private * i915,struct intel_link_m_n * m_n,i915_reg_t data_m_reg,i915_reg_t data_n_reg,i915_reg_t link_m_reg,i915_reg_t link_n_reg)3459 void intel_get_m_n(struct drm_i915_private *i915,
3460 struct intel_link_m_n *m_n,
3461 i915_reg_t data_m_reg, i915_reg_t data_n_reg,
3462 i915_reg_t link_m_reg, i915_reg_t link_n_reg)
3463 {
3464 m_n->link_m = intel_de_read(i915, link_m_reg) & DATA_LINK_M_N_MASK;
3465 m_n->link_n = intel_de_read(i915, link_n_reg) & DATA_LINK_M_N_MASK;
3466 m_n->data_m = intel_de_read(i915, data_m_reg) & DATA_LINK_M_N_MASK;
3467 m_n->data_n = intel_de_read(i915, data_n_reg) & DATA_LINK_M_N_MASK;
3468 m_n->tu = REG_FIELD_GET(TU_SIZE_MASK, intel_de_read(i915, data_m_reg)) + 1;
3469 }
3470
intel_cpu_transcoder_get_m1_n1(struct intel_crtc * crtc,enum transcoder transcoder,struct intel_link_m_n * m_n)3471 void intel_cpu_transcoder_get_m1_n1(struct intel_crtc *crtc,
3472 enum transcoder transcoder,
3473 struct intel_link_m_n *m_n)
3474 {
3475 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3476 enum pipe pipe = crtc->pipe;
3477
3478 if (DISPLAY_VER(dev_priv) >= 5)
3479 intel_get_m_n(dev_priv, m_n,
3480 PIPE_DATA_M1(dev_priv, transcoder),
3481 PIPE_DATA_N1(dev_priv, transcoder),
3482 PIPE_LINK_M1(dev_priv, transcoder),
3483 PIPE_LINK_N1(dev_priv, transcoder));
3484 else
3485 intel_get_m_n(dev_priv, m_n,
3486 PIPE_DATA_M_G4X(pipe), PIPE_DATA_N_G4X(pipe),
3487 PIPE_LINK_M_G4X(pipe), PIPE_LINK_N_G4X(pipe));
3488 }
3489
intel_cpu_transcoder_get_m2_n2(struct intel_crtc * crtc,enum transcoder transcoder,struct intel_link_m_n * m_n)3490 void intel_cpu_transcoder_get_m2_n2(struct intel_crtc *crtc,
3491 enum transcoder transcoder,
3492 struct intel_link_m_n *m_n)
3493 {
3494 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3495
3496 if (!intel_cpu_transcoder_has_m2_n2(dev_priv, transcoder))
3497 return;
3498
3499 intel_get_m_n(dev_priv, m_n,
3500 PIPE_DATA_M2(dev_priv, transcoder),
3501 PIPE_DATA_N2(dev_priv, transcoder),
3502 PIPE_LINK_M2(dev_priv, transcoder),
3503 PIPE_LINK_N2(dev_priv, transcoder));
3504 }
3505
ilk_get_pfit_config(struct intel_crtc_state * crtc_state)3506 static void ilk_get_pfit_config(struct intel_crtc_state *crtc_state)
3507 {
3508 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
3509 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3510 u32 ctl, pos, size;
3511 enum pipe pipe;
3512
3513 ctl = intel_de_read(dev_priv, PF_CTL(crtc->pipe));
3514 if ((ctl & PF_ENABLE) == 0)
3515 return;
3516
3517 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
3518 pipe = REG_FIELD_GET(PF_PIPE_SEL_MASK_IVB, ctl);
3519 else
3520 pipe = crtc->pipe;
3521
3522 crtc_state->pch_pfit.enabled = true;
3523
3524 pos = intel_de_read(dev_priv, PF_WIN_POS(crtc->pipe));
3525 size = intel_de_read(dev_priv, PF_WIN_SZ(crtc->pipe));
3526
3527 drm_rect_init(&crtc_state->pch_pfit.dst,
3528 REG_FIELD_GET(PF_WIN_XPOS_MASK, pos),
3529 REG_FIELD_GET(PF_WIN_YPOS_MASK, pos),
3530 REG_FIELD_GET(PF_WIN_XSIZE_MASK, size),
3531 REG_FIELD_GET(PF_WIN_YSIZE_MASK, size));
3532
3533 /*
3534 * We currently do not free assignements of panel fitters on
3535 * ivb/hsw (since we don't use the higher upscaling modes which
3536 * differentiates them) so just WARN about this case for now.
3537 */
3538 drm_WARN_ON(&dev_priv->drm, pipe != crtc->pipe);
3539 }
3540
ilk_get_pipe_config(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)3541 static bool ilk_get_pipe_config(struct intel_crtc *crtc,
3542 struct intel_crtc_state *pipe_config)
3543 {
3544 struct drm_device *dev = crtc->base.dev;
3545 struct drm_i915_private *dev_priv = to_i915(dev);
3546 enum intel_display_power_domain power_domain;
3547 intel_wakeref_t wakeref;
3548 u32 tmp;
3549 bool ret;
3550
3551 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
3552 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3553 if (!wakeref)
3554 return false;
3555
3556 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
3557 pipe_config->shared_dpll = NULL;
3558
3559 ret = false;
3560 tmp = intel_de_read(dev_priv,
3561 TRANSCONF(dev_priv, pipe_config->cpu_transcoder));
3562 if (!(tmp & TRANSCONF_ENABLE))
3563 goto out;
3564
3565 switch (tmp & TRANSCONF_BPC_MASK) {
3566 case TRANSCONF_BPC_6:
3567 pipe_config->pipe_bpp = 18;
3568 break;
3569 case TRANSCONF_BPC_8:
3570 pipe_config->pipe_bpp = 24;
3571 break;
3572 case TRANSCONF_BPC_10:
3573 pipe_config->pipe_bpp = 30;
3574 break;
3575 case TRANSCONF_BPC_12:
3576 pipe_config->pipe_bpp = 36;
3577 break;
3578 default:
3579 break;
3580 }
3581
3582 if (tmp & TRANSCONF_COLOR_RANGE_SELECT)
3583 pipe_config->limited_color_range = true;
3584
3585 switch (tmp & TRANSCONF_OUTPUT_COLORSPACE_MASK) {
3586 case TRANSCONF_OUTPUT_COLORSPACE_YUV601:
3587 case TRANSCONF_OUTPUT_COLORSPACE_YUV709:
3588 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
3589 break;
3590 default:
3591 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
3592 break;
3593 }
3594
3595 pipe_config->sink_format = pipe_config->output_format;
3596
3597 pipe_config->gamma_mode = REG_FIELD_GET(TRANSCONF_GAMMA_MODE_MASK_ILK, tmp);
3598
3599 pipe_config->framestart_delay = REG_FIELD_GET(TRANSCONF_FRAME_START_DELAY_MASK, tmp) + 1;
3600
3601 pipe_config->msa_timing_delay = REG_FIELD_GET(TRANSCONF_MSA_TIMING_DELAY_MASK, tmp);
3602
3603 intel_color_get_config(pipe_config);
3604
3605 pipe_config->pixel_multiplier = 1;
3606
3607 ilk_pch_get_config(pipe_config);
3608
3609 intel_get_transcoder_timings(crtc, pipe_config);
3610 intel_get_pipe_src_size(crtc, pipe_config);
3611
3612 ilk_get_pfit_config(pipe_config);
3613
3614 ret = true;
3615
3616 out:
3617 intel_display_power_put(dev_priv, power_domain, wakeref);
3618
3619 return ret;
3620 }
3621
joiner_pipes(struct drm_i915_private * i915)3622 static u8 joiner_pipes(struct drm_i915_private *i915)
3623 {
3624 u8 pipes;
3625
3626 if (DISPLAY_VER(i915) >= 12)
3627 pipes = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D);
3628 else if (DISPLAY_VER(i915) >= 11)
3629 pipes = BIT(PIPE_B) | BIT(PIPE_C);
3630 else
3631 pipes = 0;
3632
3633 return pipes & DISPLAY_RUNTIME_INFO(i915)->pipe_mask;
3634 }
3635
transcoder_ddi_func_is_enabled(struct drm_i915_private * dev_priv,enum transcoder cpu_transcoder)3636 static bool transcoder_ddi_func_is_enabled(struct drm_i915_private *dev_priv,
3637 enum transcoder cpu_transcoder)
3638 {
3639 enum intel_display_power_domain power_domain;
3640 intel_wakeref_t wakeref;
3641 u32 tmp = 0;
3642
3643 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3644
3645 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3646 tmp = intel_de_read(dev_priv,
3647 TRANS_DDI_FUNC_CTL(dev_priv, cpu_transcoder));
3648
3649 return tmp & TRANS_DDI_FUNC_ENABLE;
3650 }
3651
enabled_uncompressed_joiner_pipes(struct intel_display * display,u8 * primary_pipes,u8 * secondary_pipes)3652 static void enabled_uncompressed_joiner_pipes(struct intel_display *display,
3653 u8 *primary_pipes, u8 *secondary_pipes)
3654 {
3655 struct drm_i915_private *i915 = to_i915(display->drm);
3656 struct intel_crtc *crtc;
3657
3658 *primary_pipes = 0;
3659 *secondary_pipes = 0;
3660
3661 if (!HAS_UNCOMPRESSED_JOINER(display))
3662 return;
3663
3664 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc,
3665 joiner_pipes(i915)) {
3666 enum intel_display_power_domain power_domain;
3667 enum pipe pipe = crtc->pipe;
3668 intel_wakeref_t wakeref;
3669
3670 power_domain = POWER_DOMAIN_PIPE(pipe);
3671 with_intel_display_power_if_enabled(i915, power_domain, wakeref) {
3672 u32 tmp = intel_de_read(display, ICL_PIPE_DSS_CTL1(pipe));
3673
3674 if (tmp & UNCOMPRESSED_JOINER_PRIMARY)
3675 *primary_pipes |= BIT(pipe);
3676 if (tmp & UNCOMPRESSED_JOINER_SECONDARY)
3677 *secondary_pipes |= BIT(pipe);
3678 }
3679 }
3680 }
3681
enabled_bigjoiner_pipes(struct intel_display * display,u8 * primary_pipes,u8 * secondary_pipes)3682 static void enabled_bigjoiner_pipes(struct intel_display *display,
3683 u8 *primary_pipes, u8 *secondary_pipes)
3684 {
3685 struct drm_i915_private *i915 = to_i915(display->drm);
3686 struct intel_crtc *crtc;
3687
3688 *primary_pipes = 0;
3689 *secondary_pipes = 0;
3690
3691 if (!HAS_BIGJOINER(display))
3692 return;
3693
3694 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc,
3695 joiner_pipes(i915)) {
3696 enum intel_display_power_domain power_domain;
3697 enum pipe pipe = crtc->pipe;
3698 intel_wakeref_t wakeref;
3699
3700 power_domain = intel_dsc_power_domain(crtc, (enum transcoder)pipe);
3701 with_intel_display_power_if_enabled(i915, power_domain, wakeref) {
3702 u32 tmp = intel_de_read(display, ICL_PIPE_DSS_CTL1(pipe));
3703
3704 if (!(tmp & BIG_JOINER_ENABLE))
3705 continue;
3706
3707 if (tmp & PRIMARY_BIG_JOINER_ENABLE)
3708 *primary_pipes |= BIT(pipe);
3709 else
3710 *secondary_pipes |= BIT(pipe);
3711 }
3712 }
3713 }
3714
expected_secondary_pipes(u8 primary_pipes,int num_pipes)3715 static u8 expected_secondary_pipes(u8 primary_pipes, int num_pipes)
3716 {
3717 u8 secondary_pipes = 0;
3718
3719 for (int i = 1; i < num_pipes; i++)
3720 secondary_pipes |= primary_pipes << i;
3721
3722 return secondary_pipes;
3723 }
3724
expected_uncompressed_joiner_secondary_pipes(u8 uncompjoiner_primary_pipes)3725 static u8 expected_uncompressed_joiner_secondary_pipes(u8 uncompjoiner_primary_pipes)
3726 {
3727 return expected_secondary_pipes(uncompjoiner_primary_pipes, 2);
3728 }
3729
expected_bigjoiner_secondary_pipes(u8 bigjoiner_primary_pipes)3730 static u8 expected_bigjoiner_secondary_pipes(u8 bigjoiner_primary_pipes)
3731 {
3732 return expected_secondary_pipes(bigjoiner_primary_pipes, 2);
3733 }
3734
get_joiner_primary_pipe(enum pipe pipe,u8 primary_pipes)3735 static u8 get_joiner_primary_pipe(enum pipe pipe, u8 primary_pipes)
3736 {
3737 primary_pipes &= GENMASK(pipe, 0);
3738
3739 return primary_pipes ? BIT(fls(primary_pipes) - 1) : 0;
3740 }
3741
expected_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes)3742 static u8 expected_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes)
3743 {
3744 return expected_secondary_pipes(ultrajoiner_primary_pipes, 4);
3745 }
3746
fixup_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes,u8 ultrajoiner_secondary_pipes)3747 static u8 fixup_ultrajoiner_secondary_pipes(u8 ultrajoiner_primary_pipes,
3748 u8 ultrajoiner_secondary_pipes)
3749 {
3750 return ultrajoiner_secondary_pipes | ultrajoiner_primary_pipes << 3;
3751 }
3752
enabled_ultrajoiner_pipes(struct drm_i915_private * i915,u8 * primary_pipes,u8 * secondary_pipes)3753 static void enabled_ultrajoiner_pipes(struct drm_i915_private *i915,
3754 u8 *primary_pipes, u8 *secondary_pipes)
3755 {
3756 struct intel_display *display = &i915->display;
3757 struct intel_crtc *crtc;
3758
3759 *primary_pipes = 0;
3760 *secondary_pipes = 0;
3761
3762 if (!HAS_ULTRAJOINER(display))
3763 return;
3764
3765 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc,
3766 joiner_pipes(i915)) {
3767 enum intel_display_power_domain power_domain;
3768 enum pipe pipe = crtc->pipe;
3769 intel_wakeref_t wakeref;
3770
3771 power_domain = intel_dsc_power_domain(crtc, (enum transcoder)pipe);
3772 with_intel_display_power_if_enabled(i915, power_domain, wakeref) {
3773 u32 tmp = intel_de_read(i915, ICL_PIPE_DSS_CTL1(pipe));
3774
3775 if (!(tmp & ULTRA_JOINER_ENABLE))
3776 continue;
3777
3778 if (tmp & PRIMARY_ULTRA_JOINER_ENABLE)
3779 *primary_pipes |= BIT(pipe);
3780 else
3781 *secondary_pipes |= BIT(pipe);
3782 }
3783 }
3784 }
3785
enabled_joiner_pipes(struct drm_i915_private * dev_priv,enum pipe pipe,u8 * primary_pipe,u8 * secondary_pipes)3786 static void enabled_joiner_pipes(struct drm_i915_private *dev_priv,
3787 enum pipe pipe,
3788 u8 *primary_pipe, u8 *secondary_pipes)
3789 {
3790 struct intel_display *display = to_intel_display(&dev_priv->drm);
3791 u8 primary_ultrajoiner_pipes;
3792 u8 primary_uncompressed_joiner_pipes, primary_bigjoiner_pipes;
3793 u8 secondary_ultrajoiner_pipes;
3794 u8 secondary_uncompressed_joiner_pipes, secondary_bigjoiner_pipes;
3795 u8 ultrajoiner_pipes;
3796 u8 uncompressed_joiner_pipes, bigjoiner_pipes;
3797
3798 enabled_ultrajoiner_pipes(dev_priv, &primary_ultrajoiner_pipes,
3799 &secondary_ultrajoiner_pipes);
3800 /*
3801 * For some strange reason the last pipe in the set of four
3802 * shouldn't have ultrajoiner enable bit set in hardware.
3803 * Set the bit anyway to make life easier.
3804 */
3805 drm_WARN_ON(&dev_priv->drm,
3806 expected_secondary_pipes(primary_ultrajoiner_pipes, 3) !=
3807 secondary_ultrajoiner_pipes);
3808 secondary_ultrajoiner_pipes =
3809 fixup_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes,
3810 secondary_ultrajoiner_pipes);
3811
3812 drm_WARN_ON(&dev_priv->drm, (primary_ultrajoiner_pipes & secondary_ultrajoiner_pipes) != 0);
3813
3814 enabled_uncompressed_joiner_pipes(display, &primary_uncompressed_joiner_pipes,
3815 &secondary_uncompressed_joiner_pipes);
3816
3817 drm_WARN_ON(display->drm,
3818 (primary_uncompressed_joiner_pipes & secondary_uncompressed_joiner_pipes) != 0);
3819
3820 enabled_bigjoiner_pipes(display, &primary_bigjoiner_pipes,
3821 &secondary_bigjoiner_pipes);
3822
3823 drm_WARN_ON(display->drm,
3824 (primary_bigjoiner_pipes & secondary_bigjoiner_pipes) != 0);
3825
3826 ultrajoiner_pipes = primary_ultrajoiner_pipes | secondary_ultrajoiner_pipes;
3827 uncompressed_joiner_pipes = primary_uncompressed_joiner_pipes |
3828 secondary_uncompressed_joiner_pipes;
3829 bigjoiner_pipes = primary_bigjoiner_pipes | secondary_bigjoiner_pipes;
3830
3831 drm_WARN(display->drm, (ultrajoiner_pipes & bigjoiner_pipes) != ultrajoiner_pipes,
3832 "Ultrajoiner pipes(%#x) should be bigjoiner pipes(%#x)\n",
3833 ultrajoiner_pipes, bigjoiner_pipes);
3834
3835 drm_WARN(display->drm, secondary_ultrajoiner_pipes !=
3836 expected_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes),
3837 "Wrong secondary ultrajoiner pipes(expected %#x, current %#x)\n",
3838 expected_ultrajoiner_secondary_pipes(primary_ultrajoiner_pipes),
3839 secondary_ultrajoiner_pipes);
3840
3841 drm_WARN(display->drm, (uncompressed_joiner_pipes & bigjoiner_pipes) != 0,
3842 "Uncompressed joiner pipes(%#x) and bigjoiner pipes(%#x) can't intersect\n",
3843 uncompressed_joiner_pipes, bigjoiner_pipes);
3844
3845 drm_WARN(display->drm, secondary_bigjoiner_pipes !=
3846 expected_bigjoiner_secondary_pipes(primary_bigjoiner_pipes),
3847 "Wrong secondary bigjoiner pipes(expected %#x, current %#x)\n",
3848 expected_bigjoiner_secondary_pipes(primary_bigjoiner_pipes),
3849 secondary_bigjoiner_pipes);
3850
3851 drm_WARN(display->drm, secondary_uncompressed_joiner_pipes !=
3852 expected_uncompressed_joiner_secondary_pipes(primary_uncompressed_joiner_pipes),
3853 "Wrong secondary uncompressed joiner pipes(expected %#x, current %#x)\n",
3854 expected_uncompressed_joiner_secondary_pipes(primary_uncompressed_joiner_pipes),
3855 secondary_uncompressed_joiner_pipes);
3856
3857 *primary_pipe = 0;
3858 *secondary_pipes = 0;
3859
3860 if (ultrajoiner_pipes & BIT(pipe)) {
3861 *primary_pipe = get_joiner_primary_pipe(pipe, primary_ultrajoiner_pipes);
3862 *secondary_pipes = secondary_ultrajoiner_pipes &
3863 expected_ultrajoiner_secondary_pipes(*primary_pipe);
3864
3865 drm_WARN(display->drm,
3866 expected_ultrajoiner_secondary_pipes(*primary_pipe) !=
3867 *secondary_pipes,
3868 "Wrong ultrajoiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n",
3869 *primary_pipe,
3870 expected_ultrajoiner_secondary_pipes(*primary_pipe),
3871 *secondary_pipes);
3872 return;
3873 }
3874
3875 if (uncompressed_joiner_pipes & BIT(pipe)) {
3876 *primary_pipe = get_joiner_primary_pipe(pipe, primary_uncompressed_joiner_pipes);
3877 *secondary_pipes = secondary_uncompressed_joiner_pipes &
3878 expected_uncompressed_joiner_secondary_pipes(*primary_pipe);
3879
3880 drm_WARN(display->drm,
3881 expected_uncompressed_joiner_secondary_pipes(*primary_pipe) !=
3882 *secondary_pipes,
3883 "Wrong uncompressed joiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n",
3884 *primary_pipe,
3885 expected_uncompressed_joiner_secondary_pipes(*primary_pipe),
3886 *secondary_pipes);
3887 return;
3888 }
3889
3890 if (bigjoiner_pipes & BIT(pipe)) {
3891 *primary_pipe = get_joiner_primary_pipe(pipe, primary_bigjoiner_pipes);
3892 *secondary_pipes = secondary_bigjoiner_pipes &
3893 expected_bigjoiner_secondary_pipes(*primary_pipe);
3894
3895 drm_WARN(display->drm,
3896 expected_bigjoiner_secondary_pipes(*primary_pipe) !=
3897 *secondary_pipes,
3898 "Wrong bigjoiner secondary pipes for primary_pipe %#x (expected %#x, current %#x)\n",
3899 *primary_pipe,
3900 expected_bigjoiner_secondary_pipes(*primary_pipe),
3901 *secondary_pipes);
3902 return;
3903 }
3904 }
3905
hsw_panel_transcoders(struct drm_i915_private * i915)3906 static u8 hsw_panel_transcoders(struct drm_i915_private *i915)
3907 {
3908 u8 panel_transcoder_mask = BIT(TRANSCODER_EDP);
3909
3910 if (DISPLAY_VER(i915) >= 11)
3911 panel_transcoder_mask |= BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
3912
3913 return panel_transcoder_mask;
3914 }
3915
hsw_enabled_transcoders(struct intel_crtc * crtc)3916 static u8 hsw_enabled_transcoders(struct intel_crtc *crtc)
3917 {
3918 struct drm_device *dev = crtc->base.dev;
3919 struct drm_i915_private *dev_priv = to_i915(dev);
3920 u8 panel_transcoder_mask = hsw_panel_transcoders(dev_priv);
3921 enum transcoder cpu_transcoder;
3922 u8 primary_pipe, secondary_pipes;
3923 u8 enabled_transcoders = 0;
3924
3925 /*
3926 * XXX: Do intel_display_power_get_if_enabled before reading this (for
3927 * consistency and less surprising code; it's in always on power).
3928 */
3929 for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder,
3930 panel_transcoder_mask) {
3931 enum intel_display_power_domain power_domain;
3932 intel_wakeref_t wakeref;
3933 enum pipe trans_pipe;
3934 u32 tmp = 0;
3935
3936 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
3937 with_intel_display_power_if_enabled(dev_priv, power_domain, wakeref)
3938 tmp = intel_de_read(dev_priv,
3939 TRANS_DDI_FUNC_CTL(dev_priv, cpu_transcoder));
3940
3941 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
3942 continue;
3943
3944 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
3945 default:
3946 drm_WARN(dev, 1,
3947 "unknown pipe linked to transcoder %s\n",
3948 transcoder_name(cpu_transcoder));
3949 fallthrough;
3950 case TRANS_DDI_EDP_INPUT_A_ONOFF:
3951 case TRANS_DDI_EDP_INPUT_A_ON:
3952 trans_pipe = PIPE_A;
3953 break;
3954 case TRANS_DDI_EDP_INPUT_B_ONOFF:
3955 trans_pipe = PIPE_B;
3956 break;
3957 case TRANS_DDI_EDP_INPUT_C_ONOFF:
3958 trans_pipe = PIPE_C;
3959 break;
3960 case TRANS_DDI_EDP_INPUT_D_ONOFF:
3961 trans_pipe = PIPE_D;
3962 break;
3963 }
3964
3965 if (trans_pipe == crtc->pipe)
3966 enabled_transcoders |= BIT(cpu_transcoder);
3967 }
3968
3969 /* single pipe or joiner primary */
3970 cpu_transcoder = (enum transcoder) crtc->pipe;
3971 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3972 enabled_transcoders |= BIT(cpu_transcoder);
3973
3974 /* joiner secondary -> consider the primary pipe's transcoder as well */
3975 enabled_joiner_pipes(dev_priv, crtc->pipe, &primary_pipe, &secondary_pipes);
3976 if (secondary_pipes & BIT(crtc->pipe)) {
3977 cpu_transcoder = (enum transcoder)ffs(primary_pipe) - 1;
3978 if (transcoder_ddi_func_is_enabled(dev_priv, cpu_transcoder))
3979 enabled_transcoders |= BIT(cpu_transcoder);
3980 }
3981
3982 return enabled_transcoders;
3983 }
3984
has_edp_transcoders(u8 enabled_transcoders)3985 static bool has_edp_transcoders(u8 enabled_transcoders)
3986 {
3987 return enabled_transcoders & BIT(TRANSCODER_EDP);
3988 }
3989
has_dsi_transcoders(u8 enabled_transcoders)3990 static bool has_dsi_transcoders(u8 enabled_transcoders)
3991 {
3992 return enabled_transcoders & (BIT(TRANSCODER_DSI_0) |
3993 BIT(TRANSCODER_DSI_1));
3994 }
3995
has_pipe_transcoders(u8 enabled_transcoders)3996 static bool has_pipe_transcoders(u8 enabled_transcoders)
3997 {
3998 return enabled_transcoders & ~(BIT(TRANSCODER_EDP) |
3999 BIT(TRANSCODER_DSI_0) |
4000 BIT(TRANSCODER_DSI_1));
4001 }
4002
assert_enabled_transcoders(struct drm_i915_private * i915,u8 enabled_transcoders)4003 static void assert_enabled_transcoders(struct drm_i915_private *i915,
4004 u8 enabled_transcoders)
4005 {
4006 /* Only one type of transcoder please */
4007 drm_WARN_ON(&i915->drm,
4008 has_edp_transcoders(enabled_transcoders) +
4009 has_dsi_transcoders(enabled_transcoders) +
4010 has_pipe_transcoders(enabled_transcoders) > 1);
4011
4012 /* Only DSI transcoders can be ganged */
4013 drm_WARN_ON(&i915->drm,
4014 !has_dsi_transcoders(enabled_transcoders) &&
4015 !is_power_of_2(enabled_transcoders));
4016 }
4017
hsw_get_transcoder_state(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config,struct intel_display_power_domain_set * power_domain_set)4018 static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
4019 struct intel_crtc_state *pipe_config,
4020 struct intel_display_power_domain_set *power_domain_set)
4021 {
4022 struct drm_device *dev = crtc->base.dev;
4023 struct drm_i915_private *dev_priv = to_i915(dev);
4024 unsigned long enabled_transcoders;
4025 u32 tmp;
4026
4027 enabled_transcoders = hsw_enabled_transcoders(crtc);
4028 if (!enabled_transcoders)
4029 return false;
4030
4031 assert_enabled_transcoders(dev_priv, enabled_transcoders);
4032
4033 /*
4034 * With the exception of DSI we should only ever have
4035 * a single enabled transcoder. With DSI let's just
4036 * pick the first one.
4037 */
4038 pipe_config->cpu_transcoder = ffs(enabled_transcoders) - 1;
4039
4040 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
4041 POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder)))
4042 return false;
4043
4044 if (hsw_panel_transcoders(dev_priv) & BIT(pipe_config->cpu_transcoder)) {
4045 tmp = intel_de_read(dev_priv,
4046 TRANS_DDI_FUNC_CTL(dev_priv, pipe_config->cpu_transcoder));
4047
4048 if ((tmp & TRANS_DDI_EDP_INPUT_MASK) == TRANS_DDI_EDP_INPUT_A_ONOFF)
4049 pipe_config->pch_pfit.force_thru = true;
4050 }
4051
4052 tmp = intel_de_read(dev_priv,
4053 TRANSCONF(dev_priv, pipe_config->cpu_transcoder));
4054
4055 return tmp & TRANSCONF_ENABLE;
4056 }
4057
bxt_get_dsi_transcoder_state(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config,struct intel_display_power_domain_set * power_domain_set)4058 static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
4059 struct intel_crtc_state *pipe_config,
4060 struct intel_display_power_domain_set *power_domain_set)
4061 {
4062 struct intel_display *display = to_intel_display(crtc);
4063 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4064 enum transcoder cpu_transcoder;
4065 enum port port;
4066 u32 tmp;
4067
4068 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
4069 if (port == PORT_A)
4070 cpu_transcoder = TRANSCODER_DSI_A;
4071 else
4072 cpu_transcoder = TRANSCODER_DSI_C;
4073
4074 if (!intel_display_power_get_in_set_if_enabled(dev_priv, power_domain_set,
4075 POWER_DOMAIN_TRANSCODER(cpu_transcoder)))
4076 continue;
4077
4078 /*
4079 * The PLL needs to be enabled with a valid divider
4080 * configuration, otherwise accessing DSI registers will hang
4081 * the machine. See BSpec North Display Engine
4082 * registers/MIPI[BXT]. We can break out here early, since we
4083 * need the same DSI PLL to be enabled for both DSI ports.
4084 */
4085 if (!bxt_dsi_pll_is_enabled(dev_priv))
4086 break;
4087
4088 /* XXX: this works for video mode only */
4089 tmp = intel_de_read(display, BXT_MIPI_PORT_CTRL(port));
4090 if (!(tmp & DPI_ENABLE))
4091 continue;
4092
4093 tmp = intel_de_read(display, MIPI_CTRL(display, port));
4094 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
4095 continue;
4096
4097 pipe_config->cpu_transcoder = cpu_transcoder;
4098 break;
4099 }
4100
4101 return transcoder_is_dsi(pipe_config->cpu_transcoder);
4102 }
4103
intel_joiner_get_config(struct intel_crtc_state * crtc_state)4104 static void intel_joiner_get_config(struct intel_crtc_state *crtc_state)
4105 {
4106 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4107 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4108 u8 primary_pipe, secondary_pipes;
4109 enum pipe pipe = crtc->pipe;
4110
4111 enabled_joiner_pipes(i915, pipe, &primary_pipe, &secondary_pipes);
4112
4113 if (((primary_pipe | secondary_pipes) & BIT(pipe)) == 0)
4114 return;
4115
4116 crtc_state->joiner_pipes = primary_pipe | secondary_pipes;
4117 }
4118
hsw_get_pipe_config(struct intel_crtc * crtc,struct intel_crtc_state * pipe_config)4119 static bool hsw_get_pipe_config(struct intel_crtc *crtc,
4120 struct intel_crtc_state *pipe_config)
4121 {
4122 struct intel_display *display = to_intel_display(crtc);
4123 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4124 bool active;
4125 u32 tmp;
4126
4127 if (!intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
4128 POWER_DOMAIN_PIPE(crtc->pipe)))
4129 return false;
4130
4131 pipe_config->shared_dpll = NULL;
4132
4133 active = hsw_get_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains);
4134
4135 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4136 bxt_get_dsi_transcoder_state(crtc, pipe_config, &crtc->hw_readout_power_domains)) {
4137 drm_WARN_ON(&dev_priv->drm, active);
4138 active = true;
4139 }
4140
4141 if (!active)
4142 goto out;
4143
4144 intel_joiner_get_config(pipe_config);
4145 intel_dsc_get_config(pipe_config);
4146
4147 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
4148 DISPLAY_VER(dev_priv) >= 11)
4149 intel_get_transcoder_timings(crtc, pipe_config);
4150
4151 if (HAS_VRR(dev_priv) && !transcoder_is_dsi(pipe_config->cpu_transcoder))
4152 intel_vrr_get_config(pipe_config);
4153
4154 intel_get_pipe_src_size(crtc, pipe_config);
4155
4156 if (IS_HASWELL(dev_priv)) {
4157 u32 tmp = intel_de_read(dev_priv,
4158 TRANSCONF(dev_priv, pipe_config->cpu_transcoder));
4159
4160 if (tmp & TRANSCONF_OUTPUT_COLORSPACE_YUV_HSW)
4161 pipe_config->output_format = INTEL_OUTPUT_FORMAT_YCBCR444;
4162 else
4163 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
4164 } else {
4165 pipe_config->output_format =
4166 bdw_get_pipe_misc_output_format(crtc);
4167 }
4168
4169 pipe_config->sink_format = pipe_config->output_format;
4170
4171 intel_color_get_config(pipe_config);
4172
4173 tmp = intel_de_read(dev_priv, WM_LINETIME(crtc->pipe));
4174 pipe_config->linetime = REG_FIELD_GET(HSW_LINETIME_MASK, tmp);
4175 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
4176 pipe_config->ips_linetime =
4177 REG_FIELD_GET(HSW_IPS_LINETIME_MASK, tmp);
4178
4179 if (intel_display_power_get_in_set_if_enabled(dev_priv, &crtc->hw_readout_power_domains,
4180 POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe))) {
4181 if (DISPLAY_VER(dev_priv) >= 9)
4182 skl_scaler_get_config(pipe_config);
4183 else
4184 ilk_get_pfit_config(pipe_config);
4185 }
4186
4187 hsw_ips_get_config(pipe_config);
4188
4189 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
4190 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
4191 pipe_config->pixel_multiplier =
4192 intel_de_read(dev_priv,
4193 TRANS_MULT(dev_priv, pipe_config->cpu_transcoder)) + 1;
4194 } else {
4195 pipe_config->pixel_multiplier = 1;
4196 }
4197
4198 if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) {
4199 tmp = intel_de_read(display, CHICKEN_TRANS(display, pipe_config->cpu_transcoder));
4200
4201 pipe_config->framestart_delay = REG_FIELD_GET(HSW_FRAME_START_DELAY_MASK, tmp) + 1;
4202 } else {
4203 /* no idea if this is correct */
4204 pipe_config->framestart_delay = 1;
4205 }
4206
4207 out:
4208 intel_display_power_put_all_in_set(dev_priv, &crtc->hw_readout_power_domains);
4209
4210 return active;
4211 }
4212
intel_crtc_get_pipe_config(struct intel_crtc_state * crtc_state)4213 bool intel_crtc_get_pipe_config(struct intel_crtc_state *crtc_state)
4214 {
4215 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4216 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4217
4218 if (!i915->display.funcs.display->get_pipe_config(crtc, crtc_state))
4219 return false;
4220
4221 crtc_state->hw.active = true;
4222
4223 intel_crtc_readout_derived_state(crtc_state);
4224
4225 return true;
4226 }
4227
intel_dotclock_calculate(int link_freq,const struct intel_link_m_n * m_n)4228 int intel_dotclock_calculate(int link_freq,
4229 const struct intel_link_m_n *m_n)
4230 {
4231 /*
4232 * The calculation for the data clock -> pixel clock is:
4233 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
4234 * But we want to avoid losing precison if possible, so:
4235 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
4236 *
4237 * and for link freq (10kbs units) -> pixel clock it is:
4238 * link_symbol_clock = link_freq * 10 / link_symbol_size
4239 * pixel_clock = (m * link_symbol_clock) / n
4240 * or for more precision:
4241 * pixel_clock = (m * link_freq * 10) / (n * link_symbol_size)
4242 */
4243
4244 if (!m_n->link_n)
4245 return 0;
4246
4247 return DIV_ROUND_UP_ULL(mul_u32_u32(m_n->link_m, link_freq * 10),
4248 m_n->link_n * intel_dp_link_symbol_size(link_freq));
4249 }
4250
intel_crtc_dotclock(const struct intel_crtc_state * pipe_config)4251 int intel_crtc_dotclock(const struct intel_crtc_state *pipe_config)
4252 {
4253 int dotclock;
4254
4255 if (intel_crtc_has_dp_encoder(pipe_config))
4256 dotclock = intel_dotclock_calculate(pipe_config->port_clock,
4257 &pipe_config->dp_m_n);
4258 else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24)
4259 dotclock = DIV_ROUND_CLOSEST(pipe_config->port_clock * 24,
4260 pipe_config->pipe_bpp);
4261 else
4262 dotclock = pipe_config->port_clock;
4263
4264 if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 &&
4265 !intel_crtc_has_dp_encoder(pipe_config))
4266 dotclock *= 2;
4267
4268 if (pipe_config->pixel_multiplier)
4269 dotclock /= pipe_config->pixel_multiplier;
4270
4271 return dotclock;
4272 }
4273
4274 /* Returns the currently programmed mode of the given encoder. */
4275 struct drm_display_mode *
intel_encoder_current_mode(struct intel_encoder * encoder)4276 intel_encoder_current_mode(struct intel_encoder *encoder)
4277 {
4278 struct intel_display *display = to_intel_display(encoder);
4279 struct intel_crtc_state *crtc_state;
4280 struct drm_display_mode *mode;
4281 struct intel_crtc *crtc;
4282 enum pipe pipe;
4283
4284 if (!encoder->get_hw_state(encoder, &pipe))
4285 return NULL;
4286
4287 crtc = intel_crtc_for_pipe(display, pipe);
4288
4289 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
4290 if (!mode)
4291 return NULL;
4292
4293 crtc_state = intel_crtc_state_alloc(crtc);
4294 if (!crtc_state) {
4295 kfree(mode);
4296 return NULL;
4297 }
4298
4299 if (!intel_crtc_get_pipe_config(crtc_state)) {
4300 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
4301 kfree(mode);
4302 return NULL;
4303 }
4304
4305 intel_encoder_get_config(encoder, crtc_state);
4306
4307 intel_mode_from_crtc_timings(mode, &crtc_state->hw.adjusted_mode);
4308
4309 intel_crtc_destroy_state(&crtc->base, &crtc_state->uapi);
4310
4311 return mode;
4312 }
4313
encoders_cloneable(const struct intel_encoder * a,const struct intel_encoder * b)4314 static bool encoders_cloneable(const struct intel_encoder *a,
4315 const struct intel_encoder *b)
4316 {
4317 /* masks could be asymmetric, so check both ways */
4318 return a == b || (a->cloneable & BIT(b->type) &&
4319 b->cloneable & BIT(a->type));
4320 }
4321
check_single_encoder_cloning(struct intel_atomic_state * state,struct intel_crtc * crtc,struct intel_encoder * encoder)4322 static bool check_single_encoder_cloning(struct intel_atomic_state *state,
4323 struct intel_crtc *crtc,
4324 struct intel_encoder *encoder)
4325 {
4326 struct intel_encoder *source_encoder;
4327 struct drm_connector *connector;
4328 struct drm_connector_state *connector_state;
4329 int i;
4330
4331 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4332 if (connector_state->crtc != &crtc->base)
4333 continue;
4334
4335 source_encoder =
4336 to_intel_encoder(connector_state->best_encoder);
4337 if (!encoders_cloneable(encoder, source_encoder))
4338 return false;
4339 }
4340
4341 return true;
4342 }
4343
icl_add_linked_planes(struct intel_atomic_state * state)4344 static int icl_add_linked_planes(struct intel_atomic_state *state)
4345 {
4346 struct intel_plane *plane, *linked;
4347 struct intel_plane_state *plane_state, *linked_plane_state;
4348 int i;
4349
4350 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4351 linked = plane_state->planar_linked_plane;
4352
4353 if (!linked)
4354 continue;
4355
4356 linked_plane_state = intel_atomic_get_plane_state(state, linked);
4357 if (IS_ERR(linked_plane_state))
4358 return PTR_ERR(linked_plane_state);
4359
4360 drm_WARN_ON(state->base.dev,
4361 linked_plane_state->planar_linked_plane != plane);
4362 drm_WARN_ON(state->base.dev,
4363 linked_plane_state->planar_slave == plane_state->planar_slave);
4364 }
4365
4366 return 0;
4367 }
4368
icl_check_nv12_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)4369 static int icl_check_nv12_planes(struct intel_atomic_state *state,
4370 struct intel_crtc *crtc)
4371 {
4372 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
4373 struct intel_crtc_state *crtc_state =
4374 intel_atomic_get_new_crtc_state(state, crtc);
4375 struct intel_plane *plane, *linked;
4376 struct intel_plane_state *plane_state;
4377 int i;
4378
4379 if (DISPLAY_VER(dev_priv) < 11)
4380 return 0;
4381
4382 /*
4383 * Destroy all old plane links and make the slave plane invisible
4384 * in the crtc_state->active_planes mask.
4385 */
4386 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4387 if (plane->pipe != crtc->pipe || !plane_state->planar_linked_plane)
4388 continue;
4389
4390 plane_state->planar_linked_plane = NULL;
4391 if (plane_state->planar_slave && !plane_state->uapi.visible) {
4392 crtc_state->enabled_planes &= ~BIT(plane->id);
4393 crtc_state->active_planes &= ~BIT(plane->id);
4394 crtc_state->update_planes |= BIT(plane->id);
4395 crtc_state->data_rate[plane->id] = 0;
4396 crtc_state->rel_data_rate[plane->id] = 0;
4397 }
4398
4399 plane_state->planar_slave = false;
4400 }
4401
4402 if (!crtc_state->nv12_planes)
4403 return 0;
4404
4405 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
4406 struct intel_plane_state *linked_state = NULL;
4407
4408 if (plane->pipe != crtc->pipe ||
4409 !(crtc_state->nv12_planes & BIT(plane->id)))
4410 continue;
4411
4412 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
4413 if (!icl_is_nv12_y_plane(dev_priv, linked->id))
4414 continue;
4415
4416 if (crtc_state->active_planes & BIT(linked->id))
4417 continue;
4418
4419 linked_state = intel_atomic_get_plane_state(state, linked);
4420 if (IS_ERR(linked_state))
4421 return PTR_ERR(linked_state);
4422
4423 break;
4424 }
4425
4426 if (!linked_state) {
4427 drm_dbg_kms(&dev_priv->drm,
4428 "Need %d free Y planes for planar YUV\n",
4429 hweight8(crtc_state->nv12_planes));
4430
4431 return -EINVAL;
4432 }
4433
4434 plane_state->planar_linked_plane = linked;
4435
4436 linked_state->planar_slave = true;
4437 linked_state->planar_linked_plane = plane;
4438 crtc_state->enabled_planes |= BIT(linked->id);
4439 crtc_state->active_planes |= BIT(linked->id);
4440 crtc_state->update_planes |= BIT(linked->id);
4441 crtc_state->data_rate[linked->id] =
4442 crtc_state->data_rate_y[plane->id];
4443 crtc_state->rel_data_rate[linked->id] =
4444 crtc_state->rel_data_rate_y[plane->id];
4445 drm_dbg_kms(&dev_priv->drm, "Using %s as Y plane for %s\n",
4446 linked->base.name, plane->base.name);
4447
4448 /* Copy parameters to slave plane */
4449 linked_state->ctl = plane_state->ctl | PLANE_CTL_YUV420_Y_PLANE;
4450 linked_state->color_ctl = plane_state->color_ctl;
4451 linked_state->view = plane_state->view;
4452 linked_state->decrypt = plane_state->decrypt;
4453
4454 intel_plane_copy_hw_state(linked_state, plane_state);
4455 linked_state->uapi.src = plane_state->uapi.src;
4456 linked_state->uapi.dst = plane_state->uapi.dst;
4457
4458 if (icl_is_hdr_plane(dev_priv, plane->id)) {
4459 if (linked->id == PLANE_7)
4460 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_7_ICL;
4461 else if (linked->id == PLANE_6)
4462 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_6_ICL;
4463 else if (linked->id == PLANE_5)
4464 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_5_RKL;
4465 else if (linked->id == PLANE_4)
4466 plane_state->cus_ctl |= PLANE_CUS_Y_PLANE_4_RKL;
4467 else
4468 MISSING_CASE(linked->id);
4469 }
4470 }
4471
4472 return 0;
4473 }
4474
hsw_linetime_wm(const struct intel_crtc_state * crtc_state)4475 static u16 hsw_linetime_wm(const struct intel_crtc_state *crtc_state)
4476 {
4477 const struct drm_display_mode *pipe_mode =
4478 &crtc_state->hw.pipe_mode;
4479 int linetime_wm;
4480
4481 if (!crtc_state->hw.enable)
4482 return 0;
4483
4484 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4485 pipe_mode->crtc_clock);
4486
4487 return min(linetime_wm, 0x1ff);
4488 }
4489
hsw_ips_linetime_wm(const struct intel_crtc_state * crtc_state,const struct intel_cdclk_state * cdclk_state)4490 static u16 hsw_ips_linetime_wm(const struct intel_crtc_state *crtc_state,
4491 const struct intel_cdclk_state *cdclk_state)
4492 {
4493 const struct drm_display_mode *pipe_mode =
4494 &crtc_state->hw.pipe_mode;
4495 int linetime_wm;
4496
4497 if (!crtc_state->hw.enable)
4498 return 0;
4499
4500 linetime_wm = DIV_ROUND_CLOSEST(pipe_mode->crtc_htotal * 1000 * 8,
4501 cdclk_state->logical.cdclk);
4502
4503 return min(linetime_wm, 0x1ff);
4504 }
4505
skl_linetime_wm(const struct intel_crtc_state * crtc_state)4506 static u16 skl_linetime_wm(const struct intel_crtc_state *crtc_state)
4507 {
4508 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
4509 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4510 const struct drm_display_mode *pipe_mode =
4511 &crtc_state->hw.pipe_mode;
4512 int linetime_wm;
4513
4514 if (!crtc_state->hw.enable)
4515 return 0;
4516
4517 linetime_wm = DIV_ROUND_UP(pipe_mode->crtc_htotal * 1000 * 8,
4518 crtc_state->pixel_rate);
4519
4520 /* Display WA #1135: BXT:ALL GLK:ALL */
4521 if ((IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv)) &&
4522 skl_watermark_ipc_enabled(dev_priv))
4523 linetime_wm /= 2;
4524
4525 return min(linetime_wm, 0x1ff);
4526 }
4527
hsw_compute_linetime_wm(struct intel_atomic_state * state,struct intel_crtc * crtc)4528 static int hsw_compute_linetime_wm(struct intel_atomic_state *state,
4529 struct intel_crtc *crtc)
4530 {
4531 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4532 struct intel_crtc_state *crtc_state =
4533 intel_atomic_get_new_crtc_state(state, crtc);
4534 const struct intel_cdclk_state *cdclk_state;
4535
4536 if (DISPLAY_VER(dev_priv) >= 9)
4537 crtc_state->linetime = skl_linetime_wm(crtc_state);
4538 else
4539 crtc_state->linetime = hsw_linetime_wm(crtc_state);
4540
4541 if (!hsw_crtc_supports_ips(crtc))
4542 return 0;
4543
4544 cdclk_state = intel_atomic_get_cdclk_state(state);
4545 if (IS_ERR(cdclk_state))
4546 return PTR_ERR(cdclk_state);
4547
4548 crtc_state->ips_linetime = hsw_ips_linetime_wm(crtc_state,
4549 cdclk_state);
4550
4551 return 0;
4552 }
4553
intel_crtc_atomic_check(struct intel_atomic_state * state,struct intel_crtc * crtc)4554 static int intel_crtc_atomic_check(struct intel_atomic_state *state,
4555 struct intel_crtc *crtc)
4556 {
4557 struct intel_display *display = to_intel_display(crtc);
4558 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4559 struct intel_crtc_state *crtc_state =
4560 intel_atomic_get_new_crtc_state(state, crtc);
4561 int ret;
4562
4563 if (DISPLAY_VER(dev_priv) < 5 && !IS_G4X(dev_priv) &&
4564 intel_crtc_needs_modeset(crtc_state) &&
4565 !crtc_state->hw.active)
4566 crtc_state->update_wm_post = true;
4567
4568 if (intel_crtc_needs_modeset(crtc_state)) {
4569 ret = intel_dpll_crtc_get_shared_dpll(state, crtc);
4570 if (ret)
4571 return ret;
4572 }
4573
4574 ret = intel_color_check(state, crtc);
4575 if (ret)
4576 return ret;
4577
4578 ret = intel_wm_compute(state, crtc);
4579 if (ret) {
4580 drm_dbg_kms(&dev_priv->drm,
4581 "[CRTC:%d:%s] watermarks are invalid\n",
4582 crtc->base.base.id, crtc->base.name);
4583 return ret;
4584 }
4585
4586 if (DISPLAY_VER(dev_priv) >= 9) {
4587 if (intel_crtc_needs_modeset(crtc_state) ||
4588 intel_crtc_needs_fastset(crtc_state)) {
4589 ret = skl_update_scaler_crtc(crtc_state);
4590 if (ret)
4591 return ret;
4592 }
4593
4594 ret = intel_atomic_setup_scalers(state, crtc);
4595 if (ret)
4596 return ret;
4597 }
4598
4599 if (HAS_IPS(display)) {
4600 ret = hsw_ips_compute_config(state, crtc);
4601 if (ret)
4602 return ret;
4603 }
4604
4605 if (DISPLAY_VER(dev_priv) >= 9 ||
4606 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
4607 ret = hsw_compute_linetime_wm(state, crtc);
4608 if (ret)
4609 return ret;
4610
4611 }
4612
4613 ret = intel_psr2_sel_fetch_update(state, crtc);
4614 if (ret)
4615 return ret;
4616
4617 return 0;
4618 }
4619
4620 static int
compute_sink_pipe_bpp(const struct drm_connector_state * conn_state,struct intel_crtc_state * crtc_state)4621 compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
4622 struct intel_crtc_state *crtc_state)
4623 {
4624 struct drm_connector *connector = conn_state->connector;
4625 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
4626 const struct drm_display_info *info = &connector->display_info;
4627 int bpp;
4628
4629 switch (conn_state->max_bpc) {
4630 case 6 ... 7:
4631 bpp = 6 * 3;
4632 break;
4633 case 8 ... 9:
4634 bpp = 8 * 3;
4635 break;
4636 case 10 ... 11:
4637 bpp = 10 * 3;
4638 break;
4639 case 12 ... 16:
4640 bpp = 12 * 3;
4641 break;
4642 default:
4643 MISSING_CASE(conn_state->max_bpc);
4644 return -EINVAL;
4645 }
4646
4647 if (bpp < crtc_state->pipe_bpp) {
4648 drm_dbg_kms(&i915->drm,
4649 "[CONNECTOR:%d:%s] Limiting display bpp to %d "
4650 "(EDID bpp %d, max requested bpp %d, max platform bpp %d)\n",
4651 connector->base.id, connector->name,
4652 bpp, 3 * info->bpc,
4653 3 * conn_state->max_requested_bpc,
4654 crtc_state->pipe_bpp);
4655
4656 crtc_state->pipe_bpp = bpp;
4657 }
4658
4659 return 0;
4660 }
4661
4662 static int
compute_baseline_pipe_bpp(struct intel_atomic_state * state,struct intel_crtc * crtc)4663 compute_baseline_pipe_bpp(struct intel_atomic_state *state,
4664 struct intel_crtc *crtc)
4665 {
4666 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4667 struct intel_crtc_state *crtc_state =
4668 intel_atomic_get_new_crtc_state(state, crtc);
4669 struct drm_connector *connector;
4670 struct drm_connector_state *connector_state;
4671 int bpp, i;
4672
4673 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
4674 IS_CHERRYVIEW(dev_priv)))
4675 bpp = 10*3;
4676 else if (DISPLAY_VER(dev_priv) >= 5)
4677 bpp = 12*3;
4678 else
4679 bpp = 8*3;
4680
4681 crtc_state->pipe_bpp = bpp;
4682
4683 /* Clamp display bpp to connector max bpp */
4684 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4685 int ret;
4686
4687 if (connector_state->crtc != &crtc->base)
4688 continue;
4689
4690 ret = compute_sink_pipe_bpp(connector_state, crtc_state);
4691 if (ret)
4692 return ret;
4693 }
4694
4695 return 0;
4696 }
4697
check_digital_port_conflicts(struct intel_atomic_state * state)4698 static bool check_digital_port_conflicts(struct intel_atomic_state *state)
4699 {
4700 struct drm_device *dev = state->base.dev;
4701 struct drm_connector *connector;
4702 struct drm_connector_list_iter conn_iter;
4703 unsigned int used_ports = 0;
4704 unsigned int used_mst_ports = 0;
4705 bool ret = true;
4706
4707 /*
4708 * We're going to peek into connector->state,
4709 * hence connection_mutex must be held.
4710 */
4711 drm_modeset_lock_assert_held(&dev->mode_config.connection_mutex);
4712
4713 /*
4714 * Walk the connector list instead of the encoder
4715 * list to detect the problem on ddi platforms
4716 * where there's just one encoder per digital port.
4717 */
4718 drm_connector_list_iter_begin(dev, &conn_iter);
4719 drm_for_each_connector_iter(connector, &conn_iter) {
4720 struct drm_connector_state *connector_state;
4721 struct intel_encoder *encoder;
4722
4723 connector_state =
4724 drm_atomic_get_new_connector_state(&state->base,
4725 connector);
4726 if (!connector_state)
4727 connector_state = connector->state;
4728
4729 if (!connector_state->best_encoder)
4730 continue;
4731
4732 encoder = to_intel_encoder(connector_state->best_encoder);
4733
4734 drm_WARN_ON(dev, !connector_state->crtc);
4735
4736 switch (encoder->type) {
4737 case INTEL_OUTPUT_DDI:
4738 if (drm_WARN_ON(dev, !HAS_DDI(to_i915(dev))))
4739 break;
4740 fallthrough;
4741 case INTEL_OUTPUT_DP:
4742 case INTEL_OUTPUT_HDMI:
4743 case INTEL_OUTPUT_EDP:
4744 /* the same port mustn't appear more than once */
4745 if (used_ports & BIT(encoder->port))
4746 ret = false;
4747
4748 used_ports |= BIT(encoder->port);
4749 break;
4750 case INTEL_OUTPUT_DP_MST:
4751 used_mst_ports |=
4752 1 << encoder->port;
4753 break;
4754 default:
4755 break;
4756 }
4757 }
4758 drm_connector_list_iter_end(&conn_iter);
4759
4760 /* can't mix MST and SST/HDMI on the same port */
4761 if (used_ports & used_mst_ports)
4762 return false;
4763
4764 return ret;
4765 }
4766
4767 static void
intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state * state,struct intel_crtc * crtc)4768 intel_crtc_copy_uapi_to_hw_state_nomodeset(struct intel_atomic_state *state,
4769 struct intel_crtc *crtc)
4770 {
4771 struct intel_crtc_state *crtc_state =
4772 intel_atomic_get_new_crtc_state(state, crtc);
4773
4774 WARN_ON(intel_crtc_is_joiner_secondary(crtc_state));
4775
4776 drm_property_replace_blob(&crtc_state->hw.degamma_lut,
4777 crtc_state->uapi.degamma_lut);
4778 drm_property_replace_blob(&crtc_state->hw.gamma_lut,
4779 crtc_state->uapi.gamma_lut);
4780 drm_property_replace_blob(&crtc_state->hw.ctm,
4781 crtc_state->uapi.ctm);
4782 }
4783
4784 static void
intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state * state,struct intel_crtc * crtc)4785 intel_crtc_copy_uapi_to_hw_state_modeset(struct intel_atomic_state *state,
4786 struct intel_crtc *crtc)
4787 {
4788 struct intel_crtc_state *crtc_state =
4789 intel_atomic_get_new_crtc_state(state, crtc);
4790
4791 WARN_ON(intel_crtc_is_joiner_secondary(crtc_state));
4792
4793 crtc_state->hw.enable = crtc_state->uapi.enable;
4794 crtc_state->hw.active = crtc_state->uapi.active;
4795 drm_mode_copy(&crtc_state->hw.mode,
4796 &crtc_state->uapi.mode);
4797 drm_mode_copy(&crtc_state->hw.adjusted_mode,
4798 &crtc_state->uapi.adjusted_mode);
4799 crtc_state->hw.scaling_filter = crtc_state->uapi.scaling_filter;
4800
4801 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
4802 }
4803
4804 static void
copy_joiner_crtc_state_nomodeset(struct intel_atomic_state * state,struct intel_crtc * secondary_crtc)4805 copy_joiner_crtc_state_nomodeset(struct intel_atomic_state *state,
4806 struct intel_crtc *secondary_crtc)
4807 {
4808 struct intel_crtc_state *secondary_crtc_state =
4809 intel_atomic_get_new_crtc_state(state, secondary_crtc);
4810 struct intel_crtc *primary_crtc = intel_primary_crtc(secondary_crtc_state);
4811 const struct intel_crtc_state *primary_crtc_state =
4812 intel_atomic_get_new_crtc_state(state, primary_crtc);
4813
4814 drm_property_replace_blob(&secondary_crtc_state->hw.degamma_lut,
4815 primary_crtc_state->hw.degamma_lut);
4816 drm_property_replace_blob(&secondary_crtc_state->hw.gamma_lut,
4817 primary_crtc_state->hw.gamma_lut);
4818 drm_property_replace_blob(&secondary_crtc_state->hw.ctm,
4819 primary_crtc_state->hw.ctm);
4820
4821 secondary_crtc_state->uapi.color_mgmt_changed = primary_crtc_state->uapi.color_mgmt_changed;
4822 }
4823
4824 static int
copy_joiner_crtc_state_modeset(struct intel_atomic_state * state,struct intel_crtc * secondary_crtc)4825 copy_joiner_crtc_state_modeset(struct intel_atomic_state *state,
4826 struct intel_crtc *secondary_crtc)
4827 {
4828 struct intel_crtc_state *secondary_crtc_state =
4829 intel_atomic_get_new_crtc_state(state, secondary_crtc);
4830 struct intel_crtc *primary_crtc = intel_primary_crtc(secondary_crtc_state);
4831 const struct intel_crtc_state *primary_crtc_state =
4832 intel_atomic_get_new_crtc_state(state, primary_crtc);
4833 struct intel_crtc_state *saved_state;
4834
4835 WARN_ON(primary_crtc_state->joiner_pipes !=
4836 secondary_crtc_state->joiner_pipes);
4837
4838 saved_state = kmemdup(primary_crtc_state, sizeof(*saved_state), GFP_KERNEL);
4839 if (!saved_state)
4840 return -ENOMEM;
4841
4842 /* preserve some things from the slave's original crtc state */
4843 saved_state->uapi = secondary_crtc_state->uapi;
4844 saved_state->scaler_state = secondary_crtc_state->scaler_state;
4845 saved_state->shared_dpll = secondary_crtc_state->shared_dpll;
4846 saved_state->crc_enabled = secondary_crtc_state->crc_enabled;
4847
4848 intel_crtc_free_hw_state(secondary_crtc_state);
4849 if (secondary_crtc_state->dp_tunnel_ref.tunnel)
4850 drm_dp_tunnel_ref_put(&secondary_crtc_state->dp_tunnel_ref);
4851 memcpy(secondary_crtc_state, saved_state, sizeof(*secondary_crtc_state));
4852 kfree(saved_state);
4853
4854 /* Re-init hw state */
4855 memset(&secondary_crtc_state->hw, 0, sizeof(secondary_crtc_state->hw));
4856 secondary_crtc_state->hw.enable = primary_crtc_state->hw.enable;
4857 secondary_crtc_state->hw.active = primary_crtc_state->hw.active;
4858 drm_mode_copy(&secondary_crtc_state->hw.mode,
4859 &primary_crtc_state->hw.mode);
4860 drm_mode_copy(&secondary_crtc_state->hw.pipe_mode,
4861 &primary_crtc_state->hw.pipe_mode);
4862 drm_mode_copy(&secondary_crtc_state->hw.adjusted_mode,
4863 &primary_crtc_state->hw.adjusted_mode);
4864 secondary_crtc_state->hw.scaling_filter = primary_crtc_state->hw.scaling_filter;
4865
4866 if (primary_crtc_state->dp_tunnel_ref.tunnel)
4867 drm_dp_tunnel_ref_get(primary_crtc_state->dp_tunnel_ref.tunnel,
4868 &secondary_crtc_state->dp_tunnel_ref);
4869
4870 copy_joiner_crtc_state_nomodeset(state, secondary_crtc);
4871
4872 secondary_crtc_state->uapi.mode_changed = primary_crtc_state->uapi.mode_changed;
4873 secondary_crtc_state->uapi.connectors_changed = primary_crtc_state->uapi.connectors_changed;
4874 secondary_crtc_state->uapi.active_changed = primary_crtc_state->uapi.active_changed;
4875
4876 WARN_ON(primary_crtc_state->joiner_pipes !=
4877 secondary_crtc_state->joiner_pipes);
4878
4879 return 0;
4880 }
4881
4882 static int
intel_crtc_prepare_cleared_state(struct intel_atomic_state * state,struct intel_crtc * crtc)4883 intel_crtc_prepare_cleared_state(struct intel_atomic_state *state,
4884 struct intel_crtc *crtc)
4885 {
4886 struct intel_crtc_state *crtc_state =
4887 intel_atomic_get_new_crtc_state(state, crtc);
4888 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4889 struct intel_crtc_state *saved_state;
4890
4891 saved_state = intel_crtc_state_alloc(crtc);
4892 if (!saved_state)
4893 return -ENOMEM;
4894
4895 /* free the old crtc_state->hw members */
4896 intel_crtc_free_hw_state(crtc_state);
4897
4898 intel_dp_tunnel_atomic_clear_stream_bw(state, crtc_state);
4899
4900 /* FIXME: before the switch to atomic started, a new pipe_config was
4901 * kzalloc'd. Code that depends on any field being zero should be
4902 * fixed, so that the crtc_state can be safely duplicated. For now,
4903 * only fields that are know to not cause problems are preserved. */
4904
4905 saved_state->uapi = crtc_state->uapi;
4906 saved_state->inherited = crtc_state->inherited;
4907 saved_state->scaler_state = crtc_state->scaler_state;
4908 saved_state->shared_dpll = crtc_state->shared_dpll;
4909 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
4910 memcpy(saved_state->icl_port_dplls, crtc_state->icl_port_dplls,
4911 sizeof(saved_state->icl_port_dplls));
4912 saved_state->crc_enabled = crtc_state->crc_enabled;
4913 if (IS_G4X(dev_priv) ||
4914 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4915 saved_state->wm = crtc_state->wm;
4916
4917 memcpy(crtc_state, saved_state, sizeof(*crtc_state));
4918 kfree(saved_state);
4919
4920 intel_crtc_copy_uapi_to_hw_state_modeset(state, crtc);
4921
4922 return 0;
4923 }
4924
4925 static int
intel_modeset_pipe_config(struct intel_atomic_state * state,struct intel_crtc * crtc,const struct intel_link_bw_limits * limits)4926 intel_modeset_pipe_config(struct intel_atomic_state *state,
4927 struct intel_crtc *crtc,
4928 const struct intel_link_bw_limits *limits)
4929 {
4930 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
4931 struct intel_crtc_state *crtc_state =
4932 intel_atomic_get_new_crtc_state(state, crtc);
4933 struct drm_connector *connector;
4934 struct drm_connector_state *connector_state;
4935 int pipe_src_w, pipe_src_h;
4936 int base_bpp, ret, i;
4937
4938 crtc_state->cpu_transcoder = (enum transcoder) crtc->pipe;
4939
4940 crtc_state->framestart_delay = 1;
4941
4942 /*
4943 * Sanitize sync polarity flags based on requested ones. If neither
4944 * positive or negative polarity is requested, treat this as meaning
4945 * negative polarity.
4946 */
4947 if (!(crtc_state->hw.adjusted_mode.flags &
4948 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
4949 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
4950
4951 if (!(crtc_state->hw.adjusted_mode.flags &
4952 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
4953 crtc_state->hw.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
4954
4955 ret = compute_baseline_pipe_bpp(state, crtc);
4956 if (ret)
4957 return ret;
4958
4959 crtc_state->fec_enable = limits->force_fec_pipes & BIT(crtc->pipe);
4960 crtc_state->max_link_bpp_x16 = limits->max_bpp_x16[crtc->pipe];
4961
4962 if (crtc_state->pipe_bpp > fxp_q4_to_int(crtc_state->max_link_bpp_x16)) {
4963 drm_dbg_kms(&i915->drm,
4964 "[CRTC:%d:%s] Link bpp limited to " FXP_Q4_FMT "\n",
4965 crtc->base.base.id, crtc->base.name,
4966 FXP_Q4_ARGS(crtc_state->max_link_bpp_x16));
4967 crtc_state->bw_constrained = true;
4968 }
4969
4970 base_bpp = crtc_state->pipe_bpp;
4971
4972 /*
4973 * Determine the real pipe dimensions. Note that stereo modes can
4974 * increase the actual pipe size due to the frame doubling and
4975 * insertion of additional space for blanks between the frame. This
4976 * is stored in the crtc timings. We use the requested mode to do this
4977 * computation to clearly distinguish it from the adjusted mode, which
4978 * can be changed by the connectors in the below retry loop.
4979 */
4980 drm_mode_get_hv_timing(&crtc_state->hw.mode,
4981 &pipe_src_w, &pipe_src_h);
4982 drm_rect_init(&crtc_state->pipe_src, 0, 0,
4983 pipe_src_w, pipe_src_h);
4984
4985 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
4986 struct intel_encoder *encoder =
4987 to_intel_encoder(connector_state->best_encoder);
4988
4989 if (connector_state->crtc != &crtc->base)
4990 continue;
4991
4992 if (!check_single_encoder_cloning(state, crtc, encoder)) {
4993 drm_dbg_kms(&i915->drm,
4994 "[ENCODER:%d:%s] rejecting invalid cloning configuration\n",
4995 encoder->base.base.id, encoder->base.name);
4996 return -EINVAL;
4997 }
4998
4999 /*
5000 * Determine output_types before calling the .compute_config()
5001 * hooks so that the hooks can use this information safely.
5002 */
5003 if (encoder->compute_output_type)
5004 crtc_state->output_types |=
5005 BIT(encoder->compute_output_type(encoder, crtc_state,
5006 connector_state));
5007 else
5008 crtc_state->output_types |= BIT(encoder->type);
5009 }
5010
5011 /* Ensure the port clock defaults are reset when retrying. */
5012 crtc_state->port_clock = 0;
5013 crtc_state->pixel_multiplier = 1;
5014
5015 /* Fill in default crtc timings, allow encoders to overwrite them. */
5016 drm_mode_set_crtcinfo(&crtc_state->hw.adjusted_mode,
5017 CRTC_STEREO_DOUBLE);
5018
5019 /* Pass our mode to the connectors and the CRTC to give them a chance to
5020 * adjust it according to limitations or connector properties, and also
5021 * a chance to reject the mode entirely.
5022 */
5023 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
5024 struct intel_encoder *encoder =
5025 to_intel_encoder(connector_state->best_encoder);
5026
5027 if (connector_state->crtc != &crtc->base)
5028 continue;
5029
5030 ret = encoder->compute_config(encoder, crtc_state,
5031 connector_state);
5032 if (ret == -EDEADLK)
5033 return ret;
5034 if (ret < 0) {
5035 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] config failure: %d\n",
5036 encoder->base.base.id, encoder->base.name, ret);
5037 return ret;
5038 }
5039 }
5040
5041 /* Set default port clock if not overwritten by the encoder. Needs to be
5042 * done afterwards in case the encoder adjusts the mode. */
5043 if (!crtc_state->port_clock)
5044 crtc_state->port_clock = crtc_state->hw.adjusted_mode.crtc_clock
5045 * crtc_state->pixel_multiplier;
5046
5047 ret = intel_crtc_compute_config(state, crtc);
5048 if (ret == -EDEADLK)
5049 return ret;
5050 if (ret < 0) {
5051 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] config failure: %d\n",
5052 crtc->base.base.id, crtc->base.name, ret);
5053 return ret;
5054 }
5055
5056 /* Dithering seems to not pass-through bits correctly when it should, so
5057 * only enable it on 6bpc panels and when its not a compliance
5058 * test requesting 6bpc video pattern.
5059 */
5060 crtc_state->dither = (crtc_state->pipe_bpp == 6*3) &&
5061 !crtc_state->dither_force_disable;
5062 drm_dbg_kms(&i915->drm,
5063 "[CRTC:%d:%s] hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
5064 crtc->base.base.id, crtc->base.name,
5065 base_bpp, crtc_state->pipe_bpp, crtc_state->dither);
5066
5067 return 0;
5068 }
5069
5070 static int
intel_modeset_pipe_config_late(struct intel_atomic_state * state,struct intel_crtc * crtc)5071 intel_modeset_pipe_config_late(struct intel_atomic_state *state,
5072 struct intel_crtc *crtc)
5073 {
5074 struct intel_crtc_state *crtc_state =
5075 intel_atomic_get_new_crtc_state(state, crtc);
5076 struct drm_connector_state *conn_state;
5077 struct drm_connector *connector;
5078 int i;
5079
5080 intel_vrr_compute_config_late(crtc_state);
5081
5082 for_each_new_connector_in_state(&state->base, connector,
5083 conn_state, i) {
5084 struct intel_encoder *encoder =
5085 to_intel_encoder(conn_state->best_encoder);
5086 int ret;
5087
5088 if (conn_state->crtc != &crtc->base ||
5089 !encoder->compute_config_late)
5090 continue;
5091
5092 ret = encoder->compute_config_late(encoder, crtc_state,
5093 conn_state);
5094 if (ret)
5095 return ret;
5096 }
5097
5098 return 0;
5099 }
5100
intel_fuzzy_clock_check(int clock1,int clock2)5101 bool intel_fuzzy_clock_check(int clock1, int clock2)
5102 {
5103 int diff;
5104
5105 if (clock1 == clock2)
5106 return true;
5107
5108 if (!clock1 || !clock2)
5109 return false;
5110
5111 diff = abs(clock1 - clock2);
5112
5113 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
5114 return true;
5115
5116 return false;
5117 }
5118
5119 static bool
intel_compare_link_m_n(const struct intel_link_m_n * m_n,const struct intel_link_m_n * m2_n2)5120 intel_compare_link_m_n(const struct intel_link_m_n *m_n,
5121 const struct intel_link_m_n *m2_n2)
5122 {
5123 return m_n->tu == m2_n2->tu &&
5124 m_n->data_m == m2_n2->data_m &&
5125 m_n->data_n == m2_n2->data_n &&
5126 m_n->link_m == m2_n2->link_m &&
5127 m_n->link_n == m2_n2->link_n;
5128 }
5129
5130 static bool
intel_compare_infoframe(const union hdmi_infoframe * a,const union hdmi_infoframe * b)5131 intel_compare_infoframe(const union hdmi_infoframe *a,
5132 const union hdmi_infoframe *b)
5133 {
5134 return memcmp(a, b, sizeof(*a)) == 0;
5135 }
5136
5137 static bool
intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp * a,const struct drm_dp_vsc_sdp * b)5138 intel_compare_dp_vsc_sdp(const struct drm_dp_vsc_sdp *a,
5139 const struct drm_dp_vsc_sdp *b)
5140 {
5141 return a->pixelformat == b->pixelformat &&
5142 a->colorimetry == b->colorimetry &&
5143 a->bpc == b->bpc &&
5144 a->dynamic_range == b->dynamic_range &&
5145 a->content_type == b->content_type;
5146 }
5147
5148 static bool
intel_compare_dp_as_sdp(const struct drm_dp_as_sdp * a,const struct drm_dp_as_sdp * b)5149 intel_compare_dp_as_sdp(const struct drm_dp_as_sdp *a,
5150 const struct drm_dp_as_sdp *b)
5151 {
5152 return a->vtotal == b->vtotal &&
5153 a->target_rr == b->target_rr &&
5154 a->duration_incr_ms == b->duration_incr_ms &&
5155 a->duration_decr_ms == b->duration_decr_ms &&
5156 a->mode == b->mode;
5157 }
5158
5159 static bool
intel_compare_buffer(const u8 * a,const u8 * b,size_t len)5160 intel_compare_buffer(const u8 *a, const u8 *b, size_t len)
5161 {
5162 return memcmp(a, b, len) == 0;
5163 }
5164
5165 static void __printf(5, 6)
pipe_config_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const char * format,...)5166 pipe_config_mismatch(struct drm_printer *p, bool fastset,
5167 const struct intel_crtc *crtc,
5168 const char *name, const char *format, ...)
5169 {
5170 struct va_format vaf;
5171 va_list args;
5172
5173 va_start(args, format);
5174 vaf.fmt = format;
5175 vaf.va = &args;
5176
5177 if (fastset)
5178 drm_printf(p, "[CRTC:%d:%s] fastset requirement not met in %s %pV\n",
5179 crtc->base.base.id, crtc->base.name, name, &vaf);
5180 else
5181 drm_printf(p, "[CRTC:%d:%s] mismatch in %s %pV\n",
5182 crtc->base.base.id, crtc->base.name, name, &vaf);
5183
5184 va_end(args);
5185 }
5186
5187 static void
pipe_config_infoframe_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const union hdmi_infoframe * a,const union hdmi_infoframe * b)5188 pipe_config_infoframe_mismatch(struct drm_printer *p, bool fastset,
5189 const struct intel_crtc *crtc,
5190 const char *name,
5191 const union hdmi_infoframe *a,
5192 const union hdmi_infoframe *b)
5193 {
5194 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5195 const char *loglevel;
5196
5197 if (fastset) {
5198 if (!drm_debug_enabled(DRM_UT_KMS))
5199 return;
5200
5201 loglevel = KERN_DEBUG;
5202 } else {
5203 loglevel = KERN_ERR;
5204 }
5205
5206 pipe_config_mismatch(p, fastset, crtc, name, "infoframe");
5207
5208 drm_printf(p, "expected:\n");
5209 hdmi_infoframe_log(loglevel, i915->drm.dev, a);
5210 drm_printf(p, "found:\n");
5211 hdmi_infoframe_log(loglevel, i915->drm.dev, b);
5212 }
5213
5214 static void
pipe_config_dp_vsc_sdp_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const struct drm_dp_vsc_sdp * a,const struct drm_dp_vsc_sdp * b)5215 pipe_config_dp_vsc_sdp_mismatch(struct drm_printer *p, bool fastset,
5216 const struct intel_crtc *crtc,
5217 const char *name,
5218 const struct drm_dp_vsc_sdp *a,
5219 const struct drm_dp_vsc_sdp *b)
5220 {
5221 pipe_config_mismatch(p, fastset, crtc, name, "dp vsc sdp");
5222
5223 drm_printf(p, "expected:\n");
5224 drm_dp_vsc_sdp_log(p, a);
5225 drm_printf(p, "found:\n");
5226 drm_dp_vsc_sdp_log(p, b);
5227 }
5228
5229 static void
pipe_config_dp_as_sdp_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const struct drm_dp_as_sdp * a,const struct drm_dp_as_sdp * b)5230 pipe_config_dp_as_sdp_mismatch(struct drm_printer *p, bool fastset,
5231 const struct intel_crtc *crtc,
5232 const char *name,
5233 const struct drm_dp_as_sdp *a,
5234 const struct drm_dp_as_sdp *b)
5235 {
5236 pipe_config_mismatch(p, fastset, crtc, name, "dp as sdp");
5237
5238 drm_printf(p, "expected:\n");
5239 drm_dp_as_sdp_log(p, a);
5240 drm_printf(p, "found:\n");
5241 drm_dp_as_sdp_log(p, b);
5242 }
5243
5244 /* Returns the length up to and including the last differing byte */
5245 static size_t
memcmp_diff_len(const u8 * a,const u8 * b,size_t len)5246 memcmp_diff_len(const u8 *a, const u8 *b, size_t len)
5247 {
5248 int i;
5249
5250 for (i = len - 1; i >= 0; i--) {
5251 if (a[i] != b[i])
5252 return i + 1;
5253 }
5254
5255 return 0;
5256 }
5257
5258 static void
pipe_config_buffer_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const u8 * a,const u8 * b,size_t len)5259 pipe_config_buffer_mismatch(struct drm_printer *p, bool fastset,
5260 const struct intel_crtc *crtc,
5261 const char *name,
5262 const u8 *a, const u8 *b, size_t len)
5263 {
5264 pipe_config_mismatch(p, fastset, crtc, name, "buffer");
5265
5266 /* only dump up to the last difference */
5267 len = memcmp_diff_len(a, b, len);
5268
5269 drm_print_hex_dump(p, "expected: ", a, len);
5270 drm_print_hex_dump(p, "found: ", b, len);
5271 }
5272
5273 static void
pipe_config_pll_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const struct intel_dpll_hw_state * a,const struct intel_dpll_hw_state * b)5274 pipe_config_pll_mismatch(struct drm_printer *p, bool fastset,
5275 const struct intel_crtc *crtc,
5276 const char *name,
5277 const struct intel_dpll_hw_state *a,
5278 const struct intel_dpll_hw_state *b)
5279 {
5280 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
5281
5282 pipe_config_mismatch(p, fastset, crtc, name, " "); /* stupid -Werror=format-zero-length */
5283
5284 drm_printf(p, "expected:\n");
5285 intel_dpll_dump_hw_state(i915, p, a);
5286 drm_printf(p, "found:\n");
5287 intel_dpll_dump_hw_state(i915, p, b);
5288 }
5289
5290 static void
pipe_config_cx0pll_mismatch(struct drm_printer * p,bool fastset,const struct intel_crtc * crtc,const char * name,const struct intel_cx0pll_state * a,const struct intel_cx0pll_state * b)5291 pipe_config_cx0pll_mismatch(struct drm_printer *p, bool fastset,
5292 const struct intel_crtc *crtc,
5293 const char *name,
5294 const struct intel_cx0pll_state *a,
5295 const struct intel_cx0pll_state *b)
5296 {
5297 struct intel_display *display = to_intel_display(crtc);
5298 char *chipname = a->use_c10 ? "C10" : "C20";
5299
5300 pipe_config_mismatch(p, fastset, crtc, name, chipname);
5301
5302 drm_printf(p, "expected:\n");
5303 intel_cx0pll_dump_hw_state(display, a);
5304 drm_printf(p, "found:\n");
5305 intel_cx0pll_dump_hw_state(display, b);
5306 }
5307
5308 bool
intel_pipe_config_compare(const struct intel_crtc_state * current_config,const struct intel_crtc_state * pipe_config,bool fastset)5309 intel_pipe_config_compare(const struct intel_crtc_state *current_config,
5310 const struct intel_crtc_state *pipe_config,
5311 bool fastset)
5312 {
5313 struct intel_display *display = to_intel_display(current_config);
5314 struct drm_i915_private *dev_priv = to_i915(current_config->uapi.crtc->dev);
5315 struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc);
5316 struct drm_printer p;
5317 bool ret = true;
5318
5319 if (fastset)
5320 p = drm_dbg_printer(&dev_priv->drm, DRM_UT_KMS, NULL);
5321 else
5322 p = drm_err_printer(&dev_priv->drm, NULL);
5323
5324 #define PIPE_CONF_CHECK_X(name) do { \
5325 if (current_config->name != pipe_config->name) { \
5326 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
5327 __stringify(name) " is bool"); \
5328 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5329 "(expected 0x%08x, found 0x%08x)", \
5330 current_config->name, \
5331 pipe_config->name); \
5332 ret = false; \
5333 } \
5334 } while (0)
5335
5336 #define PIPE_CONF_CHECK_X_WITH_MASK(name, mask) do { \
5337 if ((current_config->name & (mask)) != (pipe_config->name & (mask))) { \
5338 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
5339 __stringify(name) " is bool"); \
5340 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5341 "(expected 0x%08x, found 0x%08x)", \
5342 current_config->name & (mask), \
5343 pipe_config->name & (mask)); \
5344 ret = false; \
5345 } \
5346 } while (0)
5347
5348 #define PIPE_CONF_CHECK_I(name) do { \
5349 if (current_config->name != pipe_config->name) { \
5350 BUILD_BUG_ON_MSG(__same_type(current_config->name, bool), \
5351 __stringify(name) " is bool"); \
5352 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5353 "(expected %i, found %i)", \
5354 current_config->name, \
5355 pipe_config->name); \
5356 ret = false; \
5357 } \
5358 } while (0)
5359
5360 #define PIPE_CONF_CHECK_LLI(name) do { \
5361 if (current_config->name != pipe_config->name) { \
5362 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5363 "(expected %lli, found %lli)", \
5364 current_config->name, \
5365 pipe_config->name); \
5366 ret = false; \
5367 } \
5368 } while (0)
5369
5370 #define PIPE_CONF_CHECK_BOOL(name) do { \
5371 if (current_config->name != pipe_config->name) { \
5372 BUILD_BUG_ON_MSG(!__same_type(current_config->name, bool), \
5373 __stringify(name) " is not bool"); \
5374 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5375 "(expected %s, found %s)", \
5376 str_yes_no(current_config->name), \
5377 str_yes_no(pipe_config->name)); \
5378 ret = false; \
5379 } \
5380 } while (0)
5381
5382 #define PIPE_CONF_CHECK_P(name) do { \
5383 if (current_config->name != pipe_config->name) { \
5384 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5385 "(expected %p, found %p)", \
5386 current_config->name, \
5387 pipe_config->name); \
5388 ret = false; \
5389 } \
5390 } while (0)
5391
5392 #define PIPE_CONF_CHECK_M_N(name) do { \
5393 if (!intel_compare_link_m_n(¤t_config->name, \
5394 &pipe_config->name)) { \
5395 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5396 "(expected tu %i data %i/%i link %i/%i, " \
5397 "found tu %i, data %i/%i link %i/%i)", \
5398 current_config->name.tu, \
5399 current_config->name.data_m, \
5400 current_config->name.data_n, \
5401 current_config->name.link_m, \
5402 current_config->name.link_n, \
5403 pipe_config->name.tu, \
5404 pipe_config->name.data_m, \
5405 pipe_config->name.data_n, \
5406 pipe_config->name.link_m, \
5407 pipe_config->name.link_n); \
5408 ret = false; \
5409 } \
5410 } while (0)
5411
5412 #define PIPE_CONF_CHECK_PLL(name) do { \
5413 if (!intel_dpll_compare_hw_state(dev_priv, ¤t_config->name, \
5414 &pipe_config->name)) { \
5415 pipe_config_pll_mismatch(&p, fastset, crtc, __stringify(name), \
5416 ¤t_config->name, \
5417 &pipe_config->name); \
5418 ret = false; \
5419 } \
5420 } while (0)
5421
5422 #define PIPE_CONF_CHECK_PLL_CX0(name) do { \
5423 if (!intel_cx0pll_compare_hw_state(¤t_config->name, \
5424 &pipe_config->name)) { \
5425 pipe_config_cx0pll_mismatch(&p, fastset, crtc, __stringify(name), \
5426 ¤t_config->name, \
5427 &pipe_config->name); \
5428 ret = false; \
5429 } \
5430 } while (0)
5431
5432 #define PIPE_CONF_CHECK_TIMINGS(name) do { \
5433 PIPE_CONF_CHECK_I(name.crtc_hdisplay); \
5434 PIPE_CONF_CHECK_I(name.crtc_htotal); \
5435 PIPE_CONF_CHECK_I(name.crtc_hblank_start); \
5436 PIPE_CONF_CHECK_I(name.crtc_hblank_end); \
5437 PIPE_CONF_CHECK_I(name.crtc_hsync_start); \
5438 PIPE_CONF_CHECK_I(name.crtc_hsync_end); \
5439 PIPE_CONF_CHECK_I(name.crtc_vdisplay); \
5440 PIPE_CONF_CHECK_I(name.crtc_vblank_start); \
5441 PIPE_CONF_CHECK_I(name.crtc_vsync_start); \
5442 PIPE_CONF_CHECK_I(name.crtc_vsync_end); \
5443 if (!fastset || !pipe_config->update_lrr) { \
5444 PIPE_CONF_CHECK_I(name.crtc_vtotal); \
5445 PIPE_CONF_CHECK_I(name.crtc_vblank_end); \
5446 } \
5447 } while (0)
5448
5449 #define PIPE_CONF_CHECK_RECT(name) do { \
5450 PIPE_CONF_CHECK_I(name.x1); \
5451 PIPE_CONF_CHECK_I(name.x2); \
5452 PIPE_CONF_CHECK_I(name.y1); \
5453 PIPE_CONF_CHECK_I(name.y2); \
5454 } while (0)
5455
5456 #define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
5457 if ((current_config->name ^ pipe_config->name) & (mask)) { \
5458 pipe_config_mismatch(&p, fastset, crtc, __stringify(name), \
5459 "(%x) (expected %i, found %i)", \
5460 (mask), \
5461 current_config->name & (mask), \
5462 pipe_config->name & (mask)); \
5463 ret = false; \
5464 } \
5465 } while (0)
5466
5467 #define PIPE_CONF_CHECK_INFOFRAME(name) do { \
5468 if (!intel_compare_infoframe(¤t_config->infoframes.name, \
5469 &pipe_config->infoframes.name)) { \
5470 pipe_config_infoframe_mismatch(&p, fastset, crtc, __stringify(name), \
5471 ¤t_config->infoframes.name, \
5472 &pipe_config->infoframes.name); \
5473 ret = false; \
5474 } \
5475 } while (0)
5476
5477 #define PIPE_CONF_CHECK_DP_VSC_SDP(name) do { \
5478 if (!intel_compare_dp_vsc_sdp(¤t_config->infoframes.name, \
5479 &pipe_config->infoframes.name)) { \
5480 pipe_config_dp_vsc_sdp_mismatch(&p, fastset, crtc, __stringify(name), \
5481 ¤t_config->infoframes.name, \
5482 &pipe_config->infoframes.name); \
5483 ret = false; \
5484 } \
5485 } while (0)
5486
5487 #define PIPE_CONF_CHECK_DP_AS_SDP(name) do { \
5488 if (!intel_compare_dp_as_sdp(¤t_config->infoframes.name, \
5489 &pipe_config->infoframes.name)) { \
5490 pipe_config_dp_as_sdp_mismatch(&p, fastset, crtc, __stringify(name), \
5491 ¤t_config->infoframes.name, \
5492 &pipe_config->infoframes.name); \
5493 ret = false; \
5494 } \
5495 } while (0)
5496
5497 #define PIPE_CONF_CHECK_BUFFER(name, len) do { \
5498 BUILD_BUG_ON(sizeof(current_config->name) != (len)); \
5499 BUILD_BUG_ON(sizeof(pipe_config->name) != (len)); \
5500 if (!intel_compare_buffer(current_config->name, pipe_config->name, (len))) { \
5501 pipe_config_buffer_mismatch(&p, fastset, crtc, __stringify(name), \
5502 current_config->name, \
5503 pipe_config->name, \
5504 (len)); \
5505 ret = false; \
5506 } \
5507 } while (0)
5508
5509 #define PIPE_CONF_CHECK_COLOR_LUT(lut, is_pre_csc_lut) do { \
5510 if (current_config->gamma_mode == pipe_config->gamma_mode && \
5511 !intel_color_lut_equal(current_config, \
5512 current_config->lut, pipe_config->lut, \
5513 is_pre_csc_lut)) { \
5514 pipe_config_mismatch(&p, fastset, crtc, __stringify(lut), \
5515 "hw_state doesn't match sw_state"); \
5516 ret = false; \
5517 } \
5518 } while (0)
5519
5520 #define PIPE_CONF_CHECK_CSC(name) do { \
5521 PIPE_CONF_CHECK_X(name.preoff[0]); \
5522 PIPE_CONF_CHECK_X(name.preoff[1]); \
5523 PIPE_CONF_CHECK_X(name.preoff[2]); \
5524 PIPE_CONF_CHECK_X(name.coeff[0]); \
5525 PIPE_CONF_CHECK_X(name.coeff[1]); \
5526 PIPE_CONF_CHECK_X(name.coeff[2]); \
5527 PIPE_CONF_CHECK_X(name.coeff[3]); \
5528 PIPE_CONF_CHECK_X(name.coeff[4]); \
5529 PIPE_CONF_CHECK_X(name.coeff[5]); \
5530 PIPE_CONF_CHECK_X(name.coeff[6]); \
5531 PIPE_CONF_CHECK_X(name.coeff[7]); \
5532 PIPE_CONF_CHECK_X(name.coeff[8]); \
5533 PIPE_CONF_CHECK_X(name.postoff[0]); \
5534 PIPE_CONF_CHECK_X(name.postoff[1]); \
5535 PIPE_CONF_CHECK_X(name.postoff[2]); \
5536 } while (0)
5537
5538 #define PIPE_CONF_QUIRK(quirk) \
5539 ((current_config->quirks | pipe_config->quirks) & (quirk))
5540
5541 PIPE_CONF_CHECK_BOOL(hw.enable);
5542 PIPE_CONF_CHECK_BOOL(hw.active);
5543
5544 PIPE_CONF_CHECK_I(cpu_transcoder);
5545 PIPE_CONF_CHECK_I(mst_master_transcoder);
5546
5547 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
5548 PIPE_CONF_CHECK_I(fdi_lanes);
5549 PIPE_CONF_CHECK_M_N(fdi_m_n);
5550
5551 PIPE_CONF_CHECK_I(lane_count);
5552 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
5553
5554 if (HAS_DOUBLE_BUFFERED_M_N(display)) {
5555 if (!fastset || !pipe_config->update_m_n)
5556 PIPE_CONF_CHECK_M_N(dp_m_n);
5557 } else {
5558 PIPE_CONF_CHECK_M_N(dp_m_n);
5559 PIPE_CONF_CHECK_M_N(dp_m2_n2);
5560 }
5561
5562 PIPE_CONF_CHECK_X(output_types);
5563
5564 PIPE_CONF_CHECK_I(framestart_delay);
5565 PIPE_CONF_CHECK_I(msa_timing_delay);
5566
5567 PIPE_CONF_CHECK_TIMINGS(hw.pipe_mode);
5568 PIPE_CONF_CHECK_TIMINGS(hw.adjusted_mode);
5569
5570 PIPE_CONF_CHECK_I(pixel_multiplier);
5571
5572 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5573 DRM_MODE_FLAG_INTERLACE);
5574
5575 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
5576 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5577 DRM_MODE_FLAG_PHSYNC);
5578 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5579 DRM_MODE_FLAG_NHSYNC);
5580 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5581 DRM_MODE_FLAG_PVSYNC);
5582 PIPE_CONF_CHECK_FLAGS(hw.adjusted_mode.flags,
5583 DRM_MODE_FLAG_NVSYNC);
5584 }
5585
5586 PIPE_CONF_CHECK_I(output_format);
5587 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
5588 if ((DISPLAY_VER(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
5589 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
5590 PIPE_CONF_CHECK_BOOL(limited_color_range);
5591
5592 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
5593 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
5594 PIPE_CONF_CHECK_BOOL(has_infoframe);
5595 PIPE_CONF_CHECK_BOOL(enhanced_framing);
5596 PIPE_CONF_CHECK_BOOL(fec_enable);
5597
5598 if (!fastset) {
5599 PIPE_CONF_CHECK_BOOL(has_audio);
5600 PIPE_CONF_CHECK_BUFFER(eld, MAX_ELD_BYTES);
5601 }
5602
5603 PIPE_CONF_CHECK_X(gmch_pfit.control);
5604 /* pfit ratios are autocomputed by the hw on gen4+ */
5605 if (DISPLAY_VER(dev_priv) < 4)
5606 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
5607 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
5608
5609 /*
5610 * Changing the EDP transcoder input mux
5611 * (A_ONOFF vs. A_ON) requires a full modeset.
5612 */
5613 PIPE_CONF_CHECK_BOOL(pch_pfit.force_thru);
5614
5615 if (!fastset) {
5616 PIPE_CONF_CHECK_RECT(pipe_src);
5617
5618 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
5619 PIPE_CONF_CHECK_RECT(pch_pfit.dst);
5620
5621 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
5622 PIPE_CONF_CHECK_I(pixel_rate);
5623
5624 PIPE_CONF_CHECK_X(gamma_mode);
5625 if (IS_CHERRYVIEW(dev_priv))
5626 PIPE_CONF_CHECK_X(cgm_mode);
5627 else
5628 PIPE_CONF_CHECK_X(csc_mode);
5629 PIPE_CONF_CHECK_BOOL(gamma_enable);
5630 PIPE_CONF_CHECK_BOOL(csc_enable);
5631 PIPE_CONF_CHECK_BOOL(wgc_enable);
5632
5633 PIPE_CONF_CHECK_I(linetime);
5634 PIPE_CONF_CHECK_I(ips_linetime);
5635
5636 PIPE_CONF_CHECK_COLOR_LUT(pre_csc_lut, true);
5637 PIPE_CONF_CHECK_COLOR_LUT(post_csc_lut, false);
5638
5639 PIPE_CONF_CHECK_CSC(csc);
5640 PIPE_CONF_CHECK_CSC(output_csc);
5641 }
5642
5643 /*
5644 * Panel replay has to be enabled before link training. PSR doesn't have
5645 * this requirement -> check these only if using panel replay
5646 */
5647 if (current_config->active_planes &&
5648 (current_config->has_panel_replay ||
5649 pipe_config->has_panel_replay)) {
5650 PIPE_CONF_CHECK_BOOL(has_psr);
5651 PIPE_CONF_CHECK_BOOL(has_sel_update);
5652 PIPE_CONF_CHECK_BOOL(enable_psr2_sel_fetch);
5653 PIPE_CONF_CHECK_BOOL(enable_psr2_su_region_et);
5654 PIPE_CONF_CHECK_BOOL(has_panel_replay);
5655 }
5656
5657 PIPE_CONF_CHECK_BOOL(double_wide);
5658
5659 if (dev_priv->display.dpll.mgr)
5660 PIPE_CONF_CHECK_P(shared_dpll);
5661
5662 /* FIXME convert everything over the dpll_mgr */
5663 if (dev_priv->display.dpll.mgr || HAS_GMCH(dev_priv))
5664 PIPE_CONF_CHECK_PLL(dpll_hw_state);
5665
5666 /* FIXME convert MTL+ platforms over to dpll_mgr */
5667 if (DISPLAY_VER(dev_priv) >= 14)
5668 PIPE_CONF_CHECK_PLL_CX0(dpll_hw_state.cx0pll);
5669
5670 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
5671 PIPE_CONF_CHECK_X(dsi_pll.div);
5672
5673 if (IS_G4X(dev_priv) || DISPLAY_VER(dev_priv) >= 5)
5674 PIPE_CONF_CHECK_I(pipe_bpp);
5675
5676 if (!fastset || !pipe_config->update_m_n) {
5677 PIPE_CONF_CHECK_I(hw.pipe_mode.crtc_clock);
5678 PIPE_CONF_CHECK_I(hw.adjusted_mode.crtc_clock);
5679 }
5680 PIPE_CONF_CHECK_I(port_clock);
5681
5682 PIPE_CONF_CHECK_I(min_voltage_level);
5683
5684 if (current_config->has_psr || pipe_config->has_psr)
5685 PIPE_CONF_CHECK_X_WITH_MASK(infoframes.enable,
5686 ~intel_hdmi_infoframe_enable(DP_SDP_VSC));
5687 else
5688 PIPE_CONF_CHECK_X(infoframes.enable);
5689
5690 PIPE_CONF_CHECK_X(infoframes.gcp);
5691 PIPE_CONF_CHECK_INFOFRAME(avi);
5692 PIPE_CONF_CHECK_INFOFRAME(spd);
5693 PIPE_CONF_CHECK_INFOFRAME(hdmi);
5694 if (!fastset)
5695 PIPE_CONF_CHECK_INFOFRAME(drm);
5696 PIPE_CONF_CHECK_DP_VSC_SDP(vsc);
5697 PIPE_CONF_CHECK_DP_AS_SDP(as_sdp);
5698
5699 PIPE_CONF_CHECK_X(sync_mode_slaves_mask);
5700 PIPE_CONF_CHECK_I(master_transcoder);
5701 PIPE_CONF_CHECK_X(joiner_pipes);
5702
5703 PIPE_CONF_CHECK_BOOL(dsc.config.block_pred_enable);
5704 PIPE_CONF_CHECK_BOOL(dsc.config.convert_rgb);
5705 PIPE_CONF_CHECK_BOOL(dsc.config.simple_422);
5706 PIPE_CONF_CHECK_BOOL(dsc.config.native_422);
5707 PIPE_CONF_CHECK_BOOL(dsc.config.native_420);
5708 PIPE_CONF_CHECK_BOOL(dsc.config.vbr_enable);
5709 PIPE_CONF_CHECK_I(dsc.config.line_buf_depth);
5710 PIPE_CONF_CHECK_I(dsc.config.bits_per_component);
5711 PIPE_CONF_CHECK_I(dsc.config.pic_width);
5712 PIPE_CONF_CHECK_I(dsc.config.pic_height);
5713 PIPE_CONF_CHECK_I(dsc.config.slice_width);
5714 PIPE_CONF_CHECK_I(dsc.config.slice_height);
5715 PIPE_CONF_CHECK_I(dsc.config.initial_dec_delay);
5716 PIPE_CONF_CHECK_I(dsc.config.initial_xmit_delay);
5717 PIPE_CONF_CHECK_I(dsc.config.scale_decrement_interval);
5718 PIPE_CONF_CHECK_I(dsc.config.scale_increment_interval);
5719 PIPE_CONF_CHECK_I(dsc.config.initial_scale_value);
5720 PIPE_CONF_CHECK_I(dsc.config.first_line_bpg_offset);
5721 PIPE_CONF_CHECK_I(dsc.config.flatness_min_qp);
5722 PIPE_CONF_CHECK_I(dsc.config.flatness_max_qp);
5723 PIPE_CONF_CHECK_I(dsc.config.slice_bpg_offset);
5724 PIPE_CONF_CHECK_I(dsc.config.nfl_bpg_offset);
5725 PIPE_CONF_CHECK_I(dsc.config.initial_offset);
5726 PIPE_CONF_CHECK_I(dsc.config.final_offset);
5727 PIPE_CONF_CHECK_I(dsc.config.rc_model_size);
5728 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit0);
5729 PIPE_CONF_CHECK_I(dsc.config.rc_quant_incr_limit1);
5730 PIPE_CONF_CHECK_I(dsc.config.slice_chunk_size);
5731 PIPE_CONF_CHECK_I(dsc.config.second_line_bpg_offset);
5732 PIPE_CONF_CHECK_I(dsc.config.nsl_bpg_offset);
5733
5734 PIPE_CONF_CHECK_BOOL(dsc.compression_enable);
5735 PIPE_CONF_CHECK_I(dsc.num_streams);
5736 PIPE_CONF_CHECK_I(dsc.compressed_bpp_x16);
5737
5738 PIPE_CONF_CHECK_BOOL(splitter.enable);
5739 PIPE_CONF_CHECK_I(splitter.link_count);
5740 PIPE_CONF_CHECK_I(splitter.pixel_overlap);
5741
5742 if (!fastset) {
5743 PIPE_CONF_CHECK_BOOL(vrr.enable);
5744 PIPE_CONF_CHECK_I(vrr.vmin);
5745 PIPE_CONF_CHECK_I(vrr.vmax);
5746 PIPE_CONF_CHECK_I(vrr.flipline);
5747 PIPE_CONF_CHECK_I(vrr.pipeline_full);
5748 PIPE_CONF_CHECK_I(vrr.guardband);
5749 PIPE_CONF_CHECK_I(vrr.vsync_start);
5750 PIPE_CONF_CHECK_I(vrr.vsync_end);
5751 PIPE_CONF_CHECK_LLI(cmrr.cmrr_m);
5752 PIPE_CONF_CHECK_LLI(cmrr.cmrr_n);
5753 PIPE_CONF_CHECK_BOOL(cmrr.enable);
5754 }
5755
5756 #undef PIPE_CONF_CHECK_X
5757 #undef PIPE_CONF_CHECK_I
5758 #undef PIPE_CONF_CHECK_LLI
5759 #undef PIPE_CONF_CHECK_BOOL
5760 #undef PIPE_CONF_CHECK_P
5761 #undef PIPE_CONF_CHECK_FLAGS
5762 #undef PIPE_CONF_CHECK_COLOR_LUT
5763 #undef PIPE_CONF_CHECK_TIMINGS
5764 #undef PIPE_CONF_CHECK_RECT
5765 #undef PIPE_CONF_QUIRK
5766
5767 return ret;
5768 }
5769
5770 static void
intel_verify_planes(struct intel_atomic_state * state)5771 intel_verify_planes(struct intel_atomic_state *state)
5772 {
5773 struct intel_plane *plane;
5774 const struct intel_plane_state *plane_state;
5775 int i;
5776
5777 for_each_new_intel_plane_in_state(state, plane,
5778 plane_state, i)
5779 assert_plane(plane, plane_state->planar_slave ||
5780 plane_state->uapi.visible);
5781 }
5782
intel_modeset_pipe(struct intel_atomic_state * state,struct intel_crtc_state * crtc_state,const char * reason)5783 static int intel_modeset_pipe(struct intel_atomic_state *state,
5784 struct intel_crtc_state *crtc_state,
5785 const char *reason)
5786 {
5787 struct drm_i915_private *i915 = to_i915(state->base.dev);
5788 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
5789 int ret;
5790
5791 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] Full modeset due to %s\n",
5792 crtc->base.base.id, crtc->base.name, reason);
5793
5794 ret = drm_atomic_add_affected_connectors(&state->base,
5795 &crtc->base);
5796 if (ret)
5797 return ret;
5798
5799 ret = intel_dp_tunnel_atomic_add_state_for_crtc(state, crtc);
5800 if (ret)
5801 return ret;
5802
5803 ret = intel_dp_mst_add_topology_state_for_crtc(state, crtc);
5804 if (ret)
5805 return ret;
5806
5807 ret = intel_atomic_add_affected_planes(state, crtc);
5808 if (ret)
5809 return ret;
5810
5811 crtc_state->uapi.mode_changed = true;
5812
5813 return 0;
5814 }
5815
5816 /**
5817 * intel_modeset_pipes_in_mask_early - force a full modeset on a set of pipes
5818 * @state: intel atomic state
5819 * @reason: the reason for the full modeset
5820 * @mask: mask of pipes to modeset
5821 *
5822 * Add pipes in @mask to @state and force a full modeset on the enabled ones
5823 * due to the description in @reason.
5824 * This function can be called only before new plane states are computed.
5825 *
5826 * Returns 0 in case of success, negative error code otherwise.
5827 */
intel_modeset_pipes_in_mask_early(struct intel_atomic_state * state,const char * reason,u8 mask)5828 int intel_modeset_pipes_in_mask_early(struct intel_atomic_state *state,
5829 const char *reason, u8 mask)
5830 {
5831 struct drm_i915_private *i915 = to_i915(state->base.dev);
5832 struct intel_crtc *crtc;
5833
5834 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, mask) {
5835 struct intel_crtc_state *crtc_state;
5836 int ret;
5837
5838 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5839 if (IS_ERR(crtc_state))
5840 return PTR_ERR(crtc_state);
5841
5842 if (!crtc_state->hw.enable ||
5843 intel_crtc_needs_modeset(crtc_state))
5844 continue;
5845
5846 ret = intel_modeset_pipe(state, crtc_state, reason);
5847 if (ret)
5848 return ret;
5849 }
5850
5851 return 0;
5852 }
5853
5854 static void
intel_crtc_flag_modeset(struct intel_crtc_state * crtc_state)5855 intel_crtc_flag_modeset(struct intel_crtc_state *crtc_state)
5856 {
5857 crtc_state->uapi.mode_changed = true;
5858
5859 crtc_state->update_pipe = false;
5860 crtc_state->update_m_n = false;
5861 crtc_state->update_lrr = false;
5862 }
5863
5864 /**
5865 * intel_modeset_all_pipes_late - force a full modeset on all pipes
5866 * @state: intel atomic state
5867 * @reason: the reason for the full modeset
5868 *
5869 * Add all pipes to @state and force a full modeset on the active ones due to
5870 * the description in @reason.
5871 * This function can be called only after new plane states are computed already.
5872 *
5873 * Returns 0 in case of success, negative error code otherwise.
5874 */
intel_modeset_all_pipes_late(struct intel_atomic_state * state,const char * reason)5875 int intel_modeset_all_pipes_late(struct intel_atomic_state *state,
5876 const char *reason)
5877 {
5878 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
5879 struct intel_crtc *crtc;
5880
5881 for_each_intel_crtc(&dev_priv->drm, crtc) {
5882 struct intel_crtc_state *crtc_state;
5883 int ret;
5884
5885 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5886 if (IS_ERR(crtc_state))
5887 return PTR_ERR(crtc_state);
5888
5889 if (!crtc_state->hw.active ||
5890 intel_crtc_needs_modeset(crtc_state))
5891 continue;
5892
5893 ret = intel_modeset_pipe(state, crtc_state, reason);
5894 if (ret)
5895 return ret;
5896
5897 intel_crtc_flag_modeset(crtc_state);
5898
5899 crtc_state->update_planes |= crtc_state->active_planes;
5900 crtc_state->async_flip_planes = 0;
5901 crtc_state->do_async_flip = false;
5902 }
5903
5904 return 0;
5905 }
5906
intel_modeset_commit_pipes(struct drm_i915_private * i915,u8 pipe_mask,struct drm_modeset_acquire_ctx * ctx)5907 int intel_modeset_commit_pipes(struct drm_i915_private *i915,
5908 u8 pipe_mask,
5909 struct drm_modeset_acquire_ctx *ctx)
5910 {
5911 struct drm_atomic_state *state;
5912 struct intel_crtc *crtc;
5913 int ret;
5914
5915 state = drm_atomic_state_alloc(&i915->drm);
5916 if (!state)
5917 return -ENOMEM;
5918
5919 state->acquire_ctx = ctx;
5920 to_intel_atomic_state(state)->internal = true;
5921
5922 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, pipe_mask) {
5923 struct intel_crtc_state *crtc_state =
5924 intel_atomic_get_crtc_state(state, crtc);
5925
5926 if (IS_ERR(crtc_state)) {
5927 ret = PTR_ERR(crtc_state);
5928 goto out;
5929 }
5930
5931 crtc_state->uapi.connectors_changed = true;
5932 }
5933
5934 ret = drm_atomic_commit(state);
5935 out:
5936 drm_atomic_state_put(state);
5937
5938 return ret;
5939 }
5940
5941 /*
5942 * This implements the workaround described in the "notes" section of the mode
5943 * set sequence documentation. When going from no pipes or single pipe to
5944 * multiple pipes, and planes are enabled after the pipe, we need to wait at
5945 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
5946 */
hsw_mode_set_planes_workaround(struct intel_atomic_state * state)5947 static int hsw_mode_set_planes_workaround(struct intel_atomic_state *state)
5948 {
5949 struct intel_crtc_state *crtc_state;
5950 struct intel_crtc *crtc;
5951 struct intel_crtc_state *first_crtc_state = NULL;
5952 struct intel_crtc_state *other_crtc_state = NULL;
5953 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
5954 int i;
5955
5956 /* look at all crtc's that are going to be enabled in during modeset */
5957 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
5958 if (!crtc_state->hw.active ||
5959 !intel_crtc_needs_modeset(crtc_state))
5960 continue;
5961
5962 if (first_crtc_state) {
5963 other_crtc_state = crtc_state;
5964 break;
5965 } else {
5966 first_crtc_state = crtc_state;
5967 first_pipe = crtc->pipe;
5968 }
5969 }
5970
5971 /* No workaround needed? */
5972 if (!first_crtc_state)
5973 return 0;
5974
5975 /* w/a possibly needed, check how many crtc's are already enabled. */
5976 for_each_intel_crtc(state->base.dev, crtc) {
5977 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
5978 if (IS_ERR(crtc_state))
5979 return PTR_ERR(crtc_state);
5980
5981 crtc_state->hsw_workaround_pipe = INVALID_PIPE;
5982
5983 if (!crtc_state->hw.active ||
5984 intel_crtc_needs_modeset(crtc_state))
5985 continue;
5986
5987 /* 2 or more enabled crtcs means no need for w/a */
5988 if (enabled_pipe != INVALID_PIPE)
5989 return 0;
5990
5991 enabled_pipe = crtc->pipe;
5992 }
5993
5994 if (enabled_pipe != INVALID_PIPE)
5995 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
5996 else if (other_crtc_state)
5997 other_crtc_state->hsw_workaround_pipe = first_pipe;
5998
5999 return 0;
6000 }
6001
intel_calc_active_pipes(struct intel_atomic_state * state,u8 active_pipes)6002 u8 intel_calc_active_pipes(struct intel_atomic_state *state,
6003 u8 active_pipes)
6004 {
6005 const struct intel_crtc_state *crtc_state;
6006 struct intel_crtc *crtc;
6007 int i;
6008
6009 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6010 if (crtc_state->hw.active)
6011 active_pipes |= BIT(crtc->pipe);
6012 else
6013 active_pipes &= ~BIT(crtc->pipe);
6014 }
6015
6016 return active_pipes;
6017 }
6018
intel_modeset_checks(struct intel_atomic_state * state)6019 static int intel_modeset_checks(struct intel_atomic_state *state)
6020 {
6021 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6022
6023 state->modeset = true;
6024
6025 if (IS_HASWELL(dev_priv))
6026 return hsw_mode_set_planes_workaround(state);
6027
6028 return 0;
6029 }
6030
intel_crtc_check_fastset(const struct intel_crtc_state * old_crtc_state,struct intel_crtc_state * new_crtc_state)6031 static void intel_crtc_check_fastset(const struct intel_crtc_state *old_crtc_state,
6032 struct intel_crtc_state *new_crtc_state)
6033 {
6034 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
6035 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
6036
6037 /* only allow LRR when the timings stay within the VRR range */
6038 if (old_crtc_state->vrr.in_range != new_crtc_state->vrr.in_range)
6039 new_crtc_state->update_lrr = false;
6040
6041 if (!intel_pipe_config_compare(old_crtc_state, new_crtc_state, true))
6042 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s] fastset requirement not met, forcing full modeset\n",
6043 crtc->base.base.id, crtc->base.name);
6044 else
6045 new_crtc_state->uapi.mode_changed = false;
6046
6047 if (intel_compare_link_m_n(&old_crtc_state->dp_m_n,
6048 &new_crtc_state->dp_m_n))
6049 new_crtc_state->update_m_n = false;
6050
6051 if ((old_crtc_state->hw.adjusted_mode.crtc_vtotal == new_crtc_state->hw.adjusted_mode.crtc_vtotal &&
6052 old_crtc_state->hw.adjusted_mode.crtc_vblank_end == new_crtc_state->hw.adjusted_mode.crtc_vblank_end))
6053 new_crtc_state->update_lrr = false;
6054
6055 if (intel_crtc_needs_modeset(new_crtc_state))
6056 intel_crtc_flag_modeset(new_crtc_state);
6057 else
6058 new_crtc_state->update_pipe = true;
6059 }
6060
intel_crtc_add_planes_to_state(struct intel_atomic_state * state,struct intel_crtc * crtc,u8 plane_ids_mask)6061 static int intel_crtc_add_planes_to_state(struct intel_atomic_state *state,
6062 struct intel_crtc *crtc,
6063 u8 plane_ids_mask)
6064 {
6065 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6066 struct intel_plane *plane;
6067
6068 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
6069 struct intel_plane_state *plane_state;
6070
6071 if ((plane_ids_mask & BIT(plane->id)) == 0)
6072 continue;
6073
6074 plane_state = intel_atomic_get_plane_state(state, plane);
6075 if (IS_ERR(plane_state))
6076 return PTR_ERR(plane_state);
6077 }
6078
6079 return 0;
6080 }
6081
intel_atomic_add_affected_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)6082 int intel_atomic_add_affected_planes(struct intel_atomic_state *state,
6083 struct intel_crtc *crtc)
6084 {
6085 const struct intel_crtc_state *old_crtc_state =
6086 intel_atomic_get_old_crtc_state(state, crtc);
6087 const struct intel_crtc_state *new_crtc_state =
6088 intel_atomic_get_new_crtc_state(state, crtc);
6089
6090 return intel_crtc_add_planes_to_state(state, crtc,
6091 old_crtc_state->enabled_planes |
6092 new_crtc_state->enabled_planes);
6093 }
6094
active_planes_affects_min_cdclk(struct drm_i915_private * dev_priv)6095 static bool active_planes_affects_min_cdclk(struct drm_i915_private *dev_priv)
6096 {
6097 /* See {hsw,vlv,ivb}_plane_ratio() */
6098 return IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv) ||
6099 IS_CHERRYVIEW(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
6100 IS_IVYBRIDGE(dev_priv);
6101 }
6102
intel_crtc_add_joiner_planes(struct intel_atomic_state * state,struct intel_crtc * crtc,struct intel_crtc * other)6103 static int intel_crtc_add_joiner_planes(struct intel_atomic_state *state,
6104 struct intel_crtc *crtc,
6105 struct intel_crtc *other)
6106 {
6107 const struct intel_plane_state __maybe_unused *plane_state;
6108 struct intel_plane *plane;
6109 u8 plane_ids = 0;
6110 int i;
6111
6112 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6113 if (plane->pipe == crtc->pipe)
6114 plane_ids |= BIT(plane->id);
6115 }
6116
6117 return intel_crtc_add_planes_to_state(state, other, plane_ids);
6118 }
6119
intel_joiner_add_affected_planes(struct intel_atomic_state * state)6120 static int intel_joiner_add_affected_planes(struct intel_atomic_state *state)
6121 {
6122 struct drm_i915_private *i915 = to_i915(state->base.dev);
6123 const struct intel_crtc_state *crtc_state;
6124 struct intel_crtc *crtc;
6125 int i;
6126
6127 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6128 struct intel_crtc *other;
6129
6130 for_each_intel_crtc_in_pipe_mask(&i915->drm, other,
6131 crtc_state->joiner_pipes) {
6132 int ret;
6133
6134 if (crtc == other)
6135 continue;
6136
6137 ret = intel_crtc_add_joiner_planes(state, crtc, other);
6138 if (ret)
6139 return ret;
6140 }
6141 }
6142
6143 return 0;
6144 }
6145
intel_atomic_check_planes(struct intel_atomic_state * state)6146 static int intel_atomic_check_planes(struct intel_atomic_state *state)
6147 {
6148 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
6149 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6150 struct intel_plane_state __maybe_unused *plane_state;
6151 struct intel_plane *plane;
6152 struct intel_crtc *crtc;
6153 int i, ret;
6154
6155 ret = icl_add_linked_planes(state);
6156 if (ret)
6157 return ret;
6158
6159 ret = intel_joiner_add_affected_planes(state);
6160 if (ret)
6161 return ret;
6162
6163 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6164 ret = intel_plane_atomic_check(state, plane);
6165 if (ret) {
6166 drm_dbg_atomic(&dev_priv->drm,
6167 "[PLANE:%d:%s] atomic driver check failed\n",
6168 plane->base.base.id, plane->base.name);
6169 return ret;
6170 }
6171 }
6172
6173 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6174 new_crtc_state, i) {
6175 u8 old_active_planes, new_active_planes;
6176
6177 ret = icl_check_nv12_planes(state, crtc);
6178 if (ret)
6179 return ret;
6180
6181 /*
6182 * On some platforms the number of active planes affects
6183 * the planes' minimum cdclk calculation. Add such planes
6184 * to the state before we compute the minimum cdclk.
6185 */
6186 if (!active_planes_affects_min_cdclk(dev_priv))
6187 continue;
6188
6189 old_active_planes = old_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
6190 new_active_planes = new_crtc_state->active_planes & ~BIT(PLANE_CURSOR);
6191
6192 if (hweight8(old_active_planes) == hweight8(new_active_planes))
6193 continue;
6194
6195 ret = intel_crtc_add_planes_to_state(state, crtc, new_active_planes);
6196 if (ret)
6197 return ret;
6198 }
6199
6200 return 0;
6201 }
6202
intel_atomic_check_crtcs(struct intel_atomic_state * state)6203 static int intel_atomic_check_crtcs(struct intel_atomic_state *state)
6204 {
6205 struct intel_crtc_state __maybe_unused *crtc_state;
6206 struct intel_crtc *crtc;
6207 int i;
6208
6209 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6210 struct drm_i915_private *i915 = to_i915(crtc->base.dev);
6211 int ret;
6212
6213 ret = intel_crtc_atomic_check(state, crtc);
6214 if (ret) {
6215 drm_dbg_atomic(&i915->drm,
6216 "[CRTC:%d:%s] atomic driver check failed\n",
6217 crtc->base.base.id, crtc->base.name);
6218 return ret;
6219 }
6220 }
6221
6222 return 0;
6223 }
6224
intel_cpu_transcoders_need_modeset(struct intel_atomic_state * state,u8 transcoders)6225 static bool intel_cpu_transcoders_need_modeset(struct intel_atomic_state *state,
6226 u8 transcoders)
6227 {
6228 const struct intel_crtc_state *new_crtc_state;
6229 struct intel_crtc *crtc;
6230 int i;
6231
6232 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6233 if (new_crtc_state->hw.enable &&
6234 transcoders & BIT(new_crtc_state->cpu_transcoder) &&
6235 intel_crtc_needs_modeset(new_crtc_state))
6236 return true;
6237 }
6238
6239 return false;
6240 }
6241
intel_pipes_need_modeset(struct intel_atomic_state * state,u8 pipes)6242 static bool intel_pipes_need_modeset(struct intel_atomic_state *state,
6243 u8 pipes)
6244 {
6245 const struct intel_crtc_state *new_crtc_state;
6246 struct intel_crtc *crtc;
6247 int i;
6248
6249 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6250 if (new_crtc_state->hw.enable &&
6251 pipes & BIT(crtc->pipe) &&
6252 intel_crtc_needs_modeset(new_crtc_state))
6253 return true;
6254 }
6255
6256 return false;
6257 }
6258
intel_atomic_check_joiner(struct intel_atomic_state * state,struct intel_crtc * primary_crtc)6259 static int intel_atomic_check_joiner(struct intel_atomic_state *state,
6260 struct intel_crtc *primary_crtc)
6261 {
6262 struct drm_i915_private *i915 = to_i915(state->base.dev);
6263 struct intel_crtc_state *primary_crtc_state =
6264 intel_atomic_get_new_crtc_state(state, primary_crtc);
6265 struct intel_crtc *secondary_crtc;
6266
6267 if (!primary_crtc_state->joiner_pipes)
6268 return 0;
6269
6270 /* sanity check */
6271 if (drm_WARN_ON(&i915->drm,
6272 primary_crtc->pipe != joiner_primary_pipe(primary_crtc_state)))
6273 return -EINVAL;
6274
6275 if (primary_crtc_state->joiner_pipes & ~joiner_pipes(i915)) {
6276 drm_dbg_kms(&i915->drm,
6277 "[CRTC:%d:%s] Cannot act as joiner primary "
6278 "(need 0x%x as pipes, only 0x%x possible)\n",
6279 primary_crtc->base.base.id, primary_crtc->base.name,
6280 primary_crtc_state->joiner_pipes, joiner_pipes(i915));
6281 return -EINVAL;
6282 }
6283
6284 for_each_intel_crtc_in_pipe_mask(&i915->drm, secondary_crtc,
6285 intel_crtc_joiner_secondary_pipes(primary_crtc_state)) {
6286 struct intel_crtc_state *secondary_crtc_state;
6287 int ret;
6288
6289 secondary_crtc_state = intel_atomic_get_crtc_state(&state->base, secondary_crtc);
6290 if (IS_ERR(secondary_crtc_state))
6291 return PTR_ERR(secondary_crtc_state);
6292
6293 /* primary being enabled, secondary was already configured? */
6294 if (secondary_crtc_state->uapi.enable) {
6295 drm_dbg_kms(&i915->drm,
6296 "[CRTC:%d:%s] secondary is enabled as normal CRTC, but "
6297 "[CRTC:%d:%s] claiming this CRTC for joiner.\n",
6298 secondary_crtc->base.base.id, secondary_crtc->base.name,
6299 primary_crtc->base.base.id, primary_crtc->base.name);
6300 return -EINVAL;
6301 }
6302
6303 /*
6304 * The state copy logic assumes the primary crtc gets processed
6305 * before the secondary crtc during the main compute_config loop.
6306 * This works because the crtcs are created in pipe order,
6307 * and the hardware requires primary pipe < secondary pipe as well.
6308 * Should that change we need to rethink the logic.
6309 */
6310 if (WARN_ON(drm_crtc_index(&primary_crtc->base) >
6311 drm_crtc_index(&secondary_crtc->base)))
6312 return -EINVAL;
6313
6314 drm_dbg_kms(&i915->drm,
6315 "[CRTC:%d:%s] Used as secondary for joiner primary [CRTC:%d:%s]\n",
6316 secondary_crtc->base.base.id, secondary_crtc->base.name,
6317 primary_crtc->base.base.id, primary_crtc->base.name);
6318
6319 secondary_crtc_state->joiner_pipes =
6320 primary_crtc_state->joiner_pipes;
6321
6322 ret = copy_joiner_crtc_state_modeset(state, secondary_crtc);
6323 if (ret)
6324 return ret;
6325 }
6326
6327 return 0;
6328 }
6329
kill_joiner_secondaries(struct intel_atomic_state * state,struct intel_crtc * primary_crtc)6330 static void kill_joiner_secondaries(struct intel_atomic_state *state,
6331 struct intel_crtc *primary_crtc)
6332 {
6333 struct drm_i915_private *i915 = to_i915(state->base.dev);
6334 struct intel_crtc_state *primary_crtc_state =
6335 intel_atomic_get_new_crtc_state(state, primary_crtc);
6336 struct intel_crtc *secondary_crtc;
6337
6338 for_each_intel_crtc_in_pipe_mask(&i915->drm, secondary_crtc,
6339 intel_crtc_joiner_secondary_pipes(primary_crtc_state)) {
6340 struct intel_crtc_state *secondary_crtc_state =
6341 intel_atomic_get_new_crtc_state(state, secondary_crtc);
6342
6343 secondary_crtc_state->joiner_pipes = 0;
6344
6345 intel_crtc_copy_uapi_to_hw_state_modeset(state, secondary_crtc);
6346 }
6347
6348 primary_crtc_state->joiner_pipes = 0;
6349 }
6350
6351 /**
6352 * DOC: asynchronous flip implementation
6353 *
6354 * Asynchronous page flip is the implementation for the DRM_MODE_PAGE_FLIP_ASYNC
6355 * flag. Currently async flip is only supported via the drmModePageFlip IOCTL.
6356 * Correspondingly, support is currently added for primary plane only.
6357 *
6358 * Async flip can only change the plane surface address, so anything else
6359 * changing is rejected from the intel_async_flip_check_hw() function.
6360 * Once this check is cleared, flip done interrupt is enabled using
6361 * the intel_crtc_enable_flip_done() function.
6362 *
6363 * As soon as the surface address register is written, flip done interrupt is
6364 * generated and the requested events are sent to the usersapce in the interrupt
6365 * handler itself. The timestamp and sequence sent during the flip done event
6366 * correspond to the last vblank and have no relation to the actual time when
6367 * the flip done event was sent.
6368 */
intel_async_flip_check_uapi(struct intel_atomic_state * state,struct intel_crtc * crtc)6369 static int intel_async_flip_check_uapi(struct intel_atomic_state *state,
6370 struct intel_crtc *crtc)
6371 {
6372 struct drm_i915_private *i915 = to_i915(state->base.dev);
6373 const struct intel_crtc_state *new_crtc_state =
6374 intel_atomic_get_new_crtc_state(state, crtc);
6375 const struct intel_plane_state *old_plane_state;
6376 struct intel_plane_state *new_plane_state;
6377 struct intel_plane *plane;
6378 int i;
6379
6380 if (!new_crtc_state->uapi.async_flip)
6381 return 0;
6382
6383 if (!new_crtc_state->uapi.active) {
6384 drm_dbg_kms(&i915->drm,
6385 "[CRTC:%d:%s] not active\n",
6386 crtc->base.base.id, crtc->base.name);
6387 return -EINVAL;
6388 }
6389
6390 if (intel_crtc_needs_modeset(new_crtc_state)) {
6391 drm_dbg_kms(&i915->drm,
6392 "[CRTC:%d:%s] modeset required\n",
6393 crtc->base.base.id, crtc->base.name);
6394 return -EINVAL;
6395 }
6396
6397 /*
6398 * FIXME: joiner+async flip is busted currently.
6399 * Remove this check once the issues are fixed.
6400 */
6401 if (new_crtc_state->joiner_pipes) {
6402 drm_dbg_kms(&i915->drm,
6403 "[CRTC:%d:%s] async flip disallowed with joiner\n",
6404 crtc->base.base.id, crtc->base.name);
6405 return -EINVAL;
6406 }
6407
6408 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6409 new_plane_state, i) {
6410 if (plane->pipe != crtc->pipe)
6411 continue;
6412
6413 /*
6414 * TODO: Async flip is only supported through the page flip IOCTL
6415 * as of now. So support currently added for primary plane only.
6416 * Support for other planes on platforms on which supports
6417 * this(vlv/chv and icl+) should be added when async flip is
6418 * enabled in the atomic IOCTL path.
6419 */
6420 if (!plane->async_flip) {
6421 drm_dbg_kms(&i915->drm,
6422 "[PLANE:%d:%s] async flip not supported\n",
6423 plane->base.base.id, plane->base.name);
6424 return -EINVAL;
6425 }
6426
6427 if (!old_plane_state->uapi.fb || !new_plane_state->uapi.fb) {
6428 drm_dbg_kms(&i915->drm,
6429 "[PLANE:%d:%s] no old or new framebuffer\n",
6430 plane->base.base.id, plane->base.name);
6431 return -EINVAL;
6432 }
6433 }
6434
6435 return 0;
6436 }
6437
intel_async_flip_check_hw(struct intel_atomic_state * state,struct intel_crtc * crtc)6438 static int intel_async_flip_check_hw(struct intel_atomic_state *state, struct intel_crtc *crtc)
6439 {
6440 struct drm_i915_private *i915 = to_i915(state->base.dev);
6441 const struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6442 const struct intel_plane_state *new_plane_state, *old_plane_state;
6443 struct intel_plane *plane;
6444 int i;
6445
6446 old_crtc_state = intel_atomic_get_old_crtc_state(state, crtc);
6447 new_crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6448
6449 if (!new_crtc_state->uapi.async_flip)
6450 return 0;
6451
6452 if (!new_crtc_state->hw.active) {
6453 drm_dbg_kms(&i915->drm,
6454 "[CRTC:%d:%s] not active\n",
6455 crtc->base.base.id, crtc->base.name);
6456 return -EINVAL;
6457 }
6458
6459 if (intel_crtc_needs_modeset(new_crtc_state)) {
6460 drm_dbg_kms(&i915->drm,
6461 "[CRTC:%d:%s] modeset required\n",
6462 crtc->base.base.id, crtc->base.name);
6463 return -EINVAL;
6464 }
6465
6466 if (old_crtc_state->active_planes != new_crtc_state->active_planes) {
6467 drm_dbg_kms(&i915->drm,
6468 "[CRTC:%d:%s] Active planes cannot be in async flip\n",
6469 crtc->base.base.id, crtc->base.name);
6470 return -EINVAL;
6471 }
6472
6473 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
6474 new_plane_state, i) {
6475 if (plane->pipe != crtc->pipe)
6476 continue;
6477
6478 /*
6479 * Only async flip capable planes should be in the state
6480 * if we're really about to ask the hardware to perform
6481 * an async flip. We should never get this far otherwise.
6482 */
6483 if (drm_WARN_ON(&i915->drm,
6484 new_crtc_state->do_async_flip && !plane->async_flip))
6485 return -EINVAL;
6486
6487 /*
6488 * Only check async flip capable planes other planes
6489 * may be involved in the initial commit due to
6490 * the wm0/ddb optimization.
6491 *
6492 * TODO maybe should track which planes actually
6493 * were requested to do the async flip...
6494 */
6495 if (!plane->async_flip)
6496 continue;
6497
6498 /*
6499 * FIXME: This check is kept generic for all platforms.
6500 * Need to verify this for all gen9 platforms to enable
6501 * this selectively if required.
6502 */
6503 switch (new_plane_state->hw.fb->modifier) {
6504 case DRM_FORMAT_MOD_LINEAR:
6505 /*
6506 * FIXME: Async on Linear buffer is supported on ICL as
6507 * but with additional alignment and fbc restrictions
6508 * need to be taken care of. These aren't applicable for
6509 * gen12+.
6510 */
6511 if (DISPLAY_VER(i915) < 12) {
6512 drm_dbg_kms(&i915->drm,
6513 "[PLANE:%d:%s] Modifier 0x%llx does not support async flip on display ver %d\n",
6514 plane->base.base.id, plane->base.name,
6515 new_plane_state->hw.fb->modifier, DISPLAY_VER(i915));
6516 return -EINVAL;
6517 }
6518 break;
6519
6520 case I915_FORMAT_MOD_X_TILED:
6521 case I915_FORMAT_MOD_Y_TILED:
6522 case I915_FORMAT_MOD_Yf_TILED:
6523 case I915_FORMAT_MOD_4_TILED:
6524 case I915_FORMAT_MOD_4_TILED_BMG_CCS:
6525 case I915_FORMAT_MOD_4_TILED_LNL_CCS:
6526 break;
6527 default:
6528 drm_dbg_kms(&i915->drm,
6529 "[PLANE:%d:%s] Modifier 0x%llx does not support async flip\n",
6530 plane->base.base.id, plane->base.name,
6531 new_plane_state->hw.fb->modifier);
6532 return -EINVAL;
6533 }
6534
6535 if (new_plane_state->hw.fb->format->num_planes > 1) {
6536 drm_dbg_kms(&i915->drm,
6537 "[PLANE:%d:%s] Planar formats do not support async flips\n",
6538 plane->base.base.id, plane->base.name);
6539 return -EINVAL;
6540 }
6541
6542 /*
6543 * We turn the first async flip request into a sync flip
6544 * so that we can reconfigure the plane (eg. change modifier).
6545 */
6546 if (!new_crtc_state->do_async_flip)
6547 continue;
6548
6549 if (old_plane_state->view.color_plane[0].mapping_stride !=
6550 new_plane_state->view.color_plane[0].mapping_stride) {
6551 drm_dbg_kms(&i915->drm,
6552 "[PLANE:%d:%s] Stride cannot be changed in async flip\n",
6553 plane->base.base.id, plane->base.name);
6554 return -EINVAL;
6555 }
6556
6557 if (old_plane_state->hw.fb->modifier !=
6558 new_plane_state->hw.fb->modifier) {
6559 drm_dbg_kms(&i915->drm,
6560 "[PLANE:%d:%s] Modifier cannot be changed in async flip\n",
6561 plane->base.base.id, plane->base.name);
6562 return -EINVAL;
6563 }
6564
6565 if (old_plane_state->hw.fb->format !=
6566 new_plane_state->hw.fb->format) {
6567 drm_dbg_kms(&i915->drm,
6568 "[PLANE:%d:%s] Pixel format cannot be changed in async flip\n",
6569 plane->base.base.id, plane->base.name);
6570 return -EINVAL;
6571 }
6572
6573 if (old_plane_state->hw.rotation !=
6574 new_plane_state->hw.rotation) {
6575 drm_dbg_kms(&i915->drm,
6576 "[PLANE:%d:%s] Rotation cannot be changed in async flip\n",
6577 plane->base.base.id, plane->base.name);
6578 return -EINVAL;
6579 }
6580
6581 if (!drm_rect_equals(&old_plane_state->uapi.src, &new_plane_state->uapi.src) ||
6582 !drm_rect_equals(&old_plane_state->uapi.dst, &new_plane_state->uapi.dst)) {
6583 drm_dbg_kms(&i915->drm,
6584 "[PLANE:%d:%s] Size/co-ordinates cannot be changed in async flip\n",
6585 plane->base.base.id, plane->base.name);
6586 return -EINVAL;
6587 }
6588
6589 if (old_plane_state->hw.alpha != new_plane_state->hw.alpha) {
6590 drm_dbg_kms(&i915->drm,
6591 "[PLANES:%d:%s] Alpha value cannot be changed in async flip\n",
6592 plane->base.base.id, plane->base.name);
6593 return -EINVAL;
6594 }
6595
6596 if (old_plane_state->hw.pixel_blend_mode !=
6597 new_plane_state->hw.pixel_blend_mode) {
6598 drm_dbg_kms(&i915->drm,
6599 "[PLANE:%d:%s] Pixel blend mode cannot be changed in async flip\n",
6600 plane->base.base.id, plane->base.name);
6601 return -EINVAL;
6602 }
6603
6604 if (old_plane_state->hw.color_encoding != new_plane_state->hw.color_encoding) {
6605 drm_dbg_kms(&i915->drm,
6606 "[PLANE:%d:%s] Color encoding cannot be changed in async flip\n",
6607 plane->base.base.id, plane->base.name);
6608 return -EINVAL;
6609 }
6610
6611 if (old_plane_state->hw.color_range != new_plane_state->hw.color_range) {
6612 drm_dbg_kms(&i915->drm,
6613 "[PLANE:%d:%s] Color range cannot be changed in async flip\n",
6614 plane->base.base.id, plane->base.name);
6615 return -EINVAL;
6616 }
6617
6618 /* plane decryption is allow to change only in synchronous flips */
6619 if (old_plane_state->decrypt != new_plane_state->decrypt) {
6620 drm_dbg_kms(&i915->drm,
6621 "[PLANE:%d:%s] Decryption cannot be changed in async flip\n",
6622 plane->base.base.id, plane->base.name);
6623 return -EINVAL;
6624 }
6625 }
6626
6627 return 0;
6628 }
6629
intel_joiner_add_affected_crtcs(struct intel_atomic_state * state)6630 static int intel_joiner_add_affected_crtcs(struct intel_atomic_state *state)
6631 {
6632 struct drm_i915_private *i915 = to_i915(state->base.dev);
6633 const struct intel_plane_state *plane_state;
6634 struct intel_crtc_state *crtc_state;
6635 struct intel_plane *plane;
6636 struct intel_crtc *crtc;
6637 u8 affected_pipes = 0;
6638 u8 modeset_pipes = 0;
6639 int i;
6640
6641 /*
6642 * Any plane which is in use by the joiner needs its crtc.
6643 * Pull those in first as this will not have happened yet
6644 * if the plane remains disabled according to uapi.
6645 */
6646 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
6647 crtc = to_intel_crtc(plane_state->hw.crtc);
6648 if (!crtc)
6649 continue;
6650
6651 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6652 if (IS_ERR(crtc_state))
6653 return PTR_ERR(crtc_state);
6654 }
6655
6656 /* Now pull in all joined crtcs */
6657 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6658 affected_pipes |= crtc_state->joiner_pipes;
6659 if (intel_crtc_needs_modeset(crtc_state))
6660 modeset_pipes |= crtc_state->joiner_pipes;
6661 }
6662
6663 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, affected_pipes) {
6664 crtc_state = intel_atomic_get_crtc_state(&state->base, crtc);
6665 if (IS_ERR(crtc_state))
6666 return PTR_ERR(crtc_state);
6667 }
6668
6669 for_each_intel_crtc_in_pipe_mask(&i915->drm, crtc, modeset_pipes) {
6670 int ret;
6671
6672 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
6673
6674 crtc_state->uapi.mode_changed = true;
6675
6676 ret = drm_atomic_add_affected_connectors(&state->base, &crtc->base);
6677 if (ret)
6678 return ret;
6679
6680 ret = intel_atomic_add_affected_planes(state, crtc);
6681 if (ret)
6682 return ret;
6683 }
6684
6685 for_each_new_intel_crtc_in_state(state, crtc, crtc_state, i) {
6686 /* Kill old joiner link, we may re-establish afterwards */
6687 if (intel_crtc_needs_modeset(crtc_state) &&
6688 intel_crtc_is_joiner_primary(crtc_state))
6689 kill_joiner_secondaries(state, crtc);
6690 }
6691
6692 return 0;
6693 }
6694
intel_atomic_check_config(struct intel_atomic_state * state,struct intel_link_bw_limits * limits,enum pipe * failed_pipe)6695 static int intel_atomic_check_config(struct intel_atomic_state *state,
6696 struct intel_link_bw_limits *limits,
6697 enum pipe *failed_pipe)
6698 {
6699 struct drm_i915_private *i915 = to_i915(state->base.dev);
6700 struct intel_crtc_state *new_crtc_state;
6701 struct intel_crtc *crtc;
6702 int ret;
6703 int i;
6704
6705 *failed_pipe = INVALID_PIPE;
6706
6707 ret = intel_joiner_add_affected_crtcs(state);
6708 if (ret)
6709 return ret;
6710
6711 ret = intel_fdi_add_affected_crtcs(state);
6712 if (ret)
6713 return ret;
6714
6715 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6716 if (!intel_crtc_needs_modeset(new_crtc_state)) {
6717 if (intel_crtc_is_joiner_secondary(new_crtc_state))
6718 copy_joiner_crtc_state_nomodeset(state, crtc);
6719 else
6720 intel_crtc_copy_uapi_to_hw_state_nomodeset(state, crtc);
6721 continue;
6722 }
6723
6724 if (drm_WARN_ON(&i915->drm, intel_crtc_is_joiner_secondary(new_crtc_state)))
6725 continue;
6726
6727 ret = intel_crtc_prepare_cleared_state(state, crtc);
6728 if (ret)
6729 goto fail;
6730
6731 if (!new_crtc_state->hw.enable)
6732 continue;
6733
6734 ret = intel_modeset_pipe_config(state, crtc, limits);
6735 if (ret)
6736 goto fail;
6737 }
6738
6739 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6740 if (!intel_crtc_needs_modeset(new_crtc_state))
6741 continue;
6742
6743 if (drm_WARN_ON(&i915->drm, intel_crtc_is_joiner_secondary(new_crtc_state)))
6744 continue;
6745
6746 if (!new_crtc_state->hw.enable)
6747 continue;
6748
6749 ret = intel_modeset_pipe_config_late(state, crtc);
6750 if (ret)
6751 goto fail;
6752 }
6753
6754 fail:
6755 if (ret)
6756 *failed_pipe = crtc->pipe;
6757
6758 return ret;
6759 }
6760
intel_atomic_check_config_and_link(struct intel_atomic_state * state)6761 static int intel_atomic_check_config_and_link(struct intel_atomic_state *state)
6762 {
6763 struct intel_link_bw_limits new_limits;
6764 struct intel_link_bw_limits old_limits;
6765 int ret;
6766
6767 intel_link_bw_init_limits(state, &new_limits);
6768 old_limits = new_limits;
6769
6770 while (true) {
6771 enum pipe failed_pipe;
6772
6773 ret = intel_atomic_check_config(state, &new_limits,
6774 &failed_pipe);
6775 if (ret) {
6776 /*
6777 * The bpp limit for a pipe is below the minimum it supports, set the
6778 * limit to the minimum and recalculate the config.
6779 */
6780 if (ret == -EINVAL &&
6781 intel_link_bw_set_bpp_limit_for_pipe(state,
6782 &old_limits,
6783 &new_limits,
6784 failed_pipe))
6785 continue;
6786
6787 break;
6788 }
6789
6790 old_limits = new_limits;
6791
6792 ret = intel_link_bw_atomic_check(state, &new_limits);
6793 if (ret != -EAGAIN)
6794 break;
6795 }
6796
6797 return ret;
6798 }
6799 /**
6800 * intel_atomic_check - validate state object
6801 * @dev: drm device
6802 * @_state: state to validate
6803 */
intel_atomic_check(struct drm_device * dev,struct drm_atomic_state * _state)6804 int intel_atomic_check(struct drm_device *dev,
6805 struct drm_atomic_state *_state)
6806 {
6807 struct intel_display *display = to_intel_display(dev);
6808 struct drm_i915_private *dev_priv = to_i915(dev);
6809 struct intel_atomic_state *state = to_intel_atomic_state(_state);
6810 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
6811 struct intel_crtc *crtc;
6812 int ret, i;
6813 bool any_ms = false;
6814
6815 if (!intel_display_driver_check_access(display))
6816 return -ENODEV;
6817
6818 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6819 new_crtc_state, i) {
6820 /*
6821 * crtc's state no longer considered to be inherited
6822 * after the first userspace/client initiated commit.
6823 */
6824 if (!state->internal)
6825 new_crtc_state->inherited = false;
6826
6827 if (new_crtc_state->inherited != old_crtc_state->inherited)
6828 new_crtc_state->uapi.mode_changed = true;
6829
6830 if (new_crtc_state->uapi.scaling_filter !=
6831 old_crtc_state->uapi.scaling_filter)
6832 new_crtc_state->uapi.mode_changed = true;
6833 }
6834
6835 intel_vrr_check_modeset(state);
6836
6837 ret = drm_atomic_helper_check_modeset(dev, &state->base);
6838 if (ret)
6839 goto fail;
6840
6841 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6842 ret = intel_async_flip_check_uapi(state, crtc);
6843 if (ret)
6844 return ret;
6845 }
6846
6847 ret = intel_atomic_check_config_and_link(state);
6848 if (ret)
6849 goto fail;
6850
6851 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6852 if (!intel_crtc_needs_modeset(new_crtc_state))
6853 continue;
6854
6855 if (intel_crtc_is_joiner_secondary(new_crtc_state)) {
6856 drm_WARN_ON(&dev_priv->drm, new_crtc_state->uapi.enable);
6857 continue;
6858 }
6859
6860 ret = intel_atomic_check_joiner(state, crtc);
6861 if (ret)
6862 goto fail;
6863 }
6864
6865 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6866 new_crtc_state, i) {
6867 if (!intel_crtc_needs_modeset(new_crtc_state))
6868 continue;
6869
6870 intel_joiner_adjust_pipe_src(new_crtc_state);
6871
6872 intel_crtc_check_fastset(old_crtc_state, new_crtc_state);
6873 }
6874
6875 /**
6876 * Check if fastset is allowed by external dependencies like other
6877 * pipes and transcoders.
6878 *
6879 * Right now it only forces a fullmodeset when the MST master
6880 * transcoder did not changed but the pipe of the master transcoder
6881 * needs a fullmodeset so all slaves also needs to do a fullmodeset or
6882 * in case of port synced crtcs, if one of the synced crtcs
6883 * needs a full modeset, all other synced crtcs should be
6884 * forced a full modeset.
6885 */
6886 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
6887 if (!new_crtc_state->hw.enable || intel_crtc_needs_modeset(new_crtc_state))
6888 continue;
6889
6890 if (intel_dp_mst_crtc_needs_modeset(state, crtc))
6891 intel_crtc_flag_modeset(new_crtc_state);
6892
6893 if (intel_dp_mst_is_slave_trans(new_crtc_state)) {
6894 enum transcoder master = new_crtc_state->mst_master_transcoder;
6895
6896 if (intel_cpu_transcoders_need_modeset(state, BIT(master)))
6897 intel_crtc_flag_modeset(new_crtc_state);
6898 }
6899
6900 if (is_trans_port_sync_mode(new_crtc_state)) {
6901 u8 trans = new_crtc_state->sync_mode_slaves_mask;
6902
6903 if (new_crtc_state->master_transcoder != INVALID_TRANSCODER)
6904 trans |= BIT(new_crtc_state->master_transcoder);
6905
6906 if (intel_cpu_transcoders_need_modeset(state, trans))
6907 intel_crtc_flag_modeset(new_crtc_state);
6908 }
6909
6910 if (new_crtc_state->joiner_pipes) {
6911 if (intel_pipes_need_modeset(state, new_crtc_state->joiner_pipes))
6912 intel_crtc_flag_modeset(new_crtc_state);
6913 }
6914 }
6915
6916 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6917 new_crtc_state, i) {
6918 if (!intel_crtc_needs_modeset(new_crtc_state))
6919 continue;
6920
6921 any_ms = true;
6922
6923 intel_release_shared_dplls(state, crtc);
6924 }
6925
6926 if (any_ms && !check_digital_port_conflicts(state)) {
6927 drm_dbg_kms(&dev_priv->drm,
6928 "rejecting conflicting digital port configuration\n");
6929 ret = -EINVAL;
6930 goto fail;
6931 }
6932
6933 ret = intel_atomic_check_planes(state);
6934 if (ret)
6935 goto fail;
6936
6937 ret = intel_compute_global_watermarks(state);
6938 if (ret)
6939 goto fail;
6940
6941 ret = intel_bw_atomic_check(state);
6942 if (ret)
6943 goto fail;
6944
6945 ret = intel_cdclk_atomic_check(state, &any_ms);
6946 if (ret)
6947 goto fail;
6948
6949 if (intel_any_crtc_needs_modeset(state))
6950 any_ms = true;
6951
6952 if (any_ms) {
6953 ret = intel_modeset_checks(state);
6954 if (ret)
6955 goto fail;
6956
6957 ret = intel_modeset_calc_cdclk(state);
6958 if (ret)
6959 return ret;
6960 }
6961
6962 ret = intel_pmdemand_atomic_check(state);
6963 if (ret)
6964 goto fail;
6965
6966 ret = intel_atomic_check_crtcs(state);
6967 if (ret)
6968 goto fail;
6969
6970 ret = intel_fbc_atomic_check(state);
6971 if (ret)
6972 goto fail;
6973
6974 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
6975 new_crtc_state, i) {
6976 intel_color_assert_luts(new_crtc_state);
6977
6978 ret = intel_async_flip_check_hw(state, crtc);
6979 if (ret)
6980 goto fail;
6981
6982 /* Either full modeset or fastset (or neither), never both */
6983 drm_WARN_ON(&dev_priv->drm,
6984 intel_crtc_needs_modeset(new_crtc_state) &&
6985 intel_crtc_needs_fastset(new_crtc_state));
6986
6987 if (!intel_crtc_needs_modeset(new_crtc_state) &&
6988 !intel_crtc_needs_fastset(new_crtc_state))
6989 continue;
6990
6991 intel_crtc_state_dump(new_crtc_state, state,
6992 intel_crtc_needs_modeset(new_crtc_state) ?
6993 "modeset" : "fastset");
6994 }
6995
6996 return 0;
6997
6998 fail:
6999 if (ret == -EDEADLK)
7000 return ret;
7001
7002 /*
7003 * FIXME would probably be nice to know which crtc specifically
7004 * caused the failure, in cases where we can pinpoint it.
7005 */
7006 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7007 new_crtc_state, i)
7008 intel_crtc_state_dump(new_crtc_state, state, "failed");
7009
7010 return ret;
7011 }
7012
intel_atomic_prepare_commit(struct intel_atomic_state * state)7013 static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
7014 {
7015 int ret;
7016
7017 ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
7018 if (ret < 0)
7019 return ret;
7020
7021 return 0;
7022 }
7023
intel_crtc_arm_fifo_underrun(struct intel_crtc * crtc,struct intel_crtc_state * crtc_state)7024 void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
7025 struct intel_crtc_state *crtc_state)
7026 {
7027 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7028
7029 if (DISPLAY_VER(dev_priv) != 2 || crtc_state->active_planes)
7030 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7031
7032 if (crtc_state->has_pch_encoder) {
7033 enum pipe pch_transcoder =
7034 intel_crtc_pch_transcoder(crtc);
7035
7036 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
7037 }
7038 }
7039
intel_pipe_fastset(const struct intel_crtc_state * old_crtc_state,const struct intel_crtc_state * new_crtc_state)7040 static void intel_pipe_fastset(const struct intel_crtc_state *old_crtc_state,
7041 const struct intel_crtc_state *new_crtc_state)
7042 {
7043 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->uapi.crtc);
7044 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7045
7046 /*
7047 * Update pipe size and adjust fitter if needed: the reason for this is
7048 * that in compute_mode_changes we check the native mode (not the pfit
7049 * mode) to see if we can flip rather than do a full mode set. In the
7050 * fastboot case, we'll flip, but if we don't update the pipesrc and
7051 * pfit state, we'll end up with a big fb scanned out into the wrong
7052 * sized surface.
7053 */
7054 intel_set_pipe_src_size(new_crtc_state);
7055
7056 /* on skylake this is done by detaching scalers */
7057 if (DISPLAY_VER(dev_priv) >= 9) {
7058 if (new_crtc_state->pch_pfit.enabled)
7059 skl_pfit_enable(new_crtc_state);
7060 } else if (HAS_PCH_SPLIT(dev_priv)) {
7061 if (new_crtc_state->pch_pfit.enabled)
7062 ilk_pfit_enable(new_crtc_state);
7063 else if (old_crtc_state->pch_pfit.enabled)
7064 ilk_pfit_disable(old_crtc_state);
7065 }
7066
7067 /*
7068 * The register is supposedly single buffered so perhaps
7069 * not 100% correct to do this here. But SKL+ calculate
7070 * this based on the adjust pixel rate so pfit changes do
7071 * affect it and so it must be updated for fastsets.
7072 * HSW/BDW only really need this here for fastboot, after
7073 * that the value should not change without a full modeset.
7074 */
7075 if (DISPLAY_VER(dev_priv) >= 9 ||
7076 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
7077 hsw_set_linetime_wm(new_crtc_state);
7078
7079 if (new_crtc_state->update_m_n)
7080 intel_cpu_transcoder_set_m1_n1(crtc, new_crtc_state->cpu_transcoder,
7081 &new_crtc_state->dp_m_n);
7082
7083 if (new_crtc_state->update_lrr)
7084 intel_set_transcoder_timings_lrr(new_crtc_state);
7085 }
7086
commit_pipe_pre_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)7087 static void commit_pipe_pre_planes(struct intel_atomic_state *state,
7088 struct intel_crtc *crtc)
7089 {
7090 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7091 const struct intel_crtc_state *old_crtc_state =
7092 intel_atomic_get_old_crtc_state(state, crtc);
7093 const struct intel_crtc_state *new_crtc_state =
7094 intel_atomic_get_new_crtc_state(state, crtc);
7095 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7096
7097 /*
7098 * During modesets pipe configuration was programmed as the
7099 * CRTC was enabled.
7100 */
7101 if (!modeset && !new_crtc_state->use_dsb) {
7102 if (intel_crtc_needs_color_update(new_crtc_state))
7103 intel_color_commit_arm(NULL, new_crtc_state);
7104
7105 if (DISPLAY_VER(dev_priv) >= 9 || IS_BROADWELL(dev_priv))
7106 bdw_set_pipe_misc(NULL, new_crtc_state);
7107
7108 if (intel_crtc_needs_fastset(new_crtc_state))
7109 intel_pipe_fastset(old_crtc_state, new_crtc_state);
7110 }
7111
7112 intel_psr2_program_trans_man_trk_ctl(new_crtc_state);
7113
7114 intel_atomic_update_watermarks(state, crtc);
7115 }
7116
commit_pipe_post_planes(struct intel_atomic_state * state,struct intel_crtc * crtc)7117 static void commit_pipe_post_planes(struct intel_atomic_state *state,
7118 struct intel_crtc *crtc)
7119 {
7120 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7121 const struct intel_crtc_state *new_crtc_state =
7122 intel_atomic_get_new_crtc_state(state, crtc);
7123
7124 /*
7125 * Disable the scaler(s) after the plane(s) so that we don't
7126 * get a catastrophic underrun even if the two operations
7127 * end up happening in two different frames.
7128 */
7129 if (DISPLAY_VER(dev_priv) >= 9 &&
7130 !intel_crtc_needs_modeset(new_crtc_state))
7131 skl_detach_scalers(new_crtc_state);
7132
7133 if (intel_crtc_vrr_enabling(state, crtc))
7134 intel_vrr_enable(new_crtc_state);
7135 }
7136
intel_enable_crtc(struct intel_atomic_state * state,struct intel_crtc * crtc)7137 static void intel_enable_crtc(struct intel_atomic_state *state,
7138 struct intel_crtc *crtc)
7139 {
7140 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7141 const struct intel_crtc_state *new_crtc_state =
7142 intel_atomic_get_new_crtc_state(state, crtc);
7143 struct intel_crtc *pipe_crtc;
7144
7145 if (!intel_crtc_needs_modeset(new_crtc_state))
7146 return;
7147
7148 for_each_intel_crtc_in_pipe_mask_reverse(&dev_priv->drm, pipe_crtc,
7149 intel_crtc_joined_pipe_mask(new_crtc_state)) {
7150 const struct intel_crtc_state *pipe_crtc_state =
7151 intel_atomic_get_new_crtc_state(state, pipe_crtc);
7152
7153 /* VRR will be enable later, if required */
7154 intel_crtc_update_active_timings(pipe_crtc_state, false);
7155 }
7156
7157 dev_priv->display.funcs.display->crtc_enable(state, crtc);
7158
7159 /* vblanks work again, re-enable pipe CRC. */
7160 intel_crtc_enable_pipe_crc(crtc);
7161 }
7162
intel_pre_update_crtc(struct intel_atomic_state * state,struct intel_crtc * crtc)7163 static void intel_pre_update_crtc(struct intel_atomic_state *state,
7164 struct intel_crtc *crtc)
7165 {
7166 struct drm_i915_private *i915 = to_i915(state->base.dev);
7167 const struct intel_crtc_state *old_crtc_state =
7168 intel_atomic_get_old_crtc_state(state, crtc);
7169 struct intel_crtc_state *new_crtc_state =
7170 intel_atomic_get_new_crtc_state(state, crtc);
7171 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7172
7173 if (old_crtc_state->inherited ||
7174 intel_crtc_needs_modeset(new_crtc_state)) {
7175 if (HAS_DPT(i915))
7176 intel_dpt_configure(crtc);
7177 }
7178
7179 if (!modeset) {
7180 if (new_crtc_state->preload_luts &&
7181 intel_crtc_needs_color_update(new_crtc_state))
7182 intel_color_load_luts(new_crtc_state);
7183
7184 intel_pre_plane_update(state, crtc);
7185
7186 if (intel_crtc_needs_fastset(new_crtc_state))
7187 intel_encoders_update_pipe(state, crtc);
7188
7189 if (DISPLAY_VER(i915) >= 11 &&
7190 intel_crtc_needs_fastset(new_crtc_state))
7191 icl_set_pipe_chicken(new_crtc_state);
7192
7193 if (vrr_params_changed(old_crtc_state, new_crtc_state) ||
7194 cmrr_params_changed(old_crtc_state, new_crtc_state))
7195 intel_vrr_set_transcoder_timings(new_crtc_state);
7196 }
7197
7198 intel_fbc_update(state, crtc);
7199
7200 drm_WARN_ON(&i915->drm, !intel_display_power_is_enabled(i915, POWER_DOMAIN_DC_OFF));
7201
7202 if (!modeset &&
7203 intel_crtc_needs_color_update(new_crtc_state) &&
7204 !new_crtc_state->use_dsb)
7205 intel_color_commit_noarm(NULL, new_crtc_state);
7206
7207 if (!new_crtc_state->use_dsb)
7208 intel_crtc_planes_update_noarm(NULL, state, crtc);
7209 }
7210
intel_update_crtc(struct intel_atomic_state * state,struct intel_crtc * crtc)7211 static void intel_update_crtc(struct intel_atomic_state *state,
7212 struct intel_crtc *crtc)
7213 {
7214 const struct intel_crtc_state *old_crtc_state =
7215 intel_atomic_get_old_crtc_state(state, crtc);
7216 struct intel_crtc_state *new_crtc_state =
7217 intel_atomic_get_new_crtc_state(state, crtc);
7218
7219 if (new_crtc_state->use_dsb) {
7220 intel_crtc_prepare_vblank_event(new_crtc_state, &crtc->dsb_event);
7221
7222 intel_dsb_commit(new_crtc_state->dsb_commit, false);
7223 } else {
7224 /* Perform vblank evasion around commit operation */
7225 intel_pipe_update_start(state, crtc);
7226
7227 if (new_crtc_state->dsb_commit)
7228 intel_dsb_commit(new_crtc_state->dsb_commit, false);
7229
7230 commit_pipe_pre_planes(state, crtc);
7231
7232 intel_crtc_planes_update_arm(NULL, state, crtc);
7233
7234 commit_pipe_post_planes(state, crtc);
7235
7236 intel_pipe_update_end(state, crtc);
7237 }
7238
7239 /*
7240 * VRR/Seamless M/N update may need to update frame timings.
7241 *
7242 * FIXME Should be synchronized with the start of vblank somehow...
7243 */
7244 if (intel_crtc_vrr_enabling(state, crtc) ||
7245 new_crtc_state->update_m_n || new_crtc_state->update_lrr)
7246 intel_crtc_update_active_timings(new_crtc_state,
7247 new_crtc_state->vrr.enable);
7248
7249 /*
7250 * We usually enable FIFO underrun interrupts as part of the
7251 * CRTC enable sequence during modesets. But when we inherit a
7252 * valid pipe configuration from the BIOS we need to take care
7253 * of enabling them on the CRTC's first fastset.
7254 */
7255 if (intel_crtc_needs_fastset(new_crtc_state) &&
7256 old_crtc_state->inherited)
7257 intel_crtc_arm_fifo_underrun(crtc, new_crtc_state);
7258 }
7259
intel_old_crtc_state_disables(struct intel_atomic_state * state,struct intel_crtc * crtc)7260 static void intel_old_crtc_state_disables(struct intel_atomic_state *state,
7261 struct intel_crtc *crtc)
7262 {
7263 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7264 const struct intel_crtc_state *old_crtc_state =
7265 intel_atomic_get_old_crtc_state(state, crtc);
7266 struct intel_crtc *pipe_crtc;
7267
7268 /*
7269 * We need to disable pipe CRC before disabling the pipe,
7270 * or we race against vblank off.
7271 */
7272 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, pipe_crtc,
7273 intel_crtc_joined_pipe_mask(old_crtc_state))
7274 intel_crtc_disable_pipe_crc(pipe_crtc);
7275
7276 dev_priv->display.funcs.display->crtc_disable(state, crtc);
7277
7278 for_each_intel_crtc_in_pipe_mask(&dev_priv->drm, pipe_crtc,
7279 intel_crtc_joined_pipe_mask(old_crtc_state)) {
7280 const struct intel_crtc_state *new_pipe_crtc_state =
7281 intel_atomic_get_new_crtc_state(state, pipe_crtc);
7282
7283 pipe_crtc->active = false;
7284 intel_fbc_disable(pipe_crtc);
7285
7286 if (!new_pipe_crtc_state->hw.active)
7287 intel_initial_watermarks(state, pipe_crtc);
7288 }
7289 }
7290
intel_commit_modeset_disables(struct intel_atomic_state * state)7291 static void intel_commit_modeset_disables(struct intel_atomic_state *state)
7292 {
7293 struct drm_i915_private *i915 = to_i915(state->base.dev);
7294 const struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7295 struct intel_crtc *crtc;
7296 u8 disable_pipes = 0;
7297 int i;
7298
7299 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7300 new_crtc_state, i) {
7301 if (!intel_crtc_needs_modeset(new_crtc_state))
7302 continue;
7303
7304 /*
7305 * Needs to be done even for pipes
7306 * that weren't enabled previously.
7307 */
7308 intel_pre_plane_update(state, crtc);
7309
7310 if (!old_crtc_state->hw.active)
7311 continue;
7312
7313 disable_pipes |= BIT(crtc->pipe);
7314 }
7315
7316 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) {
7317 if ((disable_pipes & BIT(crtc->pipe)) == 0)
7318 continue;
7319
7320 intel_crtc_disable_planes(state, crtc);
7321
7322 drm_vblank_work_flush_all(&crtc->base);
7323 }
7324
7325 /* Only disable port sync and MST slaves */
7326 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) {
7327 if ((disable_pipes & BIT(crtc->pipe)) == 0)
7328 continue;
7329
7330 if (intel_crtc_is_joiner_secondary(old_crtc_state))
7331 continue;
7332
7333 /* In case of Transcoder port Sync master slave CRTCs can be
7334 * assigned in any order and we need to make sure that
7335 * slave CRTCs are disabled first and then master CRTC since
7336 * Slave vblanks are masked till Master Vblanks.
7337 */
7338 if (!is_trans_port_sync_slave(old_crtc_state) &&
7339 !intel_dp_mst_is_slave_trans(old_crtc_state))
7340 continue;
7341
7342 intel_old_crtc_state_disables(state, crtc);
7343
7344 disable_pipes &= ~intel_crtc_joined_pipe_mask(old_crtc_state);
7345 }
7346
7347 /* Disable everything else left on */
7348 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i) {
7349 if ((disable_pipes & BIT(crtc->pipe)) == 0)
7350 continue;
7351
7352 if (intel_crtc_is_joiner_secondary(old_crtc_state))
7353 continue;
7354
7355 intel_old_crtc_state_disables(state, crtc);
7356
7357 disable_pipes &= ~intel_crtc_joined_pipe_mask(old_crtc_state);
7358 }
7359
7360 drm_WARN_ON(&i915->drm, disable_pipes);
7361 }
7362
intel_commit_modeset_enables(struct intel_atomic_state * state)7363 static void intel_commit_modeset_enables(struct intel_atomic_state *state)
7364 {
7365 struct intel_crtc_state *new_crtc_state;
7366 struct intel_crtc *crtc;
7367 int i;
7368
7369 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7370 if (!new_crtc_state->hw.active)
7371 continue;
7372
7373 intel_enable_crtc(state, crtc);
7374 intel_pre_update_crtc(state, crtc);
7375 }
7376
7377 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7378 if (!new_crtc_state->hw.active)
7379 continue;
7380
7381 intel_update_crtc(state, crtc);
7382 }
7383 }
7384
skl_commit_modeset_enables(struct intel_atomic_state * state)7385 static void skl_commit_modeset_enables(struct intel_atomic_state *state)
7386 {
7387 struct drm_i915_private *dev_priv = to_i915(state->base.dev);
7388 struct intel_crtc *crtc;
7389 struct intel_crtc_state *old_crtc_state, *new_crtc_state;
7390 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
7391 u8 update_pipes = 0, modeset_pipes = 0;
7392 int i;
7393
7394 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7395 enum pipe pipe = crtc->pipe;
7396
7397 if (!new_crtc_state->hw.active)
7398 continue;
7399
7400 /* ignore allocations for crtc's that have been turned off. */
7401 if (!intel_crtc_needs_modeset(new_crtc_state)) {
7402 entries[pipe] = old_crtc_state->wm.skl.ddb;
7403 update_pipes |= BIT(pipe);
7404 } else {
7405 modeset_pipes |= BIT(pipe);
7406 }
7407 }
7408
7409 /*
7410 * Whenever the number of active pipes changes, we need to make sure we
7411 * update the pipes in the right order so that their ddb allocations
7412 * never overlap with each other between CRTC updates. Otherwise we'll
7413 * cause pipe underruns and other bad stuff.
7414 *
7415 * So first lets enable all pipes that do not need a fullmodeset as
7416 * those don't have any external dependency.
7417 */
7418 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7419 enum pipe pipe = crtc->pipe;
7420
7421 if ((update_pipes & BIT(pipe)) == 0)
7422 continue;
7423
7424 intel_pre_update_crtc(state, crtc);
7425 }
7426
7427 intel_dbuf_mbus_pre_ddb_update(state);
7428
7429 while (update_pipes) {
7430 /*
7431 * Commit in reverse order to make joiner primary
7432 * send the uapi events after secondaries are done.
7433 */
7434 for_each_oldnew_intel_crtc_in_state_reverse(state, crtc, old_crtc_state,
7435 new_crtc_state, i) {
7436 enum pipe pipe = crtc->pipe;
7437
7438 if ((update_pipes & BIT(pipe)) == 0)
7439 continue;
7440
7441 if (skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
7442 entries, I915_MAX_PIPES, pipe))
7443 continue;
7444
7445 entries[pipe] = new_crtc_state->wm.skl.ddb;
7446 update_pipes &= ~BIT(pipe);
7447
7448 intel_update_crtc(state, crtc);
7449
7450 /*
7451 * If this is an already active pipe, it's DDB changed,
7452 * and this isn't the last pipe that needs updating
7453 * then we need to wait for a vblank to pass for the
7454 * new ddb allocation to take effect.
7455 */
7456 if (!skl_ddb_entry_equal(&new_crtc_state->wm.skl.ddb,
7457 &old_crtc_state->wm.skl.ddb) &&
7458 (update_pipes | modeset_pipes))
7459 intel_crtc_wait_for_next_vblank(crtc);
7460 }
7461 }
7462
7463 intel_dbuf_mbus_post_ddb_update(state);
7464
7465 update_pipes = modeset_pipes;
7466
7467 /*
7468 * Enable all pipes that needs a modeset and do not depends on other
7469 * pipes
7470 */
7471 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7472 enum pipe pipe = crtc->pipe;
7473
7474 if ((modeset_pipes & BIT(pipe)) == 0)
7475 continue;
7476
7477 if (intel_crtc_is_joiner_secondary(new_crtc_state))
7478 continue;
7479
7480 if (intel_dp_mst_is_slave_trans(new_crtc_state) ||
7481 is_trans_port_sync_master(new_crtc_state))
7482 continue;
7483
7484 modeset_pipes &= ~intel_crtc_joined_pipe_mask(new_crtc_state);
7485
7486 intel_enable_crtc(state, crtc);
7487 }
7488
7489 /*
7490 * Then we enable all remaining pipes that depend on other
7491 * pipes: MST slaves and port sync masters
7492 */
7493 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7494 enum pipe pipe = crtc->pipe;
7495
7496 if ((modeset_pipes & BIT(pipe)) == 0)
7497 continue;
7498
7499 if (intel_crtc_is_joiner_secondary(new_crtc_state))
7500 continue;
7501
7502 modeset_pipes &= ~intel_crtc_joined_pipe_mask(new_crtc_state);
7503
7504 intel_enable_crtc(state, crtc);
7505 }
7506
7507 /*
7508 * Finally we do the plane updates/etc. for all pipes that got enabled.
7509 */
7510 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7511 enum pipe pipe = crtc->pipe;
7512
7513 if ((update_pipes & BIT(pipe)) == 0)
7514 continue;
7515
7516 intel_pre_update_crtc(state, crtc);
7517 }
7518
7519 /*
7520 * Commit in reverse order to make joiner primary
7521 * send the uapi events after secondaries are done.
7522 */
7523 for_each_new_intel_crtc_in_state_reverse(state, crtc, new_crtc_state, i) {
7524 enum pipe pipe = crtc->pipe;
7525
7526 if ((update_pipes & BIT(pipe)) == 0)
7527 continue;
7528
7529 drm_WARN_ON(&dev_priv->drm, skl_ddb_allocation_overlaps(&new_crtc_state->wm.skl.ddb,
7530 entries, I915_MAX_PIPES, pipe));
7531
7532 entries[pipe] = new_crtc_state->wm.skl.ddb;
7533 update_pipes &= ~BIT(pipe);
7534
7535 intel_update_crtc(state, crtc);
7536 }
7537
7538 drm_WARN_ON(&dev_priv->drm, modeset_pipes);
7539 drm_WARN_ON(&dev_priv->drm, update_pipes);
7540 }
7541
intel_atomic_commit_fence_wait(struct intel_atomic_state * intel_state)7542 static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
7543 {
7544 struct drm_i915_private *i915 = to_i915(intel_state->base.dev);
7545 struct drm_plane *plane;
7546 struct drm_plane_state *new_plane_state;
7547 int ret, i;
7548
7549 for_each_new_plane_in_state(&intel_state->base, plane, new_plane_state, i) {
7550 if (new_plane_state->fence) {
7551 ret = dma_fence_wait_timeout(new_plane_state->fence, false,
7552 i915_fence_timeout(i915));
7553 if (ret <= 0)
7554 break;
7555
7556 dma_fence_put(new_plane_state->fence);
7557 new_plane_state->fence = NULL;
7558 }
7559 }
7560 }
7561
intel_atomic_dsb_wait_commit(struct intel_crtc_state * crtc_state)7562 static void intel_atomic_dsb_wait_commit(struct intel_crtc_state *crtc_state)
7563 {
7564 if (crtc_state->dsb_commit)
7565 intel_dsb_wait(crtc_state->dsb_commit);
7566
7567 intel_color_wait_commit(crtc_state);
7568 }
7569
intel_atomic_dsb_cleanup(struct intel_crtc_state * crtc_state)7570 static void intel_atomic_dsb_cleanup(struct intel_crtc_state *crtc_state)
7571 {
7572 if (crtc_state->dsb_commit) {
7573 intel_dsb_cleanup(crtc_state->dsb_commit);
7574 crtc_state->dsb_commit = NULL;
7575 }
7576
7577 intel_color_cleanup_commit(crtc_state);
7578 }
7579
intel_atomic_cleanup_work(struct work_struct * work)7580 static void intel_atomic_cleanup_work(struct work_struct *work)
7581 {
7582 struct intel_atomic_state *state =
7583 container_of(work, struct intel_atomic_state, cleanup_work);
7584 struct drm_i915_private *i915 = to_i915(state->base.dev);
7585 struct intel_crtc_state *old_crtc_state;
7586 struct intel_crtc *crtc;
7587 int i;
7588
7589 for_each_old_intel_crtc_in_state(state, crtc, old_crtc_state, i)
7590 intel_atomic_dsb_cleanup(old_crtc_state);
7591
7592 drm_atomic_helper_cleanup_planes(&i915->drm, &state->base);
7593 drm_atomic_helper_commit_cleanup_done(&state->base);
7594 drm_atomic_state_put(&state->base);
7595 }
7596
intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state * state)7597 static void intel_atomic_prepare_plane_clear_colors(struct intel_atomic_state *state)
7598 {
7599 struct drm_i915_private *i915 = to_i915(state->base.dev);
7600 struct intel_plane *plane;
7601 struct intel_plane_state *plane_state;
7602 int i;
7603
7604 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
7605 struct drm_framebuffer *fb = plane_state->hw.fb;
7606 int cc_plane;
7607 int ret;
7608
7609 if (!fb)
7610 continue;
7611
7612 cc_plane = intel_fb_rc_ccs_cc_plane(fb);
7613 if (cc_plane < 0)
7614 continue;
7615
7616 /*
7617 * The layout of the fast clear color value expected by HW
7618 * (the DRM ABI requiring this value to be located in fb at
7619 * offset 0 of cc plane, plane #2 previous generations or
7620 * plane #1 for flat ccs):
7621 * - 4 x 4 bytes per-channel value
7622 * (in surface type specific float/int format provided by the fb user)
7623 * - 8 bytes native color value used by the display
7624 * (converted/written by GPU during a fast clear operation using the
7625 * above per-channel values)
7626 *
7627 * The commit's FB prepare hook already ensured that FB obj is pinned and the
7628 * caller made sure that the object is synced wrt. the related color clear value
7629 * GPU write on it.
7630 */
7631 ret = intel_bo_read_from_page(intel_fb_bo(fb),
7632 fb->offsets[cc_plane] + 16,
7633 &plane_state->ccval,
7634 sizeof(plane_state->ccval));
7635 /* The above could only fail if the FB obj has an unexpected backing store type. */
7636 drm_WARN_ON(&i915->drm, ret);
7637 }
7638 }
7639
intel_atomic_dsb_prepare(struct intel_atomic_state * state,struct intel_crtc * crtc)7640 static void intel_atomic_dsb_prepare(struct intel_atomic_state *state,
7641 struct intel_crtc *crtc)
7642 {
7643 intel_color_prepare_commit(state, crtc);
7644 }
7645
intel_atomic_dsb_finish(struct intel_atomic_state * state,struct intel_crtc * crtc)7646 static void intel_atomic_dsb_finish(struct intel_atomic_state *state,
7647 struct intel_crtc *crtc)
7648 {
7649 const struct intel_crtc_state *old_crtc_state =
7650 intel_atomic_get_old_crtc_state(state, crtc);
7651 struct intel_crtc_state *new_crtc_state =
7652 intel_atomic_get_new_crtc_state(state, crtc);
7653
7654 if (!new_crtc_state->hw.active)
7655 return;
7656
7657 if (state->base.legacy_cursor_update)
7658 return;
7659
7660 /* FIXME deal with everything */
7661 new_crtc_state->use_dsb =
7662 new_crtc_state->update_planes &&
7663 !new_crtc_state->vrr.enable &&
7664 !new_crtc_state->do_async_flip &&
7665 !new_crtc_state->has_psr &&
7666 !new_crtc_state->scaler_state.scaler_users &&
7667 !old_crtc_state->scaler_state.scaler_users &&
7668 !intel_crtc_needs_modeset(new_crtc_state) &&
7669 !intel_crtc_needs_fastset(new_crtc_state);
7670
7671 if (!new_crtc_state->use_dsb && !new_crtc_state->dsb_color_vblank)
7672 return;
7673
7674 /*
7675 * Rough estimate:
7676 * ~64 registers per each plane * 8 planes = 512
7677 * Double that for pipe stuff and other overhead.
7678 */
7679 new_crtc_state->dsb_commit = intel_dsb_prepare(state, crtc, INTEL_DSB_0,
7680 new_crtc_state->use_dsb ? 1024 : 16);
7681 if (!new_crtc_state->dsb_commit) {
7682 new_crtc_state->use_dsb = false;
7683 intel_color_cleanup_commit(new_crtc_state);
7684 return;
7685 }
7686
7687 if (new_crtc_state->use_dsb) {
7688 if (intel_crtc_needs_color_update(new_crtc_state))
7689 intel_color_commit_noarm(new_crtc_state->dsb_commit,
7690 new_crtc_state);
7691 intel_crtc_planes_update_noarm(new_crtc_state->dsb_commit,
7692 state, crtc);
7693
7694 intel_dsb_vblank_evade(state, new_crtc_state->dsb_commit);
7695
7696 if (intel_crtc_needs_color_update(new_crtc_state))
7697 intel_color_commit_arm(new_crtc_state->dsb_commit,
7698 new_crtc_state);
7699 bdw_set_pipe_misc(new_crtc_state->dsb_commit,
7700 new_crtc_state);
7701 intel_crtc_planes_update_arm(new_crtc_state->dsb_commit,
7702 state, crtc);
7703
7704 if (!new_crtc_state->dsb_color_vblank) {
7705 intel_dsb_wait_vblanks(new_crtc_state->dsb_commit, 1);
7706 intel_dsb_wait_vblank_delay(state, new_crtc_state->dsb_commit);
7707 intel_dsb_interrupt(new_crtc_state->dsb_commit);
7708 }
7709 }
7710
7711 if (new_crtc_state->dsb_color_vblank)
7712 intel_dsb_chain(state, new_crtc_state->dsb_commit,
7713 new_crtc_state->dsb_color_vblank, true);
7714
7715 intel_dsb_finish(new_crtc_state->dsb_commit);
7716 }
7717
intel_atomic_commit_tail(struct intel_atomic_state * state)7718 static void intel_atomic_commit_tail(struct intel_atomic_state *state)
7719 {
7720 struct drm_device *dev = state->base.dev;
7721 struct drm_i915_private *dev_priv = to_i915(dev);
7722 struct intel_crtc_state *new_crtc_state, *old_crtc_state;
7723 struct intel_crtc *crtc;
7724 struct intel_power_domain_mask put_domains[I915_MAX_PIPES] = {};
7725 intel_wakeref_t wakeref = NULL;
7726 int i;
7727
7728 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7729 intel_atomic_dsb_prepare(state, crtc);
7730
7731 intel_atomic_commit_fence_wait(state);
7732
7733 intel_td_flush(dev_priv);
7734
7735 intel_atomic_prepare_plane_clear_colors(state);
7736
7737 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7738 intel_atomic_dsb_finish(state, crtc);
7739
7740 drm_atomic_helper_wait_for_dependencies(&state->base);
7741 drm_dp_mst_atomic_wait_for_dependencies(&state->base);
7742 intel_atomic_global_state_wait_for_dependencies(state);
7743
7744 /*
7745 * During full modesets we write a lot of registers, wait
7746 * for PLLs, etc. Doing that while DC states are enabled
7747 * is not a good idea.
7748 *
7749 * During fastsets and other updates we also need to
7750 * disable DC states due to the following scenario:
7751 * 1. DC5 exit and PSR exit happen
7752 * 2. Some or all _noarm() registers are written
7753 * 3. Due to some long delay PSR is re-entered
7754 * 4. DC5 entry -> DMC saves the already written new
7755 * _noarm() registers and the old not yet written
7756 * _arm() registers
7757 * 5. DC5 exit -> DMC restores a mixture of old and
7758 * new register values and arms the update
7759 * 6. PSR exit -> hardware latches a mixture of old and
7760 * new register values -> corrupted frame, or worse
7761 * 7. New _arm() registers are finally written
7762 * 8. Hardware finally latches a complete set of new
7763 * register values, and subsequent frames will be OK again
7764 *
7765 * Also note that due to the pipe CSC hardware issues on
7766 * SKL/GLK DC states must remain off until the pipe CSC
7767 * state readout has happened. Otherwise we risk corrupting
7768 * the CSC latched register values with the readout (see
7769 * skl_read_csc() and skl_color_commit_noarm()).
7770 */
7771 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_DC_OFF);
7772
7773 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7774 new_crtc_state, i) {
7775 if (intel_crtc_needs_modeset(new_crtc_state) ||
7776 intel_crtc_needs_fastset(new_crtc_state))
7777 intel_modeset_get_crtc_power_domains(new_crtc_state, &put_domains[crtc->pipe]);
7778 }
7779
7780 intel_commit_modeset_disables(state);
7781
7782 intel_dp_tunnel_atomic_alloc_bw(state);
7783
7784 /* FIXME: Eventually get rid of our crtc->config pointer */
7785 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
7786 crtc->config = new_crtc_state;
7787
7788 /*
7789 * In XE_LPD+ Pmdemand combines many parameters such as voltage index,
7790 * plls, cdclk frequency, QGV point selection parameter etc. Voltage
7791 * index, cdclk/ddiclk frequencies are supposed to be configured before
7792 * the cdclk config is set.
7793 */
7794 intel_pmdemand_pre_plane_update(state);
7795
7796 if (state->modeset) {
7797 drm_atomic_helper_update_legacy_modeset_state(dev, &state->base);
7798
7799 intel_set_cdclk_pre_plane_update(state);
7800
7801 intel_modeset_verify_disabled(state);
7802 }
7803
7804 intel_sagv_pre_plane_update(state);
7805
7806 /* Complete the events for pipes that have now been disabled */
7807 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7808 bool modeset = intel_crtc_needs_modeset(new_crtc_state);
7809
7810 /* Complete events for now disable pipes here. */
7811 if (modeset && !new_crtc_state->hw.active && new_crtc_state->uapi.event) {
7812 spin_lock_irq(&dev->event_lock);
7813 drm_crtc_send_vblank_event(&crtc->base,
7814 new_crtc_state->uapi.event);
7815 spin_unlock_irq(&dev->event_lock);
7816
7817 new_crtc_state->uapi.event = NULL;
7818 }
7819 }
7820
7821 intel_encoders_update_prepare(state);
7822
7823 intel_dbuf_pre_plane_update(state);
7824
7825 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7826 if (new_crtc_state->do_async_flip)
7827 intel_crtc_enable_flip_done(state, crtc);
7828 }
7829
7830 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
7831 dev_priv->display.funcs.display->commit_modeset_enables(state);
7832
7833 intel_program_dpkgc_latency(state);
7834
7835 intel_wait_for_vblank_workers(state);
7836
7837 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
7838 * already, but still need the state for the delayed optimization. To
7839 * fix this:
7840 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
7841 * - schedule that vblank worker _before_ calling hw_done
7842 * - at the start of commit_tail, cancel it _synchrously
7843 * - switch over to the vblank wait helper in the core after that since
7844 * we don't need out special handling any more.
7845 */
7846 drm_atomic_helper_wait_for_flip_done(dev, &state->base);
7847
7848 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i) {
7849 if (new_crtc_state->do_async_flip)
7850 intel_crtc_disable_flip_done(state, crtc);
7851
7852 intel_atomic_dsb_wait_commit(new_crtc_state);
7853 }
7854
7855 /*
7856 * Now that the vblank has passed, we can go ahead and program the
7857 * optimal watermarks on platforms that need two-step watermark
7858 * programming.
7859 *
7860 * TODO: Move this (and other cleanup) to an async worker eventually.
7861 */
7862 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state,
7863 new_crtc_state, i) {
7864 /*
7865 * Gen2 reports pipe underruns whenever all planes are disabled.
7866 * So re-enable underrun reporting after some planes get enabled.
7867 *
7868 * We do this before .optimize_watermarks() so that we have a
7869 * chance of catching underruns with the intermediate watermarks
7870 * vs. the new plane configuration.
7871 */
7872 if (DISPLAY_VER(dev_priv) == 2 && planes_enabling(old_crtc_state, new_crtc_state))
7873 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
7874
7875 intel_optimize_watermarks(state, crtc);
7876 }
7877
7878 intel_dbuf_post_plane_update(state);
7879
7880 for_each_oldnew_intel_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
7881 intel_post_plane_update(state, crtc);
7882
7883 intel_modeset_put_crtc_power_domains(crtc, &put_domains[crtc->pipe]);
7884
7885 intel_modeset_verify_crtc(state, crtc);
7886
7887 intel_post_plane_update_after_readout(state, crtc);
7888
7889 /*
7890 * DSB cleanup is done in cleanup_work aligning with framebuffer
7891 * cleanup. So copy and reset the dsb structure to sync with
7892 * commit_done and later do dsb cleanup in cleanup_work.
7893 *
7894 * FIXME get rid of this funny new->old swapping
7895 */
7896 old_crtc_state->dsb_color_vblank = fetch_and_zero(&new_crtc_state->dsb_color_vblank);
7897 old_crtc_state->dsb_commit = fetch_and_zero(&new_crtc_state->dsb_commit);
7898 }
7899
7900 /* Underruns don't always raise interrupts, so check manually */
7901 intel_check_cpu_fifo_underruns(dev_priv);
7902 intel_check_pch_fifo_underruns(dev_priv);
7903
7904 if (state->modeset)
7905 intel_verify_planes(state);
7906
7907 intel_sagv_post_plane_update(state);
7908 if (state->modeset)
7909 intel_set_cdclk_post_plane_update(state);
7910 intel_pmdemand_post_plane_update(state);
7911
7912 drm_atomic_helper_commit_hw_done(&state->base);
7913 intel_atomic_global_state_commit_done(state);
7914
7915 if (state->modeset) {
7916 /* As one of the primary mmio accessors, KMS has a high
7917 * likelihood of triggering bugs in unclaimed access. After we
7918 * finish modesetting, see if an error has been flagged, and if
7919 * so enable debugging for the next modeset - and hope we catch
7920 * the culprit.
7921 */
7922 intel_uncore_arm_unclaimed_mmio_detection(&dev_priv->uncore);
7923 }
7924 /*
7925 * Delay re-enabling DC states by 17 ms to avoid the off->on->off
7926 * toggling overhead at and above 60 FPS.
7927 */
7928 intel_display_power_put_async_delay(dev_priv, POWER_DOMAIN_DC_OFF, wakeref, 17);
7929 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
7930
7931 /*
7932 * Defer the cleanup of the old state to a separate worker to not
7933 * impede the current task (userspace for blocking modesets) that
7934 * are executed inline. For out-of-line asynchronous modesets/flips,
7935 * deferring to a new worker seems overkill, but we would place a
7936 * schedule point (cond_resched()) here anyway to keep latencies
7937 * down.
7938 */
7939 INIT_WORK(&state->cleanup_work, intel_atomic_cleanup_work);
7940 queue_work(dev_priv->display.wq.cleanup, &state->cleanup_work);
7941 }
7942
intel_atomic_commit_work(struct work_struct * work)7943 static void intel_atomic_commit_work(struct work_struct *work)
7944 {
7945 struct intel_atomic_state *state =
7946 container_of(work, struct intel_atomic_state, base.commit_work);
7947
7948 intel_atomic_commit_tail(state);
7949 }
7950
intel_atomic_track_fbs(struct intel_atomic_state * state)7951 static void intel_atomic_track_fbs(struct intel_atomic_state *state)
7952 {
7953 struct intel_plane_state *old_plane_state, *new_plane_state;
7954 struct intel_plane *plane;
7955 int i;
7956
7957 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
7958 new_plane_state, i)
7959 intel_frontbuffer_track(to_intel_frontbuffer(old_plane_state->hw.fb),
7960 to_intel_frontbuffer(new_plane_state->hw.fb),
7961 plane->frontbuffer_bit);
7962 }
7963
intel_atomic_setup_commit(struct intel_atomic_state * state,bool nonblock)7964 static int intel_atomic_setup_commit(struct intel_atomic_state *state, bool nonblock)
7965 {
7966 int ret;
7967
7968 ret = drm_atomic_helper_setup_commit(&state->base, nonblock);
7969 if (ret)
7970 return ret;
7971
7972 ret = intel_atomic_global_state_setup_commit(state);
7973 if (ret)
7974 return ret;
7975
7976 return 0;
7977 }
7978
intel_atomic_swap_state(struct intel_atomic_state * state)7979 static int intel_atomic_swap_state(struct intel_atomic_state *state)
7980 {
7981 int ret;
7982
7983 ret = drm_atomic_helper_swap_state(&state->base, true);
7984 if (ret)
7985 return ret;
7986
7987 intel_atomic_swap_global_state(state);
7988
7989 intel_shared_dpll_swap_state(state);
7990
7991 intel_atomic_track_fbs(state);
7992
7993 return 0;
7994 }
7995
intel_atomic_commit(struct drm_device * dev,struct drm_atomic_state * _state,bool nonblock)7996 int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state,
7997 bool nonblock)
7998 {
7999 struct intel_atomic_state *state = to_intel_atomic_state(_state);
8000 struct drm_i915_private *dev_priv = to_i915(dev);
8001 int ret = 0;
8002
8003 state->wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
8004
8005 /*
8006 * The intel_legacy_cursor_update() fast path takes care
8007 * of avoiding the vblank waits for simple cursor
8008 * movement and flips. For cursor on/off and size changes,
8009 * we want to perform the vblank waits so that watermark
8010 * updates happen during the correct frames. Gen9+ have
8011 * double buffered watermarks and so shouldn't need this.
8012 *
8013 * Unset state->legacy_cursor_update before the call to
8014 * drm_atomic_helper_setup_commit() because otherwise
8015 * drm_atomic_helper_wait_for_flip_done() is a noop and
8016 * we get FIFO underruns because we didn't wait
8017 * for vblank.
8018 *
8019 * FIXME doing watermarks and fb cleanup from a vblank worker
8020 * (assuming we had any) would solve these problems.
8021 */
8022 if (DISPLAY_VER(dev_priv) < 9 && state->base.legacy_cursor_update) {
8023 struct intel_crtc_state *new_crtc_state;
8024 struct intel_crtc *crtc;
8025 int i;
8026
8027 for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
8028 if (new_crtc_state->wm.need_postvbl_update ||
8029 new_crtc_state->update_wm_post)
8030 state->base.legacy_cursor_update = false;
8031 }
8032
8033 ret = intel_atomic_prepare_commit(state);
8034 if (ret) {
8035 drm_dbg_atomic(&dev_priv->drm,
8036 "Preparing state failed with %i\n", ret);
8037 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
8038 return ret;
8039 }
8040
8041 ret = intel_atomic_setup_commit(state, nonblock);
8042 if (!ret)
8043 ret = intel_atomic_swap_state(state);
8044
8045 if (ret) {
8046 drm_atomic_helper_unprepare_planes(dev, &state->base);
8047 intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
8048 return ret;
8049 }
8050
8051 drm_atomic_state_get(&state->base);
8052 INIT_WORK(&state->base.commit_work, intel_atomic_commit_work);
8053
8054 if (nonblock && state->modeset) {
8055 queue_work(dev_priv->display.wq.modeset, &state->base.commit_work);
8056 } else if (nonblock) {
8057 queue_work(dev_priv->display.wq.flip, &state->base.commit_work);
8058 } else {
8059 if (state->modeset)
8060 flush_workqueue(dev_priv->display.wq.modeset);
8061 intel_atomic_commit_tail(state);
8062 }
8063
8064 return 0;
8065 }
8066
8067 /**
8068 * intel_plane_destroy - destroy a plane
8069 * @plane: plane to destroy
8070 *
8071 * Common destruction function for all types of planes (primary, cursor,
8072 * sprite).
8073 */
intel_plane_destroy(struct drm_plane * plane)8074 void intel_plane_destroy(struct drm_plane *plane)
8075 {
8076 drm_plane_cleanup(plane);
8077 kfree(to_intel_plane(plane));
8078 }
8079
intel_encoder_possible_clones(struct intel_encoder * encoder)8080 static u32 intel_encoder_possible_clones(struct intel_encoder *encoder)
8081 {
8082 struct drm_device *dev = encoder->base.dev;
8083 struct intel_encoder *source_encoder;
8084 u32 possible_clones = 0;
8085
8086 for_each_intel_encoder(dev, source_encoder) {
8087 if (encoders_cloneable(encoder, source_encoder))
8088 possible_clones |= drm_encoder_mask(&source_encoder->base);
8089 }
8090
8091 return possible_clones;
8092 }
8093
intel_encoder_possible_crtcs(struct intel_encoder * encoder)8094 static u32 intel_encoder_possible_crtcs(struct intel_encoder *encoder)
8095 {
8096 struct drm_device *dev = encoder->base.dev;
8097 struct intel_crtc *crtc;
8098 u32 possible_crtcs = 0;
8099
8100 for_each_intel_crtc_in_pipe_mask(dev, crtc, encoder->pipe_mask)
8101 possible_crtcs |= drm_crtc_mask(&crtc->base);
8102
8103 return possible_crtcs;
8104 }
8105
ilk_has_edp_a(struct drm_i915_private * dev_priv)8106 static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
8107 {
8108 if (!IS_MOBILE(dev_priv))
8109 return false;
8110
8111 if ((intel_de_read(dev_priv, DP_A) & DP_DETECTED) == 0)
8112 return false;
8113
8114 if (IS_IRONLAKE(dev_priv) && (intel_de_read(dev_priv, FUSE_STRAP) & ILK_eDP_A_DISABLE))
8115 return false;
8116
8117 return true;
8118 }
8119
intel_ddi_crt_present(struct drm_i915_private * dev_priv)8120 static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
8121 {
8122 if (DISPLAY_VER(dev_priv) >= 9)
8123 return false;
8124
8125 if (IS_HASWELL_ULT(dev_priv) || IS_BROADWELL_ULT(dev_priv))
8126 return false;
8127
8128 if (HAS_PCH_LPT_H(dev_priv) &&
8129 intel_de_read(dev_priv, SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
8130 return false;
8131
8132 /* DDI E can't be used if DDI A requires 4 lanes */
8133 if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
8134 return false;
8135
8136 if (!dev_priv->display.vbt.int_crt_support)
8137 return false;
8138
8139 return true;
8140 }
8141
assert_port_valid(struct drm_i915_private * i915,enum port port)8142 bool assert_port_valid(struct drm_i915_private *i915, enum port port)
8143 {
8144 return !drm_WARN(&i915->drm, !(DISPLAY_RUNTIME_INFO(i915)->port_mask & BIT(port)),
8145 "Platform does not support port %c\n", port_name(port));
8146 }
8147
intel_setup_outputs(struct drm_i915_private * dev_priv)8148 void intel_setup_outputs(struct drm_i915_private *dev_priv)
8149 {
8150 struct intel_display *display = &dev_priv->display;
8151 struct intel_encoder *encoder;
8152 bool dpd_is_edp = false;
8153
8154 intel_pps_unlock_regs_wa(display);
8155
8156 if (!HAS_DISPLAY(dev_priv))
8157 return;
8158
8159 if (HAS_DDI(dev_priv)) {
8160 if (intel_ddi_crt_present(dev_priv))
8161 intel_crt_init(display);
8162
8163 intel_bios_for_each_encoder(display, intel_ddi_init);
8164
8165 if (IS_GEMINILAKE(dev_priv) || IS_BROXTON(dev_priv))
8166 vlv_dsi_init(dev_priv);
8167 } else if (HAS_PCH_SPLIT(dev_priv)) {
8168 int found;
8169
8170 /*
8171 * intel_edp_init_connector() depends on this completing first,
8172 * to prevent the registration of both eDP and LVDS and the
8173 * incorrect sharing of the PPS.
8174 */
8175 intel_lvds_init(dev_priv);
8176 intel_crt_init(display);
8177
8178 dpd_is_edp = intel_dp_is_port_edp(display, PORT_D);
8179
8180 if (ilk_has_edp_a(dev_priv))
8181 g4x_dp_init(dev_priv, DP_A, PORT_A);
8182
8183 if (intel_de_read(dev_priv, PCH_HDMIB) & SDVO_DETECTED) {
8184 /* PCH SDVOB multiplex with HDMIB */
8185 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
8186 if (!found)
8187 g4x_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
8188 if (!found && (intel_de_read(dev_priv, PCH_DP_B) & DP_DETECTED))
8189 g4x_dp_init(dev_priv, PCH_DP_B, PORT_B);
8190 }
8191
8192 if (intel_de_read(dev_priv, PCH_HDMIC) & SDVO_DETECTED)
8193 g4x_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
8194
8195 if (!dpd_is_edp && intel_de_read(dev_priv, PCH_HDMID) & SDVO_DETECTED)
8196 g4x_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
8197
8198 if (intel_de_read(dev_priv, PCH_DP_C) & DP_DETECTED)
8199 g4x_dp_init(dev_priv, PCH_DP_C, PORT_C);
8200
8201 if (intel_de_read(dev_priv, PCH_DP_D) & DP_DETECTED)
8202 g4x_dp_init(dev_priv, PCH_DP_D, PORT_D);
8203 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
8204 bool has_edp, has_port;
8205
8206 if (IS_VALLEYVIEW(dev_priv) && dev_priv->display.vbt.int_crt_support)
8207 intel_crt_init(display);
8208
8209 /*
8210 * The DP_DETECTED bit is the latched state of the DDC
8211 * SDA pin at boot. However since eDP doesn't require DDC
8212 * (no way to plug in a DP->HDMI dongle) the DDC pins for
8213 * eDP ports may have been muxed to an alternate function.
8214 * Thus we can't rely on the DP_DETECTED bit alone to detect
8215 * eDP ports. Consult the VBT as well as DP_DETECTED to
8216 * detect eDP ports.
8217 *
8218 * Sadly the straps seem to be missing sometimes even for HDMI
8219 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
8220 * and VBT for the presence of the port. Additionally we can't
8221 * trust the port type the VBT declares as we've seen at least
8222 * HDMI ports that the VBT claim are DP or eDP.
8223 */
8224 has_edp = intel_dp_is_port_edp(display, PORT_B);
8225 has_port = intel_bios_is_port_present(display, PORT_B);
8226 if (intel_de_read(dev_priv, VLV_DP_B) & DP_DETECTED || has_port)
8227 has_edp &= g4x_dp_init(dev_priv, VLV_DP_B, PORT_B);
8228 if ((intel_de_read(dev_priv, VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
8229 g4x_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
8230
8231 has_edp = intel_dp_is_port_edp(display, PORT_C);
8232 has_port = intel_bios_is_port_present(display, PORT_C);
8233 if (intel_de_read(dev_priv, VLV_DP_C) & DP_DETECTED || has_port)
8234 has_edp &= g4x_dp_init(dev_priv, VLV_DP_C, PORT_C);
8235 if ((intel_de_read(dev_priv, VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
8236 g4x_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
8237
8238 if (IS_CHERRYVIEW(dev_priv)) {
8239 /*
8240 * eDP not supported on port D,
8241 * so no need to worry about it
8242 */
8243 has_port = intel_bios_is_port_present(display, PORT_D);
8244 if (intel_de_read(dev_priv, CHV_DP_D) & DP_DETECTED || has_port)
8245 g4x_dp_init(dev_priv, CHV_DP_D, PORT_D);
8246 if (intel_de_read(dev_priv, CHV_HDMID) & SDVO_DETECTED || has_port)
8247 g4x_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
8248 }
8249
8250 vlv_dsi_init(dev_priv);
8251 } else if (IS_PINEVIEW(dev_priv)) {
8252 intel_lvds_init(dev_priv);
8253 intel_crt_init(display);
8254 } else if (IS_DISPLAY_VER(dev_priv, 3, 4)) {
8255 bool found = false;
8256
8257 if (IS_MOBILE(dev_priv))
8258 intel_lvds_init(dev_priv);
8259
8260 intel_crt_init(display);
8261
8262 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
8263 drm_dbg_kms(&dev_priv->drm, "probing SDVOB\n");
8264 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
8265 if (!found && IS_G4X(dev_priv)) {
8266 drm_dbg_kms(&dev_priv->drm,
8267 "probing HDMI on SDVOB\n");
8268 g4x_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
8269 }
8270
8271 if (!found && IS_G4X(dev_priv))
8272 g4x_dp_init(dev_priv, DP_B, PORT_B);
8273 }
8274
8275 /* Before G4X SDVOC doesn't have its own detect register */
8276
8277 if (intel_de_read(dev_priv, GEN3_SDVOB) & SDVO_DETECTED) {
8278 drm_dbg_kms(&dev_priv->drm, "probing SDVOC\n");
8279 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
8280 }
8281
8282 if (!found && (intel_de_read(dev_priv, GEN3_SDVOC) & SDVO_DETECTED)) {
8283
8284 if (IS_G4X(dev_priv)) {
8285 drm_dbg_kms(&dev_priv->drm,
8286 "probing HDMI on SDVOC\n");
8287 g4x_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
8288 }
8289 if (IS_G4X(dev_priv))
8290 g4x_dp_init(dev_priv, DP_C, PORT_C);
8291 }
8292
8293 if (IS_G4X(dev_priv) && (intel_de_read(dev_priv, DP_D) & DP_DETECTED))
8294 g4x_dp_init(dev_priv, DP_D, PORT_D);
8295
8296 if (SUPPORTS_TV(dev_priv))
8297 intel_tv_init(display);
8298 } else if (DISPLAY_VER(dev_priv) == 2) {
8299 if (IS_I85X(dev_priv))
8300 intel_lvds_init(dev_priv);
8301
8302 intel_crt_init(display);
8303 intel_dvo_init(dev_priv);
8304 }
8305
8306 for_each_intel_encoder(&dev_priv->drm, encoder) {
8307 encoder->base.possible_crtcs =
8308 intel_encoder_possible_crtcs(encoder);
8309 encoder->base.possible_clones =
8310 intel_encoder_possible_clones(encoder);
8311 }
8312
8313 intel_init_pch_refclk(dev_priv);
8314
8315 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
8316 }
8317
max_dotclock(struct drm_i915_private * i915)8318 static int max_dotclock(struct drm_i915_private *i915)
8319 {
8320 struct intel_display *display = &i915->display;
8321 int max_dotclock = display->cdclk.max_dotclk_freq;
8322
8323 if (HAS_ULTRAJOINER(display))
8324 max_dotclock *= 4;
8325 else if (HAS_UNCOMPRESSED_JOINER(display) || HAS_BIGJOINER(display))
8326 max_dotclock *= 2;
8327
8328 return max_dotclock;
8329 }
8330
intel_mode_valid(struct drm_device * dev,const struct drm_display_mode * mode)8331 enum drm_mode_status intel_mode_valid(struct drm_device *dev,
8332 const struct drm_display_mode *mode)
8333 {
8334 struct drm_i915_private *dev_priv = to_i915(dev);
8335 int hdisplay_max, htotal_max;
8336 int vdisplay_max, vtotal_max;
8337
8338 /*
8339 * Can't reject DBLSCAN here because Xorg ddxen can add piles
8340 * of DBLSCAN modes to the output's mode list when they detect
8341 * the scaling mode property on the connector. And they don't
8342 * ask the kernel to validate those modes in any way until
8343 * modeset time at which point the client gets a protocol error.
8344 * So in order to not upset those clients we silently ignore the
8345 * DBLSCAN flag on such connectors. For other connectors we will
8346 * reject modes with the DBLSCAN flag in encoder->compute_config().
8347 * And we always reject DBLSCAN modes in connector->mode_valid()
8348 * as we never want such modes on the connector's mode list.
8349 */
8350
8351 if (mode->vscan > 1)
8352 return MODE_NO_VSCAN;
8353
8354 if (mode->flags & DRM_MODE_FLAG_HSKEW)
8355 return MODE_H_ILLEGAL;
8356
8357 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
8358 DRM_MODE_FLAG_NCSYNC |
8359 DRM_MODE_FLAG_PCSYNC))
8360 return MODE_HSYNC;
8361
8362 if (mode->flags & (DRM_MODE_FLAG_BCAST |
8363 DRM_MODE_FLAG_PIXMUX |
8364 DRM_MODE_FLAG_CLKDIV2))
8365 return MODE_BAD;
8366
8367 /*
8368 * Reject clearly excessive dotclocks early to
8369 * avoid having to worry about huge integers later.
8370 */
8371 if (mode->clock > max_dotclock(dev_priv))
8372 return MODE_CLOCK_HIGH;
8373
8374 /* Transcoder timing limits */
8375 if (DISPLAY_VER(dev_priv) >= 11) {
8376 hdisplay_max = 16384;
8377 vdisplay_max = 8192;
8378 htotal_max = 16384;
8379 vtotal_max = 8192;
8380 } else if (DISPLAY_VER(dev_priv) >= 9 ||
8381 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
8382 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
8383 vdisplay_max = 4096;
8384 htotal_max = 8192;
8385 vtotal_max = 8192;
8386 } else if (DISPLAY_VER(dev_priv) >= 3) {
8387 hdisplay_max = 4096;
8388 vdisplay_max = 4096;
8389 htotal_max = 8192;
8390 vtotal_max = 8192;
8391 } else {
8392 hdisplay_max = 2048;
8393 vdisplay_max = 2048;
8394 htotal_max = 4096;
8395 vtotal_max = 4096;
8396 }
8397
8398 if (mode->hdisplay > hdisplay_max ||
8399 mode->hsync_start > htotal_max ||
8400 mode->hsync_end > htotal_max ||
8401 mode->htotal > htotal_max)
8402 return MODE_H_ILLEGAL;
8403
8404 if (mode->vdisplay > vdisplay_max ||
8405 mode->vsync_start > vtotal_max ||
8406 mode->vsync_end > vtotal_max ||
8407 mode->vtotal > vtotal_max)
8408 return MODE_V_ILLEGAL;
8409
8410 return MODE_OK;
8411 }
8412
intel_cpu_transcoder_mode_valid(struct drm_i915_private * dev_priv,const struct drm_display_mode * mode)8413 enum drm_mode_status intel_cpu_transcoder_mode_valid(struct drm_i915_private *dev_priv,
8414 const struct drm_display_mode *mode)
8415 {
8416 /*
8417 * Additional transcoder timing limits,
8418 * excluding BXT/GLK DSI transcoders.
8419 */
8420 if (DISPLAY_VER(dev_priv) >= 5) {
8421 if (mode->hdisplay < 64 ||
8422 mode->htotal - mode->hdisplay < 32)
8423 return MODE_H_ILLEGAL;
8424
8425 if (mode->vtotal - mode->vdisplay < 5)
8426 return MODE_V_ILLEGAL;
8427 } else {
8428 if (mode->htotal - mode->hdisplay < 32)
8429 return MODE_H_ILLEGAL;
8430
8431 if (mode->vtotal - mode->vdisplay < 3)
8432 return MODE_V_ILLEGAL;
8433 }
8434
8435 /*
8436 * Cantiga+ cannot handle modes with a hsync front porch of 0.
8437 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
8438 */
8439 if ((DISPLAY_VER(dev_priv) >= 5 || IS_G4X(dev_priv)) &&
8440 mode->hsync_start == mode->hdisplay)
8441 return MODE_H_ILLEGAL;
8442
8443 return MODE_OK;
8444 }
8445
8446 enum drm_mode_status
intel_mode_valid_max_plane_size(struct drm_i915_private * dev_priv,const struct drm_display_mode * mode,int num_joined_pipes)8447 intel_mode_valid_max_plane_size(struct drm_i915_private *dev_priv,
8448 const struct drm_display_mode *mode,
8449 int num_joined_pipes)
8450 {
8451 int plane_width_max, plane_height_max;
8452
8453 /*
8454 * intel_mode_valid() should be
8455 * sufficient on older platforms.
8456 */
8457 if (DISPLAY_VER(dev_priv) < 9)
8458 return MODE_OK;
8459
8460 /*
8461 * Most people will probably want a fullscreen
8462 * plane so let's not advertize modes that are
8463 * too big for that.
8464 */
8465 if (DISPLAY_VER(dev_priv) >= 30) {
8466 plane_width_max = 6144 * num_joined_pipes;
8467 plane_height_max = 4800;
8468 } else if (DISPLAY_VER(dev_priv) >= 11) {
8469 plane_width_max = 5120 * num_joined_pipes;
8470 plane_height_max = 4320;
8471 } else {
8472 plane_width_max = 5120;
8473 plane_height_max = 4096;
8474 }
8475
8476 if (mode->hdisplay > plane_width_max)
8477 return MODE_H_ILLEGAL;
8478
8479 if (mode->vdisplay > plane_height_max)
8480 return MODE_V_ILLEGAL;
8481
8482 return MODE_OK;
8483 }
8484
8485 static const struct intel_display_funcs skl_display_funcs = {
8486 .get_pipe_config = hsw_get_pipe_config,
8487 .crtc_enable = hsw_crtc_enable,
8488 .crtc_disable = hsw_crtc_disable,
8489 .commit_modeset_enables = skl_commit_modeset_enables,
8490 .get_initial_plane_config = skl_get_initial_plane_config,
8491 .fixup_initial_plane_config = skl_fixup_initial_plane_config,
8492 };
8493
8494 static const struct intel_display_funcs ddi_display_funcs = {
8495 .get_pipe_config = hsw_get_pipe_config,
8496 .crtc_enable = hsw_crtc_enable,
8497 .crtc_disable = hsw_crtc_disable,
8498 .commit_modeset_enables = intel_commit_modeset_enables,
8499 .get_initial_plane_config = i9xx_get_initial_plane_config,
8500 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
8501 };
8502
8503 static const struct intel_display_funcs pch_split_display_funcs = {
8504 .get_pipe_config = ilk_get_pipe_config,
8505 .crtc_enable = ilk_crtc_enable,
8506 .crtc_disable = ilk_crtc_disable,
8507 .commit_modeset_enables = intel_commit_modeset_enables,
8508 .get_initial_plane_config = i9xx_get_initial_plane_config,
8509 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
8510 };
8511
8512 static const struct intel_display_funcs vlv_display_funcs = {
8513 .get_pipe_config = i9xx_get_pipe_config,
8514 .crtc_enable = valleyview_crtc_enable,
8515 .crtc_disable = i9xx_crtc_disable,
8516 .commit_modeset_enables = intel_commit_modeset_enables,
8517 .get_initial_plane_config = i9xx_get_initial_plane_config,
8518 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
8519 };
8520
8521 static const struct intel_display_funcs i9xx_display_funcs = {
8522 .get_pipe_config = i9xx_get_pipe_config,
8523 .crtc_enable = i9xx_crtc_enable,
8524 .crtc_disable = i9xx_crtc_disable,
8525 .commit_modeset_enables = intel_commit_modeset_enables,
8526 .get_initial_plane_config = i9xx_get_initial_plane_config,
8527 .fixup_initial_plane_config = i9xx_fixup_initial_plane_config,
8528 };
8529
8530 /**
8531 * intel_init_display_hooks - initialize the display modesetting hooks
8532 * @dev_priv: device private
8533 */
intel_init_display_hooks(struct drm_i915_private * dev_priv)8534 void intel_init_display_hooks(struct drm_i915_private *dev_priv)
8535 {
8536 if (DISPLAY_VER(dev_priv) >= 9) {
8537 dev_priv->display.funcs.display = &skl_display_funcs;
8538 } else if (HAS_DDI(dev_priv)) {
8539 dev_priv->display.funcs.display = &ddi_display_funcs;
8540 } else if (HAS_PCH_SPLIT(dev_priv)) {
8541 dev_priv->display.funcs.display = &pch_split_display_funcs;
8542 } else if (IS_CHERRYVIEW(dev_priv) ||
8543 IS_VALLEYVIEW(dev_priv)) {
8544 dev_priv->display.funcs.display = &vlv_display_funcs;
8545 } else {
8546 dev_priv->display.funcs.display = &i9xx_display_funcs;
8547 }
8548 }
8549
intel_initial_commit(struct drm_device * dev)8550 int intel_initial_commit(struct drm_device *dev)
8551 {
8552 struct drm_atomic_state *state = NULL;
8553 struct drm_modeset_acquire_ctx ctx;
8554 struct intel_crtc *crtc;
8555 int ret = 0;
8556
8557 state = drm_atomic_state_alloc(dev);
8558 if (!state)
8559 return -ENOMEM;
8560
8561 drm_modeset_acquire_init(&ctx, 0);
8562
8563 state->acquire_ctx = &ctx;
8564 to_intel_atomic_state(state)->internal = true;
8565
8566 retry:
8567 for_each_intel_crtc(dev, crtc) {
8568 struct intel_crtc_state *crtc_state =
8569 intel_atomic_get_crtc_state(state, crtc);
8570
8571 if (IS_ERR(crtc_state)) {
8572 ret = PTR_ERR(crtc_state);
8573 goto out;
8574 }
8575
8576 if (crtc_state->hw.active) {
8577 struct intel_encoder *encoder;
8578
8579 ret = drm_atomic_add_affected_planes(state, &crtc->base);
8580 if (ret)
8581 goto out;
8582
8583 /*
8584 * FIXME hack to force a LUT update to avoid the
8585 * plane update forcing the pipe gamma on without
8586 * having a proper LUT loaded. Remove once we
8587 * have readout for pipe gamma enable.
8588 */
8589 crtc_state->uapi.color_mgmt_changed = true;
8590
8591 for_each_intel_encoder_mask(dev, encoder,
8592 crtc_state->uapi.encoder_mask) {
8593 if (encoder->initial_fastset_check &&
8594 !encoder->initial_fastset_check(encoder, crtc_state)) {
8595 ret = drm_atomic_add_affected_connectors(state,
8596 &crtc->base);
8597 if (ret)
8598 goto out;
8599 }
8600 }
8601 }
8602 }
8603
8604 ret = drm_atomic_commit(state);
8605
8606 out:
8607 if (ret == -EDEADLK) {
8608 drm_atomic_state_clear(state);
8609 drm_modeset_backoff(&ctx);
8610 goto retry;
8611 }
8612
8613 drm_atomic_state_put(state);
8614
8615 drm_modeset_drop_locks(&ctx);
8616 drm_modeset_acquire_fini(&ctx);
8617
8618 return ret;
8619 }
8620
i830_enable_pipe(struct intel_display * display,enum pipe pipe)8621 void i830_enable_pipe(struct intel_display *display, enum pipe pipe)
8622 {
8623 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe);
8624 enum transcoder cpu_transcoder = (enum transcoder)pipe;
8625 /* 640x480@60Hz, ~25175 kHz */
8626 struct dpll clock = {
8627 .m1 = 18,
8628 .m2 = 7,
8629 .p1 = 13,
8630 .p2 = 4,
8631 .n = 2,
8632 };
8633 u32 dpll, fp;
8634 int i;
8635
8636 drm_WARN_ON(display->drm,
8637 i9xx_calc_dpll_params(48000, &clock) != 25154);
8638
8639 drm_dbg_kms(display->drm,
8640 "enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
8641 pipe_name(pipe), clock.vco, clock.dot);
8642
8643 fp = i9xx_dpll_compute_fp(&clock);
8644 dpll = DPLL_DVO_2X_MODE |
8645 DPLL_VGA_MODE_DIS |
8646 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
8647 PLL_P2_DIVIDE_BY_4 |
8648 PLL_REF_INPUT_DREFCLK |
8649 DPLL_VCO_ENABLE;
8650
8651 intel_de_write(display, TRANS_HTOTAL(display, cpu_transcoder),
8652 HACTIVE(640 - 1) | HTOTAL(800 - 1));
8653 intel_de_write(display, TRANS_HBLANK(display, cpu_transcoder),
8654 HBLANK_START(640 - 1) | HBLANK_END(800 - 1));
8655 intel_de_write(display, TRANS_HSYNC(display, cpu_transcoder),
8656 HSYNC_START(656 - 1) | HSYNC_END(752 - 1));
8657 intel_de_write(display, TRANS_VTOTAL(display, cpu_transcoder),
8658 VACTIVE(480 - 1) | VTOTAL(525 - 1));
8659 intel_de_write(display, TRANS_VBLANK(display, cpu_transcoder),
8660 VBLANK_START(480 - 1) | VBLANK_END(525 - 1));
8661 intel_de_write(display, TRANS_VSYNC(display, cpu_transcoder),
8662 VSYNC_START(490 - 1) | VSYNC_END(492 - 1));
8663 intel_de_write(display, PIPESRC(display, pipe),
8664 PIPESRC_WIDTH(640 - 1) | PIPESRC_HEIGHT(480 - 1));
8665
8666 intel_de_write(display, FP0(pipe), fp);
8667 intel_de_write(display, FP1(pipe), fp);
8668
8669 /*
8670 * Apparently we need to have VGA mode enabled prior to changing
8671 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
8672 * dividers, even though the register value does change.
8673 */
8674 intel_de_write(display, DPLL(display, pipe),
8675 dpll & ~DPLL_VGA_MODE_DIS);
8676 intel_de_write(display, DPLL(display, pipe), dpll);
8677
8678 /* Wait for the clocks to stabilize. */
8679 intel_de_posting_read(display, DPLL(display, pipe));
8680 udelay(150);
8681
8682 /* The pixel multiplier can only be updated once the
8683 * DPLL is enabled and the clocks are stable.
8684 *
8685 * So write it again.
8686 */
8687 intel_de_write(display, DPLL(display, pipe), dpll);
8688
8689 /* We do this three times for luck */
8690 for (i = 0; i < 3 ; i++) {
8691 intel_de_write(display, DPLL(display, pipe), dpll);
8692 intel_de_posting_read(display, DPLL(display, pipe));
8693 udelay(150); /* wait for warmup */
8694 }
8695
8696 intel_de_write(display, TRANSCONF(display, pipe), TRANSCONF_ENABLE);
8697 intel_de_posting_read(display, TRANSCONF(display, pipe));
8698
8699 intel_wait_for_pipe_scanline_moving(crtc);
8700 }
8701
i830_disable_pipe(struct intel_display * display,enum pipe pipe)8702 void i830_disable_pipe(struct intel_display *display, enum pipe pipe)
8703 {
8704 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe);
8705
8706 drm_dbg_kms(display->drm, "disabling pipe %c due to force quirk\n",
8707 pipe_name(pipe));
8708
8709 drm_WARN_ON(display->drm,
8710 intel_de_read(display, DSPCNTR(display, PLANE_A)) & DISP_ENABLE);
8711 drm_WARN_ON(display->drm,
8712 intel_de_read(display, DSPCNTR(display, PLANE_B)) & DISP_ENABLE);
8713 drm_WARN_ON(display->drm,
8714 intel_de_read(display, DSPCNTR(display, PLANE_C)) & DISP_ENABLE);
8715 drm_WARN_ON(display->drm,
8716 intel_de_read(display, CURCNTR(display, PIPE_A)) & MCURSOR_MODE_MASK);
8717 drm_WARN_ON(display->drm,
8718 intel_de_read(display, CURCNTR(display, PIPE_B)) & MCURSOR_MODE_MASK);
8719
8720 intel_de_write(display, TRANSCONF(display, pipe), 0);
8721 intel_de_posting_read(display, TRANSCONF(display, pipe));
8722
8723 intel_wait_for_pipe_scanline_stopped(crtc);
8724
8725 intel_de_write(display, DPLL(display, pipe), DPLL_VGA_MODE_DIS);
8726 intel_de_posting_read(display, DPLL(display, pipe));
8727 }
8728
intel_hpd_poll_fini(struct drm_i915_private * i915)8729 void intel_hpd_poll_fini(struct drm_i915_private *i915)
8730 {
8731 struct intel_connector *connector;
8732 struct drm_connector_list_iter conn_iter;
8733
8734 /* Kill all the work that may have been queued by hpd. */
8735 drm_connector_list_iter_begin(&i915->drm, &conn_iter);
8736 for_each_intel_connector_iter(connector, &conn_iter) {
8737 if (connector->modeset_retry_work.func &&
8738 cancel_work_sync(&connector->modeset_retry_work))
8739 drm_connector_put(&connector->base);
8740 if (connector->hdcp.shim) {
8741 cancel_delayed_work_sync(&connector->hdcp.check_work);
8742 cancel_work_sync(&connector->hdcp.prop_work);
8743 }
8744 }
8745 drm_connector_list_iter_end(&conn_iter);
8746 }
8747
intel_scanout_needs_vtd_wa(struct drm_i915_private * i915)8748 bool intel_scanout_needs_vtd_wa(struct drm_i915_private *i915)
8749 {
8750 return DISPLAY_VER(i915) >= 6 && i915_vtd_active(i915);
8751 }
8752