2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include <linux/debugfs.h>
26 #include <drm/drm_atomic_helper.h>
27 #include <drm/drm_damage_helper.h>
28 #include <drm/drm_debugfs.h>
32 #include "intel_alpm.h"
33 #include "intel_atomic.h"
34 #include "intel_crtc.h"
35 #include "intel_cursor_regs.h"
36 #include "intel_ddi.h"
38 #include "intel_display_irq.h"
39 #include "intel_display_types.h"
41 #include "intel_dp_aux.h"
42 #include "intel_frontbuffer.h"
43 #include "intel_hdmi.h"
44 #include "intel_psr.h"
45 #include "intel_psr_regs.h"
46 #include "intel_snps_phy.h"
47 #include "skl_universal_plane.h"
50 * DOC: Panel Self Refresh (PSR/SRD)
52 * Since Haswell Display controller supports Panel Self-Refresh on display
53 * panels witch have a remote frame buffer (RFB) implemented according to PSR
54 * spec in eDP1.3. PSR feature allows the display to go to lower standby states
55 * when system is idle but display is on as it eliminates display refresh
56 * request to DDR memory completely as long as the frame buffer for that
57 * display is unchanged.
59 * Panel Self Refresh must be supported by both Hardware (source) and
62 * PSR saves power by caching the framebuffer in the panel RFB, which allows us
63 * to power down the link and memory controller. For DSI panels the same idea
64 * is called "manual mode".
66 * The implementation uses the hardware-based PSR support which automatically
67 * enters/exits self-refresh mode. The hardware takes care of sending the
68 * required DP aux message and could even retrain the link (that part isn't
69 * enabled yet though). The hardware also keeps track of any frontbuffer
70 * changes to know when to exit self-refresh mode again. Unfortunately that
71 * part doesn't work too well, hence why the i915 PSR support uses the
72 * software frontbuffer tracking to make sure it doesn't miss a screen
73 * update. For this integration intel_psr_invalidate() and intel_psr_flush()
74 * get called by the frontbuffer tracking code. Note that because of locking
75 * issues the self-refresh re-enable code is done from a work queue, which
76 * must be correctly synchronized/cancelled when shutting down the pipe."
78 * DC3CO (DC3 clock off)
80 * On top of PSR2, GEN12 adds a intermediate power savings state that turns
81 * clock off automatically during PSR2 idle state.
82 * The smaller overhead of DC3co entry/exit vs. the overhead of PSR2 deep sleep
83 * entry/exit allows the HW to enter a low-power state even when page flipping
84 * periodically (for instance a 30fps video playback scenario).
86 * Every time a flips occurs PSR2 will get out of deep sleep state(if it was),
87 * so DC3CO is enabled and tgl_dc3co_disable_work is schedule to run after 6
88 * frames, if no other flip occurs and the function above is executed, DC3CO is
89 * disabled and PSR2 is configured to enter deep sleep, resetting again in case
91 * Front buffer modifications do not trigger DC3CO activation on purpose as it
92 * would bring a lot of complexity and most of the moderns systems will only
97 * Description of PSR mask bits:
99 * EDP_PSR_DEBUG[16]/EDP_PSR_DEBUG_MASK_DISP_REG_WRITE (hsw-skl):
101 * When unmasked (nearly) all display register writes (eg. even
102 * SWF) trigger a PSR exit. Some registers are excluded from this
103 * and they have a more specific mask (described below). On icl+
104 * this bit no longer exists and is effectively always set.
106 * PIPE_MISC[21]/PIPE_MISC_PSR_MASK_PIPE_REG_WRITE (skl+):
108 * When unmasked (nearly) all pipe/plane register writes
109 * trigger a PSR exit. Some plane registers are excluded from this
110 * and they have a more specific mask (described below).
112 * CHICKEN_PIPESL_1[11]/SKL_PSR_MASK_PLANE_FLIP (skl+):
113 * PIPE_MISC[23]/PIPE_MISC_PSR_MASK_PRIMARY_FLIP (bdw):
114 * EDP_PSR_DEBUG[23]/EDP_PSR_DEBUG_MASK_PRIMARY_FLIP (hsw):
116 * When unmasked PRI_SURF/PLANE_SURF writes trigger a PSR exit.
117 * SPR_SURF/CURBASE are not included in this and instead are
118 * controlled by PIPE_MISC_PSR_MASK_PIPE_REG_WRITE (skl+) or
119 * EDP_PSR_DEBUG_MASK_DISP_REG_WRITE (hsw/bdw).
121 * PIPE_MISC[22]/PIPE_MISC_PSR_MASK_SPRITE_ENABLE (bdw):
122 * EDP_PSR_DEBUG[21]/EDP_PSR_DEBUG_MASK_SPRITE_ENABLE (hsw):
124 * When unmasked PSR is blocked as long as the sprite
125 * plane is enabled. skl+ with their universal planes no
126 * longer have a mask bit like this, and no plane being
127 * enabledb blocks PSR.
129 * PIPE_MISC[21]/PIPE_MISC_PSR_MASK_CURSOR_MOVE (bdw):
130 * EDP_PSR_DEBUG[20]/EDP_PSR_DEBUG_MASK_CURSOR_MOVE (hsw):
132 * When umasked CURPOS writes trigger a PSR exit. On skl+
133 * this doesn't exit but CURPOS is included in the
134 * PIPE_MISC_PSR_MASK_PIPE_REG_WRITE mask.
136 * PIPE_MISC[20]/PIPE_MISC_PSR_MASK_VBLANK_VSYNC_INT (bdw+):
137 * EDP_PSR_DEBUG[19]/EDP_PSR_DEBUG_MASK_VBLANK_VSYNC_INT (hsw):
139 * When unmasked PSR is blocked as long as vblank and/or vsync
140 * interrupt is unmasked in IMR *and* enabled in IER.
142 * CHICKEN_TRANS[30]/SKL_UNMASK_VBL_TO_PIPE_IN_SRD (skl+):
143 * CHICKEN_PAR1_1[15]/HSW_MASK_VBL_TO_PIPE_IN_SRD (hsw/bdw):
145 * Selectcs whether PSR exit generates an extra vblank before
146 * the first frame is transmitted. Also note the opposite polarity
147 * if the bit on hsw/bdw vs. skl+ (masked==generate the extra vblank,
148 * unmasked==do not generate the extra vblank).
150 * With DC states enabled the extra vblank happens after link training,
151 * with DC states disabled it happens immediately upuon PSR exit trigger.
152 * No idea as of now why there is a difference. HSW/BDW (which don't
153 * even have DMC) always generate it after link training. Go figure.
155 * Unfortunately CHICKEN_TRANS itself seems to be double buffered
156 * and thus won't latch until the first vblank. So with DC states
157 * enabled the register effctively uses the reset value during DC5
158 * exit+PSR exit sequence, and thus the bit does nothing until
159 * latched by the vblank that it was trying to prevent from being
160 * generated in the first place. So we should probably call this
161 * one a chicken/egg bit instead on skl+.
163 * In standby mode (as opposed to link-off) this makes no difference
164 * as the timing generator keeps running the whole time generating
165 * normal periodic vblanks.
167 * WaPsrDPAMaskVBlankInSRD asks us to set the bit on hsw/bdw,
168 * and doing so makes the behaviour match the skl+ reset value.
170 * CHICKEN_PIPESL_1[0]/BDW_UNMASK_VBL_TO_REGS_IN_SRD (bdw):
171 * CHICKEN_PIPESL_1[15]/HSW_UNMASK_VBL_TO_REGS_IN_SRD (hsw):
173 * On BDW without this bit is no vblanks whatsoever are
174 * generated after PSR exit. On HSW this has no apparant effect.
175 * WaPsrDPRSUnmaskVBlankInSRD says to set this.
177 * The rest of the bits are more self-explanatory and/or
178 * irrelevant for normal operation.
180 * Description of intel_crtc_state variables. has_psr, has_panel_replay and
183 * has_psr (alone): PSR1
184 * has_psr + has_sel_update: PSR2
185 * has_psr + has_panel_replay: Panel Replay
186 * has_psr + has_panel_replay + has_sel_update: Panel Replay Selective Update
188 * Description of some intel_psr varibles. enabled, panel_replay_enabled,
191 * enabled (alone): PSR1
192 * enabled + sel_update_enabled: PSR2
193 * enabled + panel_replay_enabled: Panel Replay
194 * enabled + panel_replay_enabled + sel_update_enabled: Panel Replay SU
197 #define CAN_PSR(intel_dp) ((intel_dp)->psr.sink_support && \
198 (intel_dp)->psr.source_support)
200 bool intel_encoder_can_psr(struct intel_encoder *encoder)
202 if (intel_encoder_is_dp(encoder) || encoder->type == INTEL_OUTPUT_DP_MST)
203 return CAN_PSR(enc_to_intel_dp(encoder)) ||
204 CAN_PANEL_REPLAY(enc_to_intel_dp(encoder));
209 bool intel_psr_needs_aux_io_power(struct intel_encoder *encoder,
210 const struct intel_crtc_state *crtc_state)
213 * For PSR/PR modes only eDP requires the AUX IO power to be enabled whenever
214 * the output is enabled. For non-eDP outputs the main link is always
215 * on, hence it doesn't require the HW initiated AUX wake-up signaling used
219 * - Consider leaving AUX IO disabled for eDP / PR as well, in case
220 * the ALPM with main-link off mode is not enabled.
221 * - Leave AUX IO enabled for DP / PR, once support for ALPM with
222 * main-link off mode is added for it and this mode gets enabled.
224 return intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP) &&
225 intel_encoder_can_psr(encoder);
228 static bool psr_global_enabled(struct intel_dp *intel_dp)
230 struct intel_display *display = to_intel_display(intel_dp);
231 struct intel_connector *connector = intel_dp->attached_connector;
233 switch (intel_dp->psr.debug & I915_PSR_DEBUG_MODE_MASK) {
234 case I915_PSR_DEBUG_DEFAULT:
235 if (display->params.enable_psr == -1)
236 return intel_dp_is_edp(intel_dp) ?
237 connector->panel.vbt.psr.enable :
239 return display->params.enable_psr;
240 case I915_PSR_DEBUG_DISABLE:
247 static bool psr2_global_enabled(struct intel_dp *intel_dp)
249 struct intel_display *display = to_intel_display(intel_dp);
251 switch (intel_dp->psr.debug & I915_PSR_DEBUG_MODE_MASK) {
252 case I915_PSR_DEBUG_DISABLE:
253 case I915_PSR_DEBUG_FORCE_PSR1:
256 if (display->params.enable_psr == 1)
262 static bool psr2_su_region_et_global_enabled(struct intel_dp *intel_dp)
264 struct intel_display *display = to_intel_display(intel_dp);
266 if (display->params.enable_psr != -1)
272 static bool panel_replay_global_enabled(struct intel_dp *intel_dp)
274 struct intel_display *display = to_intel_display(intel_dp);
276 if ((display->params.enable_psr != -1) ||
277 (intel_dp->psr.debug & I915_PSR_DEBUG_PANEL_REPLAY_DISABLE))
282 static u32 psr_irq_psr_error_bit_get(struct intel_dp *intel_dp)
284 struct intel_display *display = to_intel_display(intel_dp);
286 return DISPLAY_VER(display) >= 12 ? TGL_PSR_ERROR :
287 EDP_PSR_ERROR(intel_dp->psr.transcoder);
290 static u32 psr_irq_post_exit_bit_get(struct intel_dp *intel_dp)
292 struct intel_display *display = to_intel_display(intel_dp);
294 return DISPLAY_VER(display) >= 12 ? TGL_PSR_POST_EXIT :
295 EDP_PSR_POST_EXIT(intel_dp->psr.transcoder);
298 static u32 psr_irq_pre_entry_bit_get(struct intel_dp *intel_dp)
300 struct intel_display *display = to_intel_display(intel_dp);
302 return DISPLAY_VER(display) >= 12 ? TGL_PSR_PRE_ENTRY :
303 EDP_PSR_PRE_ENTRY(intel_dp->psr.transcoder);
306 static u32 psr_irq_mask_get(struct intel_dp *intel_dp)
308 struct intel_display *display = to_intel_display(intel_dp);
310 return DISPLAY_VER(display) >= 12 ? TGL_PSR_MASK :
311 EDP_PSR_MASK(intel_dp->psr.transcoder);
314 static i915_reg_t psr_ctl_reg(struct intel_display *display,
315 enum transcoder cpu_transcoder)
317 if (DISPLAY_VER(display) >= 8)
318 return EDP_PSR_CTL(display, cpu_transcoder);
323 static i915_reg_t psr_debug_reg(struct intel_display *display,
324 enum transcoder cpu_transcoder)
326 if (DISPLAY_VER(display) >= 8)
327 return EDP_PSR_DEBUG(display, cpu_transcoder);
329 return HSW_SRD_DEBUG;
332 static i915_reg_t psr_perf_cnt_reg(struct intel_display *display,
333 enum transcoder cpu_transcoder)
335 if (DISPLAY_VER(display) >= 8)
336 return EDP_PSR_PERF_CNT(display, cpu_transcoder);
338 return HSW_SRD_PERF_CNT;
341 static i915_reg_t psr_status_reg(struct intel_display *display,
342 enum transcoder cpu_transcoder)
344 if (DISPLAY_VER(display) >= 8)
345 return EDP_PSR_STATUS(display, cpu_transcoder);
347 return HSW_SRD_STATUS;
350 static i915_reg_t psr_imr_reg(struct intel_display *display,
351 enum transcoder cpu_transcoder)
353 if (DISPLAY_VER(display) >= 12)
354 return TRANS_PSR_IMR(display, cpu_transcoder);
359 static i915_reg_t psr_iir_reg(struct intel_display *display,
360 enum transcoder cpu_transcoder)
362 if (DISPLAY_VER(display) >= 12)
363 return TRANS_PSR_IIR(display, cpu_transcoder);
368 static i915_reg_t psr_aux_ctl_reg(struct intel_display *display,
369 enum transcoder cpu_transcoder)
371 if (DISPLAY_VER(display) >= 8)
372 return EDP_PSR_AUX_CTL(display, cpu_transcoder);
374 return HSW_SRD_AUX_CTL;
377 static i915_reg_t psr_aux_data_reg(struct intel_display *display,
378 enum transcoder cpu_transcoder, int i)
380 if (DISPLAY_VER(display) >= 8)
381 return EDP_PSR_AUX_DATA(display, cpu_transcoder, i);
383 return HSW_SRD_AUX_DATA(i);
386 static void psr_irq_control(struct intel_dp *intel_dp)
388 struct intel_display *display = to_intel_display(intel_dp);
389 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
392 if (intel_dp->psr.panel_replay_enabled)
395 mask = psr_irq_psr_error_bit_get(intel_dp);
396 if (intel_dp->psr.debug & I915_PSR_DEBUG_IRQ)
397 mask |= psr_irq_post_exit_bit_get(intel_dp) |
398 psr_irq_pre_entry_bit_get(intel_dp);
400 intel_de_rmw(display, psr_imr_reg(display, cpu_transcoder),
401 psr_irq_mask_get(intel_dp), ~mask);
404 static void psr_event_print(struct intel_display *display,
405 u32 val, bool sel_update_enabled)
407 drm_dbg_kms(display->drm, "PSR exit events: 0x%x\n", val);
408 if (val & PSR_EVENT_PSR2_WD_TIMER_EXPIRE)
409 drm_dbg_kms(display->drm, "\tPSR2 watchdog timer expired\n");
410 if ((val & PSR_EVENT_PSR2_DISABLED) && sel_update_enabled)
411 drm_dbg_kms(display->drm, "\tPSR2 disabled\n");
412 if (val & PSR_EVENT_SU_DIRTY_FIFO_UNDERRUN)
413 drm_dbg_kms(display->drm, "\tSU dirty FIFO underrun\n");
414 if (val & PSR_EVENT_SU_CRC_FIFO_UNDERRUN)
415 drm_dbg_kms(display->drm, "\tSU CRC FIFO underrun\n");
416 if (val & PSR_EVENT_GRAPHICS_RESET)
417 drm_dbg_kms(display->drm, "\tGraphics reset\n");
418 if (val & PSR_EVENT_PCH_INTERRUPT)
419 drm_dbg_kms(display->drm, "\tPCH interrupt\n");
420 if (val & PSR_EVENT_MEMORY_UP)
421 drm_dbg_kms(display->drm, "\tMemory up\n");
422 if (val & PSR_EVENT_FRONT_BUFFER_MODIFY)
423 drm_dbg_kms(display->drm, "\tFront buffer modification\n");
424 if (val & PSR_EVENT_WD_TIMER_EXPIRE)
425 drm_dbg_kms(display->drm, "\tPSR watchdog timer expired\n");
426 if (val & PSR_EVENT_PIPE_REGISTERS_UPDATE)
427 drm_dbg_kms(display->drm, "\tPIPE registers updated\n");
428 if (val & PSR_EVENT_REGISTER_UPDATE)
429 drm_dbg_kms(display->drm, "\tRegister updated\n");
430 if (val & PSR_EVENT_HDCP_ENABLE)
431 drm_dbg_kms(display->drm, "\tHDCP enabled\n");
432 if (val & PSR_EVENT_KVMR_SESSION_ENABLE)
433 drm_dbg_kms(display->drm, "\tKVMR session enabled\n");
434 if (val & PSR_EVENT_VBI_ENABLE)
435 drm_dbg_kms(display->drm, "\tVBI enabled\n");
436 if (val & PSR_EVENT_LPSP_MODE_EXIT)
437 drm_dbg_kms(display->drm, "\tLPSP mode exited\n");
438 if ((val & PSR_EVENT_PSR_DISABLE) && !sel_update_enabled)
439 drm_dbg_kms(display->drm, "\tPSR disabled\n");
442 void intel_psr_irq_handler(struct intel_dp *intel_dp, u32 psr_iir)
444 struct intel_display *display = to_intel_display(intel_dp);
445 struct drm_i915_private *dev_priv = to_i915(display->drm);
446 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
447 ktime_t time_ns = ktime_get();
449 if (psr_iir & psr_irq_pre_entry_bit_get(intel_dp)) {
450 intel_dp->psr.last_entry_attempt = time_ns;
451 drm_dbg_kms(display->drm,
452 "[transcoder %s] PSR entry attempt in 2 vblanks\n",
453 transcoder_name(cpu_transcoder));
456 if (psr_iir & psr_irq_post_exit_bit_get(intel_dp)) {
457 intel_dp->psr.last_exit = time_ns;
458 drm_dbg_kms(display->drm,
459 "[transcoder %s] PSR exit completed\n",
460 transcoder_name(cpu_transcoder));
462 if (DISPLAY_VER(display) >= 9) {
465 val = intel_de_rmw(dev_priv,
466 PSR_EVENT(dev_priv, cpu_transcoder),
469 psr_event_print(display, val, intel_dp->psr.sel_update_enabled);
473 if (psr_iir & psr_irq_psr_error_bit_get(intel_dp)) {
474 drm_warn(display->drm, "[transcoder %s] PSR aux error\n",
475 transcoder_name(cpu_transcoder));
477 intel_dp->psr.irq_aux_error = true;
480 * If this interruption is not masked it will keep
481 * interrupting so fast that it prevents the scheduled
483 * Also after a PSR error, we don't want to arm PSR
484 * again so we don't care about unmask the interruption
485 * or unset irq_aux_error.
487 intel_de_rmw(display, psr_imr_reg(display, cpu_transcoder),
488 0, psr_irq_psr_error_bit_get(intel_dp));
490 queue_work(dev_priv->unordered_wq, &intel_dp->psr.work);
494 static u8 intel_dp_get_sink_sync_latency(struct intel_dp *intel_dp)
496 struct intel_display *display = to_intel_display(intel_dp);
497 u8 val = 8; /* assume the worst if we can't read the value */
499 if (drm_dp_dpcd_readb(&intel_dp->aux,
500 DP_SYNCHRONIZATION_LATENCY_IN_SINK, &val) == 1)
501 val &= DP_MAX_RESYNC_FRAME_COUNT_MASK;
503 drm_dbg_kms(display->drm,
504 "Unable to get sink synchronization latency, assuming 8 frames\n");
508 static u8 intel_dp_get_su_capability(struct intel_dp *intel_dp)
510 u8 su_capability = 0;
512 if (intel_dp->psr.sink_panel_replay_su_support)
513 drm_dp_dpcd_readb(&intel_dp->aux,
514 DP_PANEL_PANEL_REPLAY_CAPABILITY,
517 su_capability = intel_dp->psr_dpcd[1];
519 return su_capability;
523 intel_dp_get_su_x_granularity_offset(struct intel_dp *intel_dp)
525 return intel_dp->psr.sink_panel_replay_su_support ?
526 DP_PANEL_PANEL_REPLAY_X_GRANULARITY :
527 DP_PSR2_SU_X_GRANULARITY;
531 intel_dp_get_su_y_granularity_offset(struct intel_dp *intel_dp)
533 return intel_dp->psr.sink_panel_replay_su_support ?
534 DP_PANEL_PANEL_REPLAY_Y_GRANULARITY :
535 DP_PSR2_SU_Y_GRANULARITY;
539 * Note: Bits related to granularity are same in panel replay and psr
540 * registers. Rely on PSR definitions on these "common" bits.
542 static void intel_dp_get_su_granularity(struct intel_dp *intel_dp)
544 struct intel_display *display = to_intel_display(intel_dp);
550 * TODO: Do we need to take into account panel supporting both PSR and
555 * If sink don't have specific granularity requirements set legacy
558 if (!(intel_dp_get_su_capability(intel_dp) &
559 DP_PSR2_SU_GRANULARITY_REQUIRED)) {
560 /* As PSR2 HW sends full lines, we do not care about x granularity */
566 r = drm_dp_dpcd_read(&intel_dp->aux,
567 intel_dp_get_su_x_granularity_offset(intel_dp),
570 drm_dbg_kms(display->drm,
571 "Unable to read selective update x granularity\n");
573 * Spec says that if the value read is 0 the default granularity should
576 if (r != 2 || w == 0)
579 r = drm_dp_dpcd_read(&intel_dp->aux,
580 intel_dp_get_su_y_granularity_offset(intel_dp),
583 drm_dbg_kms(display->drm,
584 "Unable to read selective update y granularity\n");
591 intel_dp->psr.su_w_granularity = w;
592 intel_dp->psr.su_y_granularity = y;
595 static void _panel_replay_init_dpcd(struct intel_dp *intel_dp)
597 struct intel_display *display = to_intel_display(intel_dp);
599 if (intel_dp_is_edp(intel_dp)) {
600 if (!intel_alpm_aux_less_wake_supported(intel_dp)) {
601 drm_dbg_kms(display->drm,
602 "Panel doesn't support AUX-less ALPM, eDP Panel Replay not possible\n");
606 if (!(intel_dp->pr_dpcd & DP_PANEL_REPLAY_EARLY_TRANSPORT_SUPPORT)) {
607 drm_dbg_kms(display->drm,
608 "Panel doesn't support early transport, eDP Panel Replay not possible\n");
613 intel_dp->psr.sink_panel_replay_support = true;
615 if (intel_dp->pr_dpcd & DP_PANEL_REPLAY_SU_SUPPORT)
616 intel_dp->psr.sink_panel_replay_su_support = true;
618 drm_dbg_kms(display->drm,
619 "Panel replay %sis supported by panel\n",
620 intel_dp->psr.sink_panel_replay_su_support ?
621 "selective_update " : "");
624 static void _psr_init_dpcd(struct intel_dp *intel_dp)
626 struct intel_display *display = to_intel_display(intel_dp);
628 drm_dbg_kms(display->drm, "eDP panel supports PSR version %x\n",
629 intel_dp->psr_dpcd[0]);
631 if (drm_dp_has_quirk(&intel_dp->desc, DP_DPCD_QUIRK_NO_PSR)) {
632 drm_dbg_kms(display->drm,
633 "PSR support not currently available for this panel\n");
637 if (!(intel_dp->edp_dpcd[1] & DP_EDP_SET_POWER_CAP)) {
638 drm_dbg_kms(display->drm,
639 "Panel lacks power state control, PSR cannot be enabled\n");
643 intel_dp->psr.sink_support = true;
644 intel_dp->psr.sink_sync_latency =
645 intel_dp_get_sink_sync_latency(intel_dp);
647 if (DISPLAY_VER(display) >= 9 &&
648 intel_dp->psr_dpcd[0] >= DP_PSR2_WITH_Y_COORD_IS_SUPPORTED) {
649 bool y_req = intel_dp->psr_dpcd[1] &
650 DP_PSR2_SU_Y_COORDINATE_REQUIRED;
653 * All panels that supports PSR version 03h (PSR2 +
654 * Y-coordinate) can handle Y-coordinates in VSC but we are
655 * only sure that it is going to be used when required by the
656 * panel. This way panel is capable to do selective update
657 * without a aux frame sync.
659 * To support PSR version 02h and PSR version 03h without
660 * Y-coordinate requirement panels we would need to enable
663 intel_dp->psr.sink_psr2_support = y_req &&
664 intel_alpm_aux_wake_supported(intel_dp);
665 drm_dbg_kms(display->drm, "PSR2 %ssupported\n",
666 intel_dp->psr.sink_psr2_support ? "" : "not ");
670 void intel_psr_init_dpcd(struct intel_dp *intel_dp)
672 drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT, intel_dp->psr_dpcd,
673 sizeof(intel_dp->psr_dpcd));
674 drm_dp_dpcd_readb(&intel_dp->aux, DP_PANEL_REPLAY_CAP,
677 if (intel_dp->pr_dpcd & DP_PANEL_REPLAY_SUPPORT)
678 _panel_replay_init_dpcd(intel_dp);
680 if (intel_dp->psr_dpcd[0])
681 _psr_init_dpcd(intel_dp);
683 if (intel_dp->psr.sink_psr2_support ||
684 intel_dp->psr.sink_panel_replay_su_support)
685 intel_dp_get_su_granularity(intel_dp);
688 static void hsw_psr_setup_aux(struct intel_dp *intel_dp)
690 struct intel_display *display = to_intel_display(intel_dp);
691 struct drm_i915_private *dev_priv = to_i915(display->drm);
692 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
693 u32 aux_clock_divider, aux_ctl;
694 /* write DP_SET_POWER=D0 */
695 static const u8 aux_msg[] = {
696 [0] = (DP_AUX_NATIVE_WRITE << 4) | ((DP_SET_POWER >> 16) & 0xf),
697 [1] = (DP_SET_POWER >> 8) & 0xff,
698 [2] = DP_SET_POWER & 0xff,
700 [4] = DP_SET_POWER_D0,
704 BUILD_BUG_ON(sizeof(aux_msg) > 20);
705 for (i = 0; i < sizeof(aux_msg); i += 4)
706 intel_de_write(dev_priv,
707 psr_aux_data_reg(display, cpu_transcoder, i >> 2),
708 intel_dp_aux_pack(&aux_msg[i], sizeof(aux_msg) - i));
710 aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0);
712 /* Start with bits set for DDI_AUX_CTL register */
713 aux_ctl = intel_dp->get_aux_send_ctl(intel_dp, sizeof(aux_msg),
716 /* Select only valid bits for SRD_AUX_CTL */
717 aux_ctl &= EDP_PSR_AUX_CTL_TIME_OUT_MASK |
718 EDP_PSR_AUX_CTL_MESSAGE_SIZE_MASK |
719 EDP_PSR_AUX_CTL_PRECHARGE_2US_MASK |
720 EDP_PSR_AUX_CTL_BIT_CLOCK_2X_MASK;
722 intel_de_write(display, psr_aux_ctl_reg(display, cpu_transcoder),
726 static bool psr2_su_region_et_valid(struct intel_dp *intel_dp, bool panel_replay)
728 struct intel_display *display = to_intel_display(intel_dp);
730 if (DISPLAY_VER(display) < 20 || !intel_dp_is_edp(intel_dp) ||
731 intel_dp->psr.debug & I915_PSR_DEBUG_SU_REGION_ET_DISABLE)
734 return panel_replay ?
735 intel_dp->pr_dpcd & DP_PANEL_REPLAY_EARLY_TRANSPORT_SUPPORT :
736 intel_dp->psr_dpcd[0] == DP_PSR2_WITH_Y_COORD_ET_SUPPORTED &&
737 psr2_su_region_et_global_enabled(intel_dp);
740 static void _panel_replay_enable_sink(struct intel_dp *intel_dp,
741 const struct intel_crtc_state *crtc_state)
743 u8 val = DP_PANEL_REPLAY_ENABLE |
744 DP_PANEL_REPLAY_VSC_SDP_CRC_EN |
745 DP_PANEL_REPLAY_UNRECOVERABLE_ERROR_EN |
746 DP_PANEL_REPLAY_RFB_STORAGE_ERROR_EN |
747 DP_PANEL_REPLAY_ACTIVE_FRAME_CRC_ERROR_EN;
748 u8 panel_replay_config2 = DP_PANEL_REPLAY_CRC_VERIFICATION;
750 if (crtc_state->has_sel_update)
751 val |= DP_PANEL_REPLAY_SU_ENABLE;
753 if (crtc_state->enable_psr2_su_region_et)
754 val |= DP_PANEL_REPLAY_ENABLE_SU_REGION_ET;
756 if (crtc_state->req_psr2_sdp_prior_scanline)
757 panel_replay_config2 |=
758 DP_PANEL_REPLAY_SU_REGION_SCANLINE_CAPTURE;
760 drm_dp_dpcd_writeb(&intel_dp->aux, PANEL_REPLAY_CONFIG, val);
762 drm_dp_dpcd_writeb(&intel_dp->aux, PANEL_REPLAY_CONFIG2,
763 panel_replay_config2);
766 static void _psr_enable_sink(struct intel_dp *intel_dp,
767 const struct intel_crtc_state *crtc_state)
769 struct intel_display *display = to_intel_display(intel_dp);
772 if (crtc_state->has_sel_update) {
773 val |= DP_PSR_ENABLE_PSR2 | DP_PSR_IRQ_HPD_WITH_CRC_ERRORS;
775 if (intel_dp->psr.link_standby)
776 val |= DP_PSR_MAIN_LINK_ACTIVE;
778 if (DISPLAY_VER(display) >= 8)
779 val |= DP_PSR_CRC_VERIFICATION;
782 if (crtc_state->req_psr2_sdp_prior_scanline)
783 val |= DP_PSR_SU_REGION_SCANLINE_CAPTURE;
785 if (crtc_state->enable_psr2_su_region_et)
786 val |= DP_PANEL_REPLAY_ENABLE_SU_REGION_ET;
788 if (intel_dp->psr.entry_setup_frames > 0)
789 val |= DP_PSR_FRAME_CAPTURE;
790 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, val);
792 val |= DP_PSR_ENABLE;
793 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, val);
796 static void intel_psr_enable_sink_alpm(struct intel_dp *intel_dp,
797 const struct intel_crtc_state *crtc_state)
802 * eDP Panel Replay uses always ALPM
803 * PSR2 uses ALPM but PSR1 doesn't
805 if (!intel_dp_is_edp(intel_dp) || (!crtc_state->has_panel_replay &&
806 !crtc_state->has_sel_update))
809 val = DP_ALPM_ENABLE | DP_ALPM_LOCK_ERROR_IRQ_HPD_ENABLE;
811 if (crtc_state->has_panel_replay)
812 val |= DP_ALPM_MODE_AUX_LESS;
814 drm_dp_dpcd_writeb(&intel_dp->aux, DP_RECEIVER_ALPM_CONFIG, val);
817 void intel_psr_enable_sink(struct intel_dp *intel_dp,
818 const struct intel_crtc_state *crtc_state)
820 intel_psr_enable_sink_alpm(intel_dp, crtc_state);
822 crtc_state->has_panel_replay ?
823 _panel_replay_enable_sink(intel_dp, crtc_state) :
824 _psr_enable_sink(intel_dp, crtc_state);
826 if (intel_dp_is_edp(intel_dp))
827 drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, DP_SET_POWER_D0);
830 static u32 intel_psr1_get_tp_time(struct intel_dp *intel_dp)
832 struct intel_display *display = to_intel_display(intel_dp);
833 struct intel_connector *connector = intel_dp->attached_connector;
834 struct drm_i915_private *dev_priv = to_i915(display->drm);
837 if (DISPLAY_VER(display) >= 11)
838 val |= EDP_PSR_TP4_TIME_0us;
840 if (display->params.psr_safest_params) {
841 val |= EDP_PSR_TP1_TIME_2500us;
842 val |= EDP_PSR_TP2_TP3_TIME_2500us;
846 if (connector->panel.vbt.psr.tp1_wakeup_time_us == 0)
847 val |= EDP_PSR_TP1_TIME_0us;
848 else if (connector->panel.vbt.psr.tp1_wakeup_time_us <= 100)
849 val |= EDP_PSR_TP1_TIME_100us;
850 else if (connector->panel.vbt.psr.tp1_wakeup_time_us <= 500)
851 val |= EDP_PSR_TP1_TIME_500us;
853 val |= EDP_PSR_TP1_TIME_2500us;
855 if (connector->panel.vbt.psr.tp2_tp3_wakeup_time_us == 0)
856 val |= EDP_PSR_TP2_TP3_TIME_0us;
857 else if (connector->panel.vbt.psr.tp2_tp3_wakeup_time_us <= 100)
858 val |= EDP_PSR_TP2_TP3_TIME_100us;
859 else if (connector->panel.vbt.psr.tp2_tp3_wakeup_time_us <= 500)
860 val |= EDP_PSR_TP2_TP3_TIME_500us;
862 val |= EDP_PSR_TP2_TP3_TIME_2500us;
866 * "Do not skip both TP1 and TP2/TP3"
868 if (DISPLAY_VER(dev_priv) < 9 &&
869 connector->panel.vbt.psr.tp1_wakeup_time_us == 0 &&
870 connector->panel.vbt.psr.tp2_tp3_wakeup_time_us == 0)
871 val |= EDP_PSR_TP2_TP3_TIME_100us;
874 if (intel_dp_source_supports_tps3(display) &&
875 drm_dp_tps3_supported(intel_dp->dpcd))
876 val |= EDP_PSR_TP_TP1_TP3;
878 val |= EDP_PSR_TP_TP1_TP2;
883 static u8 psr_compute_idle_frames(struct intel_dp *intel_dp)
885 struct intel_display *display = to_intel_display(intel_dp);
886 struct intel_connector *connector = intel_dp->attached_connector;
889 /* Let's use 6 as the minimum to cover all known cases including the
890 * off-by-one issue that HW has in some cases.
892 idle_frames = max(6, connector->panel.vbt.psr.idle_frames);
893 idle_frames = max(idle_frames, intel_dp->psr.sink_sync_latency + 1);
895 if (drm_WARN_ON(display->drm, idle_frames > 0xf))
901 static void hsw_activate_psr1(struct intel_dp *intel_dp)
903 struct intel_display *display = to_intel_display(intel_dp);
904 struct drm_i915_private *dev_priv = to_i915(display->drm);
905 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
906 u32 max_sleep_time = 0x1f;
907 u32 val = EDP_PSR_ENABLE;
909 val |= EDP_PSR_IDLE_FRAMES(psr_compute_idle_frames(intel_dp));
911 if (DISPLAY_VER(display) < 20)
912 val |= EDP_PSR_MAX_SLEEP_TIME(max_sleep_time);
914 if (IS_HASWELL(dev_priv))
915 val |= EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
917 if (intel_dp->psr.link_standby)
918 val |= EDP_PSR_LINK_STANDBY;
920 val |= intel_psr1_get_tp_time(intel_dp);
922 if (DISPLAY_VER(display) >= 8)
923 val |= EDP_PSR_CRC_ENABLE;
925 if (DISPLAY_VER(display) >= 20)
926 val |= LNL_EDP_PSR_ENTRY_SETUP_FRAMES(intel_dp->psr.entry_setup_frames);
928 intel_de_rmw(display, psr_ctl_reg(display, cpu_transcoder),
929 ~EDP_PSR_RESTORE_PSR_ACTIVE_CTX_MASK, val);
932 static u32 intel_psr2_get_tp_time(struct intel_dp *intel_dp)
934 struct intel_display *display = to_intel_display(intel_dp);
935 struct intel_connector *connector = intel_dp->attached_connector;
938 if (display->params.psr_safest_params)
939 return EDP_PSR2_TP2_TIME_2500us;
941 if (connector->panel.vbt.psr.psr2_tp2_tp3_wakeup_time_us >= 0 &&
942 connector->panel.vbt.psr.psr2_tp2_tp3_wakeup_time_us <= 50)
943 val |= EDP_PSR2_TP2_TIME_50us;
944 else if (connector->panel.vbt.psr.psr2_tp2_tp3_wakeup_time_us <= 100)
945 val |= EDP_PSR2_TP2_TIME_100us;
946 else if (connector->panel.vbt.psr.psr2_tp2_tp3_wakeup_time_us <= 500)
947 val |= EDP_PSR2_TP2_TIME_500us;
949 val |= EDP_PSR2_TP2_TIME_2500us;
954 static int psr2_block_count_lines(struct intel_dp *intel_dp)
956 return intel_dp->alpm_parameters.io_wake_lines < 9 &&
957 intel_dp->alpm_parameters.fast_wake_lines < 9 ? 8 : 12;
960 static int psr2_block_count(struct intel_dp *intel_dp)
962 return psr2_block_count_lines(intel_dp) / 4;
965 static u8 frames_before_su_entry(struct intel_dp *intel_dp)
967 u8 frames_before_su_entry;
969 frames_before_su_entry = max_t(u8,
970 intel_dp->psr.sink_sync_latency + 1,
973 /* Entry setup frames must be at least 1 less than frames before SU entry */
974 if (intel_dp->psr.entry_setup_frames >= frames_before_su_entry)
975 frames_before_su_entry = intel_dp->psr.entry_setup_frames + 1;
977 return frames_before_su_entry;
980 static void dg2_activate_panel_replay(struct intel_dp *intel_dp)
982 struct intel_display *display = to_intel_display(intel_dp);
983 struct intel_psr *psr = &intel_dp->psr;
984 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
986 if (intel_dp_is_edp(intel_dp) && psr->sel_update_enabled) {
987 u32 val = psr->su_region_et_enabled ?
988 LNL_EDP_PSR2_SU_REGION_ET_ENABLE : 0;
990 if (intel_dp->psr.req_psr2_sdp_prior_scanline)
991 val |= EDP_PSR2_SU_SDP_SCANLINE;
993 intel_de_write(display, EDP_PSR2_CTL(display, cpu_transcoder),
997 intel_de_rmw(display,
998 PSR2_MAN_TRK_CTL(display, intel_dp->psr.transcoder),
999 0, ADLP_PSR2_MAN_TRK_CTL_SF_CONTINUOS_FULL_FRAME);
1001 intel_de_rmw(display, TRANS_DP2_CTL(intel_dp->psr.transcoder), 0,
1002 TRANS_DP2_PANEL_REPLAY_ENABLE);
1005 static void hsw_activate_psr2(struct intel_dp *intel_dp)
1007 struct intel_display *display = to_intel_display(intel_dp);
1008 struct drm_i915_private *dev_priv = to_i915(display->drm);
1009 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
1010 u32 val = EDP_PSR2_ENABLE;
1013 val |= EDP_PSR2_IDLE_FRAMES(psr_compute_idle_frames(intel_dp));
1015 if (DISPLAY_VER(display) < 14 && !IS_ALDERLAKE_P(dev_priv))
1016 val |= EDP_SU_TRACK_ENABLE;
1018 if (DISPLAY_VER(display) >= 10 && DISPLAY_VER(display) < 13)
1019 val |= EDP_Y_COORDINATE_ENABLE;
1021 val |= EDP_PSR2_FRAME_BEFORE_SU(frames_before_su_entry(intel_dp));
1023 val |= intel_psr2_get_tp_time(intel_dp);
1025 if (DISPLAY_VER(display) >= 12 && DISPLAY_VER(display) < 20) {
1026 if (psr2_block_count(intel_dp) > 2)
1027 val |= TGL_EDP_PSR2_BLOCK_COUNT_NUM_3;
1029 val |= TGL_EDP_PSR2_BLOCK_COUNT_NUM_2;
1032 /* Wa_22012278275:adl-p */
1033 if (IS_ALDERLAKE_P(dev_priv) && IS_DISPLAY_STEP(display, STEP_A0, STEP_E0)) {
1034 static const u8 map[] = {
1045 * Still using the default IO_BUFFER_WAKE and FAST_WAKE, see
1046 * comments bellow for more information
1050 tmp = map[intel_dp->alpm_parameters.io_wake_lines -
1051 TGL_EDP_PSR2_IO_BUFFER_WAKE_MIN_LINES];
1052 val |= TGL_EDP_PSR2_IO_BUFFER_WAKE(tmp + TGL_EDP_PSR2_IO_BUFFER_WAKE_MIN_LINES);
1054 tmp = map[intel_dp->alpm_parameters.fast_wake_lines - TGL_EDP_PSR2_FAST_WAKE_MIN_LINES];
1055 val |= TGL_EDP_PSR2_FAST_WAKE(tmp + TGL_EDP_PSR2_FAST_WAKE_MIN_LINES);
1056 } else if (DISPLAY_VER(display) >= 20) {
1057 val |= LNL_EDP_PSR2_IO_BUFFER_WAKE(intel_dp->alpm_parameters.io_wake_lines);
1058 } else if (DISPLAY_VER(display) >= 12) {
1059 val |= TGL_EDP_PSR2_IO_BUFFER_WAKE(intel_dp->alpm_parameters.io_wake_lines);
1060 val |= TGL_EDP_PSR2_FAST_WAKE(intel_dp->alpm_parameters.fast_wake_lines);
1061 } else if (DISPLAY_VER(display) >= 9) {
1062 val |= EDP_PSR2_IO_BUFFER_WAKE(intel_dp->alpm_parameters.io_wake_lines);
1063 val |= EDP_PSR2_FAST_WAKE(intel_dp->alpm_parameters.fast_wake_lines);
1066 if (intel_dp->psr.req_psr2_sdp_prior_scanline)
1067 val |= EDP_PSR2_SU_SDP_SCANLINE;
1069 if (DISPLAY_VER(display) >= 20)
1070 psr_val |= LNL_EDP_PSR_ENTRY_SETUP_FRAMES(intel_dp->psr.entry_setup_frames);
1072 if (intel_dp->psr.psr2_sel_fetch_enabled) {
1075 tmp = intel_de_read(display,
1076 PSR2_MAN_TRK_CTL(display, cpu_transcoder));
1077 drm_WARN_ON(display->drm, !(tmp & PSR2_MAN_TRK_CTL_ENABLE));
1078 } else if (HAS_PSR2_SEL_FETCH(display)) {
1079 intel_de_write(display,
1080 PSR2_MAN_TRK_CTL(display, cpu_transcoder), 0);
1083 if (intel_dp->psr.su_region_et_enabled)
1084 val |= LNL_EDP_PSR2_SU_REGION_ET_ENABLE;
1087 * PSR2 HW is incorrectly using EDP_PSR_TP1_TP3_SEL and BSpec is
1088 * recommending keep this bit unset while PSR2 is enabled.
1090 intel_de_write(display, psr_ctl_reg(display, cpu_transcoder), psr_val);
1092 intel_de_write(display, EDP_PSR2_CTL(display, cpu_transcoder), val);
1096 transcoder_has_psr2(struct intel_display *display, enum transcoder cpu_transcoder)
1098 struct drm_i915_private *dev_priv = to_i915(display->drm);
1100 if (IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14)
1101 return cpu_transcoder == TRANSCODER_A || cpu_transcoder == TRANSCODER_B;
1102 else if (DISPLAY_VER(display) >= 12)
1103 return cpu_transcoder == TRANSCODER_A;
1104 else if (DISPLAY_VER(display) >= 9)
1105 return cpu_transcoder == TRANSCODER_EDP;
1110 static u32 intel_get_frame_time_us(const struct intel_crtc_state *crtc_state)
1112 if (!crtc_state->hw.active)
1115 return DIV_ROUND_UP(1000 * 1000,
1116 drm_mode_vrefresh(&crtc_state->hw.adjusted_mode));
1119 static void psr2_program_idle_frames(struct intel_dp *intel_dp,
1122 struct intel_display *display = to_intel_display(intel_dp);
1123 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
1125 intel_de_rmw(display, EDP_PSR2_CTL(display, cpu_transcoder),
1126 EDP_PSR2_IDLE_FRAMES_MASK,
1127 EDP_PSR2_IDLE_FRAMES(idle_frames));
1130 static void tgl_psr2_enable_dc3co(struct intel_dp *intel_dp)
1132 struct intel_display *display = to_intel_display(intel_dp);
1134 psr2_program_idle_frames(intel_dp, 0);
1135 intel_display_power_set_target_dc_state(display, DC_STATE_EN_DC3CO);
1138 static void tgl_psr2_disable_dc3co(struct intel_dp *intel_dp)
1140 struct intel_display *display = to_intel_display(intel_dp);
1142 intel_display_power_set_target_dc_state(display, DC_STATE_EN_UPTO_DC6);
1143 psr2_program_idle_frames(intel_dp, psr_compute_idle_frames(intel_dp));
1146 static void tgl_dc3co_disable_work(struct work_struct *work)
1148 struct intel_dp *intel_dp =
1149 container_of(work, typeof(*intel_dp), psr.dc3co_work.work);
1151 mutex_lock(&intel_dp->psr.lock);
1152 /* If delayed work is pending, it is not idle */
1153 if (delayed_work_pending(&intel_dp->psr.dc3co_work))
1156 tgl_psr2_disable_dc3co(intel_dp);
1158 mutex_unlock(&intel_dp->psr.lock);
1161 static void tgl_disallow_dc3co_on_psr2_exit(struct intel_dp *intel_dp)
1163 if (!intel_dp->psr.dc3co_exitline)
1166 cancel_delayed_work(&intel_dp->psr.dc3co_work);
1167 /* Before PSR2 exit disallow dc3co*/
1168 tgl_psr2_disable_dc3co(intel_dp);
1172 dc3co_is_pipe_port_compatible(struct intel_dp *intel_dp,
1173 struct intel_crtc_state *crtc_state)
1175 struct intel_display *display = to_intel_display(intel_dp);
1176 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1177 enum pipe pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe;
1178 struct drm_i915_private *dev_priv = to_i915(display->drm);
1179 enum port port = dig_port->base.port;
1181 if (IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14)
1182 return pipe <= PIPE_B && port <= PORT_B;
1184 return pipe == PIPE_A && port == PORT_A;
1188 tgl_dc3co_exitline_compute_config(struct intel_dp *intel_dp,
1189 struct intel_crtc_state *crtc_state)
1191 struct intel_display *display = to_intel_display(intel_dp);
1192 struct drm_i915_private *dev_priv = to_i915(display->drm);
1193 const u32 crtc_vdisplay = crtc_state->uapi.adjusted_mode.crtc_vdisplay;
1194 struct i915_power_domains *power_domains = &display->power.domains;
1198 * FIXME: Due to the changed sequence of activating/deactivating DC3CO,
1199 * disable DC3CO until the changed dc3co activating/deactivating sequence
1200 * is applied. B.Specs:49196
1205 * DMC's DC3CO exit mechanism has an issue with Selective Fecth
1206 * TODO: when the issue is addressed, this restriction should be removed.
1208 if (crtc_state->enable_psr2_sel_fetch)
1211 if (!(power_domains->allowed_dc_mask & DC_STATE_EN_DC3CO))
1214 if (!dc3co_is_pipe_port_compatible(intel_dp, crtc_state))
1217 /* Wa_16011303918:adl-p */
1218 if (IS_ALDERLAKE_P(dev_priv) && IS_DISPLAY_STEP(display, STEP_A0, STEP_B0))
1222 * DC3CO Exit time 200us B.Spec 49196
1223 * PSR2 transcoder Early Exit scanlines = ROUNDUP(200 / line time) + 1
1226 intel_usecs_to_scanlines(&crtc_state->uapi.adjusted_mode, 200) + 1;
1228 if (drm_WARN_ON(display->drm, exit_scanlines > crtc_vdisplay))
1231 crtc_state->dc3co_exitline = crtc_vdisplay - exit_scanlines;
1234 static bool intel_psr2_sel_fetch_config_valid(struct intel_dp *intel_dp,
1235 struct intel_crtc_state *crtc_state)
1237 struct intel_display *display = to_intel_display(intel_dp);
1239 if (!display->params.enable_psr2_sel_fetch &&
1240 intel_dp->psr.debug != I915_PSR_DEBUG_ENABLE_SEL_FETCH) {
1241 drm_dbg_kms(display->drm,
1242 "PSR2 sel fetch not enabled, disabled by parameter\n");
1246 if (crtc_state->uapi.async_flip) {
1247 drm_dbg_kms(display->drm,
1248 "PSR2 sel fetch not enabled, async flip enabled\n");
1252 return crtc_state->enable_psr2_sel_fetch = true;
1255 static bool psr2_granularity_check(struct intel_dp *intel_dp,
1256 struct intel_crtc_state *crtc_state)
1258 struct intel_display *display = to_intel_display(intel_dp);
1259 struct drm_i915_private *dev_priv = to_i915(display->drm);
1260 const struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config;
1261 const int crtc_hdisplay = crtc_state->hw.adjusted_mode.crtc_hdisplay;
1262 const int crtc_vdisplay = crtc_state->hw.adjusted_mode.crtc_vdisplay;
1263 u16 y_granularity = 0;
1265 /* PSR2 HW only send full lines so we only need to validate the width */
1266 if (crtc_hdisplay % intel_dp->psr.su_w_granularity)
1269 if (crtc_vdisplay % intel_dp->psr.su_y_granularity)
1272 /* HW tracking is only aligned to 4 lines */
1273 if (!crtc_state->enable_psr2_sel_fetch)
1274 return intel_dp->psr.su_y_granularity == 4;
1277 * adl_p and mtl platforms have 1 line granularity.
1278 * For other platforms with SW tracking we can adjust the y coordinates
1279 * to match sink requirement if multiple of 4.
1281 if (IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14)
1282 y_granularity = intel_dp->psr.su_y_granularity;
1283 else if (intel_dp->psr.su_y_granularity <= 2)
1285 else if ((intel_dp->psr.su_y_granularity % 4) == 0)
1286 y_granularity = intel_dp->psr.su_y_granularity;
1288 if (y_granularity == 0 || crtc_vdisplay % y_granularity)
1291 if (crtc_state->dsc.compression_enable &&
1292 vdsc_cfg->slice_height % y_granularity)
1295 crtc_state->su_y_granularity = y_granularity;
1299 static bool _compute_psr2_sdp_prior_scanline_indication(struct intel_dp *intel_dp,
1300 struct intel_crtc_state *crtc_state)
1302 struct intel_display *display = to_intel_display(intel_dp);
1303 const struct drm_display_mode *adjusted_mode = &crtc_state->uapi.adjusted_mode;
1304 u32 hblank_total, hblank_ns, req_ns;
1306 hblank_total = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start;
1307 hblank_ns = div_u64(1000000ULL * hblank_total, adjusted_mode->crtc_clock);
1309 /* From spec: ((60 / number of lanes) + 11) * 1000 / symbol clock frequency MHz */
1310 req_ns = ((60 / crtc_state->lane_count) + 11) * 1000 / (crtc_state->port_clock / 1000);
1312 if ((hblank_ns - req_ns) > 100)
1315 /* Not supported <13 / Wa_22012279113:adl-p */
1316 if (DISPLAY_VER(display) < 14 || intel_dp->edp_dpcd[0] < DP_EDP_14b)
1319 crtc_state->req_psr2_sdp_prior_scanline = true;
1323 static int intel_psr_entry_setup_frames(struct intel_dp *intel_dp,
1324 const struct drm_display_mode *adjusted_mode)
1326 struct intel_display *display = to_intel_display(intel_dp);
1327 int psr_setup_time = drm_dp_psr_setup_time(intel_dp->psr_dpcd);
1328 int entry_setup_frames = 0;
1330 if (psr_setup_time < 0) {
1331 drm_dbg_kms(display->drm,
1332 "PSR condition failed: Invalid PSR setup time (0x%02x)\n",
1333 intel_dp->psr_dpcd[1]);
1337 if (intel_usecs_to_scanlines(adjusted_mode, psr_setup_time) >
1338 adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vdisplay - 1) {
1339 if (DISPLAY_VER(display) >= 20) {
1340 /* setup entry frames can be up to 3 frames */
1341 entry_setup_frames = 1;
1342 drm_dbg_kms(display->drm,
1343 "PSR setup entry frames %d\n",
1344 entry_setup_frames);
1346 drm_dbg_kms(display->drm,
1347 "PSR condition failed: PSR setup time (%d us) too long\n",
1353 return entry_setup_frames;
1356 static bool wake_lines_fit_into_vblank(struct intel_dp *intel_dp,
1357 const struct intel_crtc_state *crtc_state,
1360 struct intel_display *display = to_intel_display(intel_dp);
1361 int vblank = crtc_state->hw.adjusted_mode.crtc_vblank_end -
1362 crtc_state->hw.adjusted_mode.crtc_vblank_start;
1366 wake_lines = intel_dp->alpm_parameters.aux_less_wake_lines;
1368 wake_lines = DISPLAY_VER(display) < 20 ?
1369 psr2_block_count_lines(intel_dp) :
1370 intel_dp->alpm_parameters.io_wake_lines;
1372 if (crtc_state->req_psr2_sdp_prior_scanline)
1375 /* Vblank >= PSR2_CTL Block Count Number maximum line count */
1376 if (vblank < wake_lines)
1382 static bool alpm_config_valid(struct intel_dp *intel_dp,
1383 const struct intel_crtc_state *crtc_state,
1386 struct intel_display *display = to_intel_display(intel_dp);
1388 if (!intel_alpm_compute_params(intel_dp, crtc_state)) {
1389 drm_dbg_kms(display->drm,
1390 "PSR2/Panel Replay not enabled, Unable to use long enough wake times\n");
1394 if (!wake_lines_fit_into_vblank(intel_dp, crtc_state, aux_less)) {
1395 drm_dbg_kms(display->drm,
1396 "PSR2/Panel Replay not enabled, too short vblank time\n");
1403 static bool intel_psr2_config_valid(struct intel_dp *intel_dp,
1404 struct intel_crtc_state *crtc_state)
1406 struct intel_display *display = to_intel_display(intel_dp);
1407 struct drm_i915_private *dev_priv = to_i915(display->drm);
1408 int crtc_hdisplay = crtc_state->hw.adjusted_mode.crtc_hdisplay;
1409 int crtc_vdisplay = crtc_state->hw.adjusted_mode.crtc_vdisplay;
1410 int psr_max_h = 0, psr_max_v = 0, max_bpp = 0;
1412 if (!intel_dp->psr.sink_psr2_support)
1415 /* JSL and EHL only supports eDP 1.3 */
1416 if (IS_JASPERLAKE(dev_priv) || IS_ELKHARTLAKE(dev_priv)) {
1417 drm_dbg_kms(display->drm, "PSR2 not supported by phy\n");
1421 /* Wa_16011181250 */
1422 if (IS_ROCKETLAKE(dev_priv) || IS_ALDERLAKE_S(dev_priv) ||
1424 drm_dbg_kms(display->drm,
1425 "PSR2 is defeatured for this platform\n");
1429 if (IS_ALDERLAKE_P(dev_priv) && IS_DISPLAY_STEP(display, STEP_A0, STEP_B0)) {
1430 drm_dbg_kms(display->drm,
1431 "PSR2 not completely functional in this stepping\n");
1435 if (!transcoder_has_psr2(display, crtc_state->cpu_transcoder)) {
1436 drm_dbg_kms(display->drm,
1437 "PSR2 not supported in transcoder %s\n",
1438 transcoder_name(crtc_state->cpu_transcoder));
1443 * DSC and PSR2 cannot be enabled simultaneously. If a requested
1444 * resolution requires DSC to be enabled, priority is given to DSC
1447 if (crtc_state->dsc.compression_enable &&
1448 (DISPLAY_VER(display) < 14 && !IS_ALDERLAKE_P(dev_priv))) {
1449 drm_dbg_kms(display->drm,
1450 "PSR2 cannot be enabled since DSC is enabled\n");
1454 if (DISPLAY_VER(display) >= 20) {
1455 psr_max_h = crtc_hdisplay;
1456 psr_max_v = crtc_vdisplay;
1457 max_bpp = crtc_state->pipe_bpp;
1458 } else if (IS_DISPLAY_VER(display, 12, 14)) {
1462 } else if (IS_DISPLAY_VER(display, 10, 11)) {
1466 } else if (DISPLAY_VER(display) == 9) {
1472 if (crtc_state->pipe_bpp > max_bpp) {
1473 drm_dbg_kms(display->drm,
1474 "PSR2 not enabled, pipe bpp %d > max supported %d\n",
1475 crtc_state->pipe_bpp, max_bpp);
1479 /* Wa_16011303918:adl-p */
1480 if (crtc_state->vrr.enable &&
1481 IS_ALDERLAKE_P(dev_priv) && IS_DISPLAY_STEP(display, STEP_A0, STEP_B0)) {
1482 drm_dbg_kms(display->drm,
1483 "PSR2 not enabled, not compatible with HW stepping + VRR\n");
1487 if (!alpm_config_valid(intel_dp, crtc_state, false))
1490 if (!crtc_state->enable_psr2_sel_fetch &&
1491 (crtc_hdisplay > psr_max_h || crtc_vdisplay > psr_max_v)) {
1492 drm_dbg_kms(display->drm,
1493 "PSR2 not enabled, resolution %dx%d > max supported %dx%d\n",
1494 crtc_hdisplay, crtc_vdisplay,
1495 psr_max_h, psr_max_v);
1499 tgl_dc3co_exitline_compute_config(intel_dp, crtc_state);
1504 static bool intel_sel_update_config_valid(struct intel_dp *intel_dp,
1505 struct intel_crtc_state *crtc_state)
1507 struct intel_display *display = to_intel_display(intel_dp);
1509 if (HAS_PSR2_SEL_FETCH(display) &&
1510 !intel_psr2_sel_fetch_config_valid(intel_dp, crtc_state) &&
1511 !HAS_PSR_HW_TRACKING(display)) {
1512 drm_dbg_kms(display->drm,
1513 "Selective update not enabled, selective fetch not valid and no HW tracking available\n");
1517 if (!psr2_global_enabled(intel_dp)) {
1518 drm_dbg_kms(display->drm,
1519 "Selective update disabled by flag\n");
1523 if (!crtc_state->has_panel_replay && !intel_psr2_config_valid(intel_dp, crtc_state))
1526 if (!_compute_psr2_sdp_prior_scanline_indication(intel_dp, crtc_state)) {
1527 drm_dbg_kms(display->drm,
1528 "Selective update not enabled, SDP indication do not fit in hblank\n");
1532 if (crtc_state->has_panel_replay && (DISPLAY_VER(display) < 14 ||
1533 !intel_dp->psr.sink_panel_replay_su_support))
1536 if (crtc_state->crc_enabled) {
1537 drm_dbg_kms(display->drm,
1538 "Selective update not enabled because it would inhibit pipe CRC calculation\n");
1542 if (!psr2_granularity_check(intel_dp, crtc_state)) {
1543 drm_dbg_kms(display->drm,
1544 "Selective update not enabled, SU granularity not compatible\n");
1548 crtc_state->enable_psr2_su_region_et =
1549 psr2_su_region_et_valid(intel_dp, crtc_state->has_panel_replay);
1554 crtc_state->enable_psr2_sel_fetch = false;
1558 static bool _psr_compute_config(struct intel_dp *intel_dp,
1559 struct intel_crtc_state *crtc_state)
1561 struct intel_display *display = to_intel_display(intel_dp);
1562 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
1563 int entry_setup_frames;
1565 if (!CAN_PSR(intel_dp))
1568 entry_setup_frames = intel_psr_entry_setup_frames(intel_dp, adjusted_mode);
1570 if (entry_setup_frames >= 0) {
1571 intel_dp->psr.entry_setup_frames = entry_setup_frames;
1573 drm_dbg_kms(display->drm,
1574 "PSR condition failed: PSR setup timing not met\n");
1582 _panel_replay_compute_config(struct intel_dp *intel_dp,
1583 const struct intel_crtc_state *crtc_state,
1584 const struct drm_connector_state *conn_state)
1586 struct intel_display *display = to_intel_display(intel_dp);
1587 struct intel_connector *connector =
1588 to_intel_connector(conn_state->connector);
1589 struct intel_hdcp *hdcp = &connector->hdcp;
1591 if (!CAN_PANEL_REPLAY(intel_dp))
1594 if (!panel_replay_global_enabled(intel_dp)) {
1595 drm_dbg_kms(display->drm, "Panel Replay disabled by flag\n");
1599 if (!intel_dp_is_edp(intel_dp))
1602 /* Remaining checks are for eDP only */
1604 if (to_intel_crtc(crtc_state->uapi.crtc)->pipe != PIPE_A &&
1605 to_intel_crtc(crtc_state->uapi.crtc)->pipe != PIPE_B)
1608 /* 128b/132b Panel Replay is not supported on eDP */
1609 if (intel_dp_is_uhbr(crtc_state)) {
1610 drm_dbg_kms(display->drm,
1611 "Panel Replay is not supported with 128b/132b\n");
1615 /* HW will not allow Panel Replay on eDP when HDCP enabled */
1616 if (conn_state->content_protection ==
1617 DRM_MODE_CONTENT_PROTECTION_DESIRED ||
1618 (conn_state->content_protection ==
1619 DRM_MODE_CONTENT_PROTECTION_ENABLED && hdcp->value ==
1620 DRM_MODE_CONTENT_PROTECTION_UNDESIRED)) {
1621 drm_dbg_kms(display->drm,
1622 "Panel Replay is not supported with HDCP\n");
1626 if (!alpm_config_valid(intel_dp, crtc_state, true))
1629 if (crtc_state->crc_enabled) {
1630 drm_dbg_kms(display->drm,
1631 "Panel Replay not enabled because it would inhibit pipe CRC calculation\n");
1638 static bool intel_psr_needs_wa_18037818876(struct intel_dp *intel_dp,
1639 struct intel_crtc_state *crtc_state)
1641 struct intel_display *display = to_intel_display(intel_dp);
1643 return (DISPLAY_VER(display) == 20 && intel_dp->psr.entry_setup_frames > 0 &&
1644 !crtc_state->has_sel_update);
1647 void intel_psr_compute_config(struct intel_dp *intel_dp,
1648 struct intel_crtc_state *crtc_state,
1649 struct drm_connector_state *conn_state)
1651 struct intel_display *display = to_intel_display(intel_dp);
1652 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
1654 if (!psr_global_enabled(intel_dp)) {
1655 drm_dbg_kms(display->drm, "PSR disabled by flag\n");
1659 if (intel_dp->psr.sink_not_reliable) {
1660 drm_dbg_kms(display->drm,
1661 "PSR sink implementation is not reliable\n");
1665 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
1666 drm_dbg_kms(display->drm,
1667 "PSR condition failed: Interlaced mode enabled\n");
1672 * FIXME figure out what is wrong with PSR+joiner and
1673 * fix it. Presumably something related to the fact that
1674 * PSR is a transcoder level feature.
1676 if (crtc_state->joiner_pipes) {
1677 drm_dbg_kms(display->drm,
1678 "PSR disabled due to joiner\n");
1683 * Currently PSR/PR doesn't work reliably with VRR enabled.
1685 if (crtc_state->vrr.enable)
1688 crtc_state->has_panel_replay = _panel_replay_compute_config(intel_dp,
1692 crtc_state->has_psr = crtc_state->has_panel_replay ? true :
1693 _psr_compute_config(intel_dp, crtc_state);
1695 if (!crtc_state->has_psr)
1698 crtc_state->has_sel_update = intel_sel_update_config_valid(intel_dp, crtc_state);
1700 /* Wa_18037818876 */
1701 if (intel_psr_needs_wa_18037818876(intel_dp, crtc_state)) {
1702 crtc_state->has_psr = false;
1703 drm_dbg_kms(display->drm,
1704 "PSR disabled to workaround PSR FSM hang issue\n");
1708 void intel_psr_get_config(struct intel_encoder *encoder,
1709 struct intel_crtc_state *pipe_config)
1711 struct intel_display *display = to_intel_display(encoder);
1712 struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
1713 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
1714 struct intel_dp *intel_dp;
1720 intel_dp = &dig_port->dp;
1721 if (!(CAN_PSR(intel_dp) || CAN_PANEL_REPLAY(intel_dp)))
1724 mutex_lock(&intel_dp->psr.lock);
1725 if (!intel_dp->psr.enabled)
1728 if (intel_dp->psr.panel_replay_enabled) {
1729 pipe_config->has_psr = pipe_config->has_panel_replay = true;
1732 * Not possible to read EDP_PSR/PSR2_CTL registers as it is
1733 * enabled/disabled because of frontbuffer tracking and others.
1735 pipe_config->has_psr = true;
1738 pipe_config->has_sel_update = intel_dp->psr.sel_update_enabled;
1739 pipe_config->infoframes.enable |= intel_hdmi_infoframe_enable(DP_SDP_VSC);
1741 if (!intel_dp->psr.sel_update_enabled)
1744 if (HAS_PSR2_SEL_FETCH(display)) {
1745 val = intel_de_read(display,
1746 PSR2_MAN_TRK_CTL(display, cpu_transcoder));
1747 if (val & PSR2_MAN_TRK_CTL_ENABLE)
1748 pipe_config->enable_psr2_sel_fetch = true;
1751 pipe_config->enable_psr2_su_region_et = intel_dp->psr.su_region_et_enabled;
1753 if (DISPLAY_VER(display) >= 12) {
1754 val = intel_de_read(display,
1755 TRANS_EXITLINE(display, cpu_transcoder));
1756 pipe_config->dc3co_exitline = REG_FIELD_GET(EXITLINE_MASK, val);
1759 mutex_unlock(&intel_dp->psr.lock);
1762 static void intel_psr_activate(struct intel_dp *intel_dp)
1764 struct intel_display *display = to_intel_display(intel_dp);
1765 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
1767 drm_WARN_ON(display->drm,
1768 transcoder_has_psr2(display, cpu_transcoder) &&
1769 intel_de_read(display, EDP_PSR2_CTL(display, cpu_transcoder)) & EDP_PSR2_ENABLE);
1771 drm_WARN_ON(display->drm,
1772 intel_de_read(display, psr_ctl_reg(display, cpu_transcoder)) & EDP_PSR_ENABLE);
1774 drm_WARN_ON(display->drm, intel_dp->psr.active);
1776 lockdep_assert_held(&intel_dp->psr.lock);
1778 /* psr1, psr2 and panel-replay are mutually exclusive.*/
1779 if (intel_dp->psr.panel_replay_enabled)
1780 dg2_activate_panel_replay(intel_dp);
1781 else if (intel_dp->psr.sel_update_enabled)
1782 hsw_activate_psr2(intel_dp);
1784 hsw_activate_psr1(intel_dp);
1786 intel_dp->psr.active = true;
1793 static void wm_optimization_wa(struct intel_dp *intel_dp,
1794 const struct intel_crtc_state *crtc_state)
1796 struct intel_display *display = to_intel_display(intel_dp);
1797 enum pipe pipe = intel_dp->psr.pipe;
1798 bool activate = false;
1800 /* Wa_14015648006 */
1801 if (IS_DISPLAY_VER(display, 11, 14) && crtc_state->wm_level_disabled)
1804 /* Wa_16013835468 */
1805 if (DISPLAY_VER(display) == 12 &&
1806 crtc_state->hw.adjusted_mode.crtc_vblank_start !=
1807 crtc_state->hw.adjusted_mode.crtc_vdisplay)
1811 intel_de_rmw(display, GEN8_CHICKEN_DCPR_1,
1812 0, LATENCY_REPORTING_REMOVED(pipe));
1814 intel_de_rmw(display, GEN8_CHICKEN_DCPR_1,
1815 LATENCY_REPORTING_REMOVED(pipe), 0);
1818 static void intel_psr_enable_source(struct intel_dp *intel_dp,
1819 const struct intel_crtc_state *crtc_state)
1821 struct intel_display *display = to_intel_display(intel_dp);
1822 struct drm_i915_private *dev_priv = to_i915(display->drm);
1823 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
1827 * Only HSW and BDW have PSR AUX registers that need to be setup.
1828 * SKL+ use hardcoded values PSR AUX transactions
1830 if (DISPLAY_VER(display) < 9)
1831 hsw_psr_setup_aux(intel_dp);
1834 * Per Spec: Avoid continuous PSR exit by masking MEMUP and HPD also
1835 * mask LPSP to avoid dependency on other drivers that might block
1836 * runtime_pm besides preventing other hw tracking issues now we
1837 * can rely on frontbuffer tracking.
1839 * From bspec prior LunarLake:
1840 * Only PSR_MASK[Mask FBC modify] and PSR_MASK[Mask Hotplug] are used in
1841 * panel replay mode.
1843 * From bspec beyod LunarLake:
1844 * Panel Replay on DP: No bits are applicable
1845 * Panel Replay on eDP: All bits are applicable
1847 if (DISPLAY_VER(display) < 20 || intel_dp_is_edp(intel_dp))
1848 mask = EDP_PSR_DEBUG_MASK_HPD;
1850 if (intel_dp_is_edp(intel_dp)) {
1851 mask |= EDP_PSR_DEBUG_MASK_MEMUP;
1854 * For some unknown reason on HSW non-ULT (or at least on
1855 * Dell Latitude E6540) external displays start to flicker
1856 * when PSR is enabled on the eDP. SR/PC6 residency is much
1857 * higher than should be possible with an external display.
1858 * As a workaround leave LPSP unmasked to prevent PSR entry
1859 * when external displays are active.
1861 if (DISPLAY_VER(display) >= 8 || IS_HASWELL_ULT(dev_priv))
1862 mask |= EDP_PSR_DEBUG_MASK_LPSP;
1864 if (DISPLAY_VER(display) < 20)
1865 mask |= EDP_PSR_DEBUG_MASK_MAX_SLEEP;
1868 * No separate pipe reg write mask on hsw/bdw, so have to unmask all
1869 * registers in order to keep the CURSURFLIVE tricks working :(
1871 if (IS_DISPLAY_VER(display, 9, 10))
1872 mask |= EDP_PSR_DEBUG_MASK_DISP_REG_WRITE;
1874 /* allow PSR with sprite enabled */
1875 if (IS_HASWELL(dev_priv))
1876 mask |= EDP_PSR_DEBUG_MASK_SPRITE_ENABLE;
1879 intel_de_write(display, psr_debug_reg(display, cpu_transcoder), mask);
1881 psr_irq_control(intel_dp);
1884 * TODO: if future platforms supports DC3CO in more than one
1885 * transcoder, EXITLINE will need to be unset when disabling PSR
1887 if (intel_dp->psr.dc3co_exitline)
1888 intel_de_rmw(display,
1889 TRANS_EXITLINE(display, cpu_transcoder),
1891 intel_dp->psr.dc3co_exitline << EXITLINE_SHIFT | EXITLINE_ENABLE);
1893 if (HAS_PSR_HW_TRACKING(display) && HAS_PSR2_SEL_FETCH(display))
1894 intel_de_rmw(display, CHICKEN_PAR1_1, IGNORE_PSR2_HW_TRACKING,
1895 intel_dp->psr.psr2_sel_fetch_enabled ?
1896 IGNORE_PSR2_HW_TRACKING : 0);
1898 if (intel_dp_is_edp(intel_dp))
1899 intel_alpm_configure(intel_dp, crtc_state);
1905 wm_optimization_wa(intel_dp, crtc_state);
1907 if (intel_dp->psr.sel_update_enabled) {
1908 if (DISPLAY_VER(display) == 9)
1909 intel_de_rmw(display, CHICKEN_TRANS(display, cpu_transcoder), 0,
1910 PSR2_VSC_ENABLE_PROG_HEADER |
1911 PSR2_ADD_VERTICAL_LINE_COUNT);
1914 * Wa_16014451276:adlp,mtl[a0,b0]
1915 * All supported adlp panels have 1-based X granularity, this may
1916 * cause issues if non-supported panels are used.
1918 if (!intel_dp->psr.panel_replay_enabled &&
1919 (IS_DISPLAY_VERx100_STEP(display, 1400, STEP_A0, STEP_B0) ||
1920 IS_ALDERLAKE_P(dev_priv)))
1921 intel_de_rmw(display, CHICKEN_TRANS(display, cpu_transcoder),
1922 0, ADLP_1_BASED_X_GRANULARITY);
1924 /* Wa_16012604467:adlp,mtl[a0,b0] */
1925 if (!intel_dp->psr.panel_replay_enabled &&
1926 IS_DISPLAY_VERx100_STEP(display, 1400, STEP_A0, STEP_B0))
1927 intel_de_rmw(display,
1928 MTL_CLKGATE_DIS_TRANS(display, cpu_transcoder),
1930 MTL_CLKGATE_DIS_TRANS_DMASC_GATING_DIS);
1931 else if (IS_ALDERLAKE_P(dev_priv))
1932 intel_de_rmw(display, CLKGATE_DIS_MISC, 0,
1933 CLKGATE_DIS_MISC_DMASC_GATING_DIS);
1937 static bool psr_interrupt_error_check(struct intel_dp *intel_dp)
1939 struct intel_display *display = to_intel_display(intel_dp);
1940 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
1943 if (intel_dp->psr.panel_replay_enabled)
1947 * If a PSR error happened and the driver is reloaded, the EDP_PSR_IIR
1948 * will still keep the error set even after the reset done in the
1949 * irq_preinstall and irq_uninstall hooks.
1950 * And enabling in this situation cause the screen to freeze in the
1951 * first time that PSR HW tries to activate so lets keep PSR disabled
1952 * to avoid any rendering problems.
1954 val = intel_de_read(display, psr_iir_reg(display, cpu_transcoder));
1955 val &= psr_irq_psr_error_bit_get(intel_dp);
1957 intel_dp->psr.sink_not_reliable = true;
1958 drm_dbg_kms(display->drm,
1959 "PSR interruption error set, not enabling PSR\n");
1967 static void intel_psr_enable_locked(struct intel_dp *intel_dp,
1968 const struct intel_crtc_state *crtc_state)
1970 struct intel_display *display = to_intel_display(intel_dp);
1971 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
1974 drm_WARN_ON(display->drm, intel_dp->psr.enabled);
1976 intel_dp->psr.sel_update_enabled = crtc_state->has_sel_update;
1977 intel_dp->psr.panel_replay_enabled = crtc_state->has_panel_replay;
1978 intel_dp->psr.busy_frontbuffer_bits = 0;
1979 intel_dp->psr.pipe = to_intel_crtc(crtc_state->uapi.crtc)->pipe;
1980 intel_dp->psr.transcoder = crtc_state->cpu_transcoder;
1981 /* DC5/DC6 requires at least 6 idle frames */
1982 val = usecs_to_jiffies(intel_get_frame_time_us(crtc_state) * 6);
1983 intel_dp->psr.dc3co_exit_delay = val;
1984 intel_dp->psr.dc3co_exitline = crtc_state->dc3co_exitline;
1985 intel_dp->psr.psr2_sel_fetch_enabled = crtc_state->enable_psr2_sel_fetch;
1986 intel_dp->psr.su_region_et_enabled = crtc_state->enable_psr2_su_region_et;
1987 intel_dp->psr.psr2_sel_fetch_cff_enabled = false;
1988 intel_dp->psr.req_psr2_sdp_prior_scanline =
1989 crtc_state->req_psr2_sdp_prior_scanline;
1991 if (!psr_interrupt_error_check(intel_dp))
1994 if (intel_dp->psr.panel_replay_enabled) {
1995 drm_dbg_kms(display->drm, "Enabling Panel Replay\n");
1997 drm_dbg_kms(display->drm, "Enabling PSR%s\n",
1998 intel_dp->psr.sel_update_enabled ? "2" : "1");
2001 * Panel replay has to be enabled before link training: doing it
2002 * only for PSR here.
2004 intel_psr_enable_sink(intel_dp, crtc_state);
2007 if (intel_dp_is_edp(intel_dp))
2008 intel_snps_phy_update_psr_power_state(&dig_port->base, true);
2010 intel_psr_enable_source(intel_dp, crtc_state);
2011 intel_dp->psr.enabled = true;
2012 intel_dp->psr.paused = false;
2015 * Link_ok is sticky and set here on PSR enable. We can assume link
2016 * training is complete as we never continue to PSR enable with
2017 * untrained link. Link_ok is kept as set until first short pulse
2018 * interrupt. This is targeted to workaround panels stating bad link
2019 * after PSR is enabled.
2021 intel_dp->psr.link_ok = true;
2023 intel_psr_activate(intel_dp);
2026 static void intel_psr_exit(struct intel_dp *intel_dp)
2028 struct intel_display *display = to_intel_display(intel_dp);
2029 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
2032 if (!intel_dp->psr.active) {
2033 if (transcoder_has_psr2(display, cpu_transcoder)) {
2034 val = intel_de_read(display,
2035 EDP_PSR2_CTL(display, cpu_transcoder));
2036 drm_WARN_ON(display->drm, val & EDP_PSR2_ENABLE);
2039 val = intel_de_read(display,
2040 psr_ctl_reg(display, cpu_transcoder));
2041 drm_WARN_ON(display->drm, val & EDP_PSR_ENABLE);
2046 if (intel_dp->psr.panel_replay_enabled) {
2047 intel_de_rmw(display, TRANS_DP2_CTL(intel_dp->psr.transcoder),
2048 TRANS_DP2_PANEL_REPLAY_ENABLE, 0);
2049 } else if (intel_dp->psr.sel_update_enabled) {
2050 tgl_disallow_dc3co_on_psr2_exit(intel_dp);
2052 val = intel_de_rmw(display,
2053 EDP_PSR2_CTL(display, cpu_transcoder),
2054 EDP_PSR2_ENABLE, 0);
2056 drm_WARN_ON(display->drm, !(val & EDP_PSR2_ENABLE));
2058 val = intel_de_rmw(display,
2059 psr_ctl_reg(display, cpu_transcoder),
2062 drm_WARN_ON(display->drm, !(val & EDP_PSR_ENABLE));
2064 intel_dp->psr.active = false;
2067 static void intel_psr_wait_exit_locked(struct intel_dp *intel_dp)
2069 struct intel_display *display = to_intel_display(intel_dp);
2070 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
2071 i915_reg_t psr_status;
2072 u32 psr_status_mask;
2074 if (intel_dp_is_edp(intel_dp) && (intel_dp->psr.sel_update_enabled ||
2075 intel_dp->psr.panel_replay_enabled)) {
2076 psr_status = EDP_PSR2_STATUS(display, cpu_transcoder);
2077 psr_status_mask = EDP_PSR2_STATUS_STATE_MASK;
2079 psr_status = psr_status_reg(display, cpu_transcoder);
2080 psr_status_mask = EDP_PSR_STATUS_STATE_MASK;
2083 /* Wait till PSR is idle */
2084 if (intel_de_wait_for_clear(display, psr_status,
2085 psr_status_mask, 2000))
2086 drm_err(display->drm, "Timed out waiting PSR idle state\n");
2089 static void intel_psr_disable_locked(struct intel_dp *intel_dp)
2091 struct intel_display *display = to_intel_display(intel_dp);
2092 struct drm_i915_private *dev_priv = to_i915(display->drm);
2093 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
2095 lockdep_assert_held(&intel_dp->psr.lock);
2097 if (!intel_dp->psr.enabled)
2100 if (intel_dp->psr.panel_replay_enabled)
2101 drm_dbg_kms(display->drm, "Disabling Panel Replay\n");
2103 drm_dbg_kms(display->drm, "Disabling PSR%s\n",
2104 intel_dp->psr.sel_update_enabled ? "2" : "1");
2106 intel_psr_exit(intel_dp);
2107 intel_psr_wait_exit_locked(intel_dp);
2113 if (DISPLAY_VER(display) >= 11)
2114 intel_de_rmw(display, GEN8_CHICKEN_DCPR_1,
2115 LATENCY_REPORTING_REMOVED(intel_dp->psr.pipe), 0);
2117 if (intel_dp->psr.sel_update_enabled) {
2118 /* Wa_16012604467:adlp,mtl[a0,b0] */
2119 if (!intel_dp->psr.panel_replay_enabled &&
2120 IS_DISPLAY_VERx100_STEP(display, 1400, STEP_A0, STEP_B0))
2121 intel_de_rmw(display,
2122 MTL_CLKGATE_DIS_TRANS(display, cpu_transcoder),
2123 MTL_CLKGATE_DIS_TRANS_DMASC_GATING_DIS, 0);
2124 else if (IS_ALDERLAKE_P(dev_priv))
2125 intel_de_rmw(display, CLKGATE_DIS_MISC,
2126 CLKGATE_DIS_MISC_DMASC_GATING_DIS, 0);
2129 if (intel_dp_is_edp(intel_dp))
2130 intel_snps_phy_update_psr_power_state(&dp_to_dig_port(intel_dp)->base, false);
2132 /* Panel Replay on eDP is always using ALPM aux less. */
2133 if (intel_dp->psr.panel_replay_enabled && intel_dp_is_edp(intel_dp)) {
2134 intel_de_rmw(display, ALPM_CTL(display, cpu_transcoder),
2135 ALPM_CTL_ALPM_ENABLE |
2136 ALPM_CTL_ALPM_AUX_LESS_ENABLE, 0);
2138 intel_de_rmw(display,
2139 PORT_ALPM_CTL(cpu_transcoder),
2140 PORT_ALPM_CTL_ALPM_AUX_LESS_ENABLE, 0);
2143 /* Disable PSR on Sink */
2144 if (!intel_dp->psr.panel_replay_enabled) {
2145 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG, 0);
2147 if (intel_dp->psr.sel_update_enabled)
2148 drm_dp_dpcd_writeb(&intel_dp->aux,
2149 DP_RECEIVER_ALPM_CONFIG, 0);
2152 intel_dp->psr.enabled = false;
2153 intel_dp->psr.panel_replay_enabled = false;
2154 intel_dp->psr.sel_update_enabled = false;
2155 intel_dp->psr.psr2_sel_fetch_enabled = false;
2156 intel_dp->psr.su_region_et_enabled = false;
2157 intel_dp->psr.psr2_sel_fetch_cff_enabled = false;
2161 * intel_psr_disable - Disable PSR
2162 * @intel_dp: Intel DP
2163 * @old_crtc_state: old CRTC state
2165 * This function needs to be called before disabling pipe.
2167 void intel_psr_disable(struct intel_dp *intel_dp,
2168 const struct intel_crtc_state *old_crtc_state)
2170 struct intel_display *display = to_intel_display(intel_dp);
2172 if (!old_crtc_state->has_psr)
2175 if (drm_WARN_ON(display->drm, !CAN_PSR(intel_dp)))
2178 mutex_lock(&intel_dp->psr.lock);
2180 intel_psr_disable_locked(intel_dp);
2182 intel_dp->psr.link_ok = false;
2184 mutex_unlock(&intel_dp->psr.lock);
2185 cancel_work_sync(&intel_dp->psr.work);
2186 cancel_delayed_work_sync(&intel_dp->psr.dc3co_work);
2190 * intel_psr_pause - Pause PSR
2191 * @intel_dp: Intel DP
2193 * This function need to be called after enabling psr.
2195 void intel_psr_pause(struct intel_dp *intel_dp)
2197 struct intel_display *display = to_intel_display(intel_dp);
2198 struct intel_psr *psr = &intel_dp->psr;
2200 if (!CAN_PSR(intel_dp) && !CAN_PANEL_REPLAY(intel_dp))
2203 mutex_lock(&psr->lock);
2205 if (!psr->enabled) {
2206 mutex_unlock(&psr->lock);
2210 /* If we ever hit this, we will need to add refcount to pause/resume */
2211 drm_WARN_ON(display->drm, psr->paused);
2213 intel_psr_exit(intel_dp);
2214 intel_psr_wait_exit_locked(intel_dp);
2217 mutex_unlock(&psr->lock);
2219 cancel_work_sync(&psr->work);
2220 cancel_delayed_work_sync(&psr->dc3co_work);
2224 * intel_psr_resume - Resume PSR
2225 * @intel_dp: Intel DP
2227 * This function need to be called after pausing psr.
2229 void intel_psr_resume(struct intel_dp *intel_dp)
2231 struct intel_psr *psr = &intel_dp->psr;
2233 if (!CAN_PSR(intel_dp) && !CAN_PANEL_REPLAY(intel_dp))
2236 mutex_lock(&psr->lock);
2241 psr->paused = false;
2242 intel_psr_activate(intel_dp);
2245 mutex_unlock(&psr->lock);
2249 * intel_psr_needs_block_dc_vblank - Check if block dc entry is needed
2250 * @crtc_state: CRTC status
2252 * We need to block DC6 entry in case of Panel Replay as enabling VBI doesn't
2253 * prevent it in case of Panel Replay. Panel Replay switches main link off on
2254 * DC entry. This means vblank interrupts are not fired and is a problem if
2255 * user-space is polling for vblank events.
2257 bool intel_psr_needs_block_dc_vblank(const struct intel_crtc_state *crtc_state)
2259 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2260 struct intel_encoder *encoder;
2262 for_each_encoder_on_crtc(crtc->base.dev, &crtc->base, encoder) {
2263 struct intel_dp *intel_dp;
2265 if (!intel_encoder_is_dp(encoder))
2268 intel_dp = enc_to_intel_dp(encoder);
2270 if (intel_dp_is_edp(intel_dp) &&
2271 CAN_PANEL_REPLAY(intel_dp))
2278 static u32 man_trk_ctl_enable_bit_get(struct intel_display *display)
2280 struct drm_i915_private *dev_priv = to_i915(display->drm);
2282 return IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14 ? 0 :
2283 PSR2_MAN_TRK_CTL_ENABLE;
2286 static u32 man_trk_ctl_single_full_frame_bit_get(struct intel_display *display)
2288 struct drm_i915_private *dev_priv = to_i915(display->drm);
2290 return IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14 ?
2291 ADLP_PSR2_MAN_TRK_CTL_SF_SINGLE_FULL_FRAME :
2292 PSR2_MAN_TRK_CTL_SF_SINGLE_FULL_FRAME;
2295 static u32 man_trk_ctl_partial_frame_bit_get(struct intel_display *display)
2297 struct drm_i915_private *dev_priv = to_i915(display->drm);
2299 return IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14 ?
2300 ADLP_PSR2_MAN_TRK_CTL_SF_PARTIAL_FRAME_UPDATE :
2301 PSR2_MAN_TRK_CTL_SF_PARTIAL_FRAME_UPDATE;
2304 static u32 man_trk_ctl_continuos_full_frame(struct intel_display *display)
2306 struct drm_i915_private *dev_priv = to_i915(display->drm);
2308 return IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14 ?
2309 ADLP_PSR2_MAN_TRK_CTL_SF_CONTINUOS_FULL_FRAME :
2310 PSR2_MAN_TRK_CTL_SF_CONTINUOS_FULL_FRAME;
2313 static void psr_force_hw_tracking_exit(struct intel_dp *intel_dp)
2315 struct intel_display *display = to_intel_display(intel_dp);
2316 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
2318 if (intel_dp->psr.psr2_sel_fetch_enabled)
2319 intel_de_write(display,
2320 PSR2_MAN_TRK_CTL(display, cpu_transcoder),
2321 man_trk_ctl_enable_bit_get(display) |
2322 man_trk_ctl_partial_frame_bit_get(display) |
2323 man_trk_ctl_single_full_frame_bit_get(display) |
2324 man_trk_ctl_continuos_full_frame(display));
2327 * Display WA #0884: skl+
2328 * This documented WA for bxt can be safely applied
2329 * broadly so we can force HW tracking to exit PSR
2330 * instead of disabling and re-enabling.
2331 * Workaround tells us to write 0 to CUR_SURFLIVE_A,
2332 * but it makes more sense write to the current active
2335 * This workaround do not exist for platforms with display 10 or newer
2336 * but testing proved that it works for up display 13, for newer
2337 * than that testing will be needed.
2339 intel_de_write(display, CURSURFLIVE(display, intel_dp->psr.pipe), 0);
2342 void intel_psr2_program_trans_man_trk_ctl(const struct intel_crtc_state *crtc_state)
2344 struct intel_display *display = to_intel_display(crtc_state);
2345 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2346 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
2347 struct intel_encoder *encoder;
2349 if (!crtc_state->enable_psr2_sel_fetch)
2352 for_each_intel_encoder_mask_with_psr(display->drm, encoder,
2353 crtc_state->uapi.encoder_mask) {
2354 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2356 lockdep_assert_held(&intel_dp->psr.lock);
2357 if (intel_dp->psr.psr2_sel_fetch_cff_enabled)
2362 intel_de_write(display, PSR2_MAN_TRK_CTL(display, cpu_transcoder),
2363 crtc_state->psr2_man_track_ctl);
2365 if (!crtc_state->enable_psr2_su_region_et)
2368 intel_de_write(display, PIPE_SRCSZ_ERLY_TPT(crtc->pipe),
2369 crtc_state->pipe_srcsz_early_tpt);
2372 static void psr2_man_trk_ctl_calc(struct intel_crtc_state *crtc_state,
2375 struct intel_display *display = to_intel_display(crtc_state);
2376 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
2377 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
2378 u32 val = man_trk_ctl_enable_bit_get(display);
2380 /* SF partial frame enable has to be set even on full update */
2381 val |= man_trk_ctl_partial_frame_bit_get(display);
2384 val |= man_trk_ctl_single_full_frame_bit_get(display);
2385 val |= man_trk_ctl_continuos_full_frame(display);
2389 if (crtc_state->psr2_su_area.y1 == -1)
2392 if (IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14) {
2393 val |= ADLP_PSR2_MAN_TRK_CTL_SU_REGION_START_ADDR(crtc_state->psr2_su_area.y1);
2394 val |= ADLP_PSR2_MAN_TRK_CTL_SU_REGION_END_ADDR(crtc_state->psr2_su_area.y2 - 1);
2396 drm_WARN_ON(crtc_state->uapi.crtc->dev,
2397 crtc_state->psr2_su_area.y1 % 4 ||
2398 crtc_state->psr2_su_area.y2 % 4);
2400 val |= PSR2_MAN_TRK_CTL_SU_REGION_START_ADDR(
2401 crtc_state->psr2_su_area.y1 / 4 + 1);
2402 val |= PSR2_MAN_TRK_CTL_SU_REGION_END_ADDR(
2403 crtc_state->psr2_su_area.y2 / 4 + 1);
2406 crtc_state->psr2_man_track_ctl = val;
2409 static u32 psr2_pipe_srcsz_early_tpt_calc(struct intel_crtc_state *crtc_state,
2414 if (!crtc_state->enable_psr2_su_region_et || full_update)
2417 width = drm_rect_width(&crtc_state->psr2_su_area);
2418 height = drm_rect_height(&crtc_state->psr2_su_area);
2420 return PIPESRC_WIDTH(width - 1) | PIPESRC_HEIGHT(height - 1);
2423 static void clip_area_update(struct drm_rect *overlap_damage_area,
2424 struct drm_rect *damage_area,
2425 struct drm_rect *pipe_src)
2427 if (!drm_rect_intersect(damage_area, pipe_src))
2430 if (overlap_damage_area->y1 == -1) {
2431 overlap_damage_area->y1 = damage_area->y1;
2432 overlap_damage_area->y2 = damage_area->y2;
2436 if (damage_area->y1 < overlap_damage_area->y1)
2437 overlap_damage_area->y1 = damage_area->y1;
2439 if (damage_area->y2 > overlap_damage_area->y2)
2440 overlap_damage_area->y2 = damage_area->y2;
2443 static void intel_psr2_sel_fetch_pipe_alignment(struct intel_crtc_state *crtc_state)
2445 struct intel_display *display = to_intel_display(crtc_state);
2446 struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev);
2447 const struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config;
2450 /* ADLP aligns the SU region to vdsc slice height in case dsc is enabled */
2451 if (crtc_state->dsc.compression_enable &&
2452 (IS_ALDERLAKE_P(dev_priv) || DISPLAY_VER(display) >= 14))
2453 y_alignment = vdsc_cfg->slice_height;
2455 y_alignment = crtc_state->su_y_granularity;
2457 crtc_state->psr2_su_area.y1 -= crtc_state->psr2_su_area.y1 % y_alignment;
2458 if (crtc_state->psr2_su_area.y2 % y_alignment)
2459 crtc_state->psr2_su_area.y2 = ((crtc_state->psr2_su_area.y2 /
2460 y_alignment) + 1) * y_alignment;
2464 * When early transport is in use we need to extend SU area to cover
2465 * cursor fully when cursor is in SU area.
2468 intel_psr2_sel_fetch_et_alignment(struct intel_atomic_state *state,
2469 struct intel_crtc *crtc,
2470 bool *cursor_in_su_area)
2472 struct intel_crtc_state *crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
2473 struct intel_plane_state *new_plane_state;
2474 struct intel_plane *plane;
2477 if (!crtc_state->enable_psr2_su_region_et)
2480 for_each_new_intel_plane_in_state(state, plane, new_plane_state, i) {
2481 struct drm_rect inter;
2483 if (new_plane_state->uapi.crtc != crtc_state->uapi.crtc)
2486 if (plane->id != PLANE_CURSOR)
2489 if (!new_plane_state->uapi.visible)
2492 inter = crtc_state->psr2_su_area;
2493 if (!drm_rect_intersect(&inter, &new_plane_state->uapi.dst))
2496 clip_area_update(&crtc_state->psr2_su_area, &new_plane_state->uapi.dst,
2497 &crtc_state->pipe_src);
2498 *cursor_in_su_area = true;
2503 * TODO: Not clear how to handle planes with negative position,
2504 * also planes are not updated if they have a negative X
2505 * position so for now doing a full update in this cases
2507 * Plane scaling and rotation is not supported by selective fetch and both
2508 * properties can change without a modeset, so need to be check at every
2511 static bool psr2_sel_fetch_plane_state_supported(const struct intel_plane_state *plane_state)
2513 if (plane_state->uapi.dst.y1 < 0 ||
2514 plane_state->uapi.dst.x1 < 0 ||
2515 plane_state->scaler_id >= 0 ||
2516 plane_state->uapi.rotation != DRM_MODE_ROTATE_0)
2523 * Check for pipe properties that is not supported by selective fetch.
2525 * TODO: pipe scaling causes a modeset but skl_update_scaler_crtc() is executed
2526 * after intel_psr_compute_config(), so for now keeping PSR2 selective fetch
2527 * enabled and going to the full update path.
2529 static bool psr2_sel_fetch_pipe_state_supported(const struct intel_crtc_state *crtc_state)
2531 if (crtc_state->scaler_state.scaler_id >= 0)
2537 /* Wa 14019834836 */
2538 static void intel_psr_apply_pr_link_on_su_wa(struct intel_crtc_state *crtc_state)
2540 struct intel_display *display = to_intel_display(crtc_state);
2541 struct intel_encoder *encoder;
2544 if (crtc_state->psr2_su_area.y1 != 0 ||
2545 crtc_state->psr2_su_area.y2 != 0)
2548 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
2549 hactive_limit = intel_dp_is_uhbr(crtc_state) ? 1230 : 546;
2551 hactive_limit = intel_dp_is_uhbr(crtc_state) ? 615 : 273;
2553 if (crtc_state->hw.adjusted_mode.hdisplay < hactive_limit)
2556 for_each_intel_encoder_mask_with_psr(display->drm, encoder,
2557 crtc_state->uapi.encoder_mask) {
2558 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2560 if (!intel_dp_is_edp(intel_dp) &&
2561 intel_dp->psr.panel_replay_enabled &&
2562 intel_dp->psr.sel_update_enabled) {
2563 crtc_state->psr2_su_area.y2++;
2570 intel_psr_apply_su_area_workarounds(struct intel_crtc_state *crtc_state)
2572 struct intel_display *display = to_intel_display(crtc_state);
2573 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
2575 /* Wa_14014971492 */
2576 if (!crtc_state->has_panel_replay &&
2577 ((IS_DISPLAY_VERx100_STEP(display, 1400, STEP_A0, STEP_B0) ||
2578 IS_ALDERLAKE_P(i915) || IS_TIGERLAKE(i915))) &&
2579 crtc_state->splitter.enable)
2580 crtc_state->psr2_su_area.y1 = 0;
2582 /* Wa 14019834836 */
2583 if (DISPLAY_VER(display) == 30)
2584 intel_psr_apply_pr_link_on_su_wa(crtc_state);
2587 int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,
2588 struct intel_crtc *crtc)
2590 struct intel_display *display = to_intel_display(state);
2591 struct intel_crtc_state *crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
2592 struct intel_plane_state *new_plane_state, *old_plane_state;
2593 struct intel_plane *plane;
2594 bool full_update = false, cursor_in_su_area = false;
2597 if (!crtc_state->enable_psr2_sel_fetch)
2600 if (!psr2_sel_fetch_pipe_state_supported(crtc_state)) {
2602 goto skip_sel_fetch_set_loop;
2605 crtc_state->psr2_su_area.x1 = 0;
2606 crtc_state->psr2_su_area.y1 = -1;
2607 crtc_state->psr2_su_area.x2 = drm_rect_width(&crtc_state->pipe_src);
2608 crtc_state->psr2_su_area.y2 = -1;
2611 * Calculate minimal selective fetch area of each plane and calculate
2612 * the pipe damaged area.
2613 * In the next loop the plane selective fetch area will actually be set
2614 * using whole pipe damaged area.
2616 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
2617 new_plane_state, i) {
2618 struct drm_rect src, damaged_area = { .x1 = 0, .y1 = -1,
2621 if (new_plane_state->uapi.crtc != crtc_state->uapi.crtc)
2624 if (!new_plane_state->uapi.visible &&
2625 !old_plane_state->uapi.visible)
2628 if (!psr2_sel_fetch_plane_state_supported(new_plane_state)) {
2634 * If visibility or plane moved, mark the whole plane area as
2635 * damaged as it needs to be complete redraw in the new and old
2638 if (new_plane_state->uapi.visible != old_plane_state->uapi.visible ||
2639 !drm_rect_equals(&new_plane_state->uapi.dst,
2640 &old_plane_state->uapi.dst)) {
2641 if (old_plane_state->uapi.visible) {
2642 damaged_area.y1 = old_plane_state->uapi.dst.y1;
2643 damaged_area.y2 = old_plane_state->uapi.dst.y2;
2644 clip_area_update(&crtc_state->psr2_su_area, &damaged_area,
2645 &crtc_state->pipe_src);
2648 if (new_plane_state->uapi.visible) {
2649 damaged_area.y1 = new_plane_state->uapi.dst.y1;
2650 damaged_area.y2 = new_plane_state->uapi.dst.y2;
2651 clip_area_update(&crtc_state->psr2_su_area, &damaged_area,
2652 &crtc_state->pipe_src);
2655 } else if (new_plane_state->uapi.alpha != old_plane_state->uapi.alpha) {
2656 /* If alpha changed mark the whole plane area as damaged */
2657 damaged_area.y1 = new_plane_state->uapi.dst.y1;
2658 damaged_area.y2 = new_plane_state->uapi.dst.y2;
2659 clip_area_update(&crtc_state->psr2_su_area, &damaged_area,
2660 &crtc_state->pipe_src);
2664 src = drm_plane_state_src(&new_plane_state->uapi);
2665 drm_rect_fp_to_int(&src, &src);
2667 if (!drm_atomic_helper_damage_merged(&old_plane_state->uapi,
2668 &new_plane_state->uapi, &damaged_area))
2671 damaged_area.y1 += new_plane_state->uapi.dst.y1 - src.y1;
2672 damaged_area.y2 += new_plane_state->uapi.dst.y1 - src.y1;
2673 damaged_area.x1 += new_plane_state->uapi.dst.x1 - src.x1;
2674 damaged_area.x2 += new_plane_state->uapi.dst.x1 - src.x1;
2676 clip_area_update(&crtc_state->psr2_su_area, &damaged_area, &crtc_state->pipe_src);
2680 * TODO: For now we are just using full update in case
2681 * selective fetch area calculation fails. To optimize this we
2682 * should identify cases where this happens and fix the area
2683 * calculation for those.
2685 if (crtc_state->psr2_su_area.y1 == -1) {
2686 drm_info_once(display->drm,
2687 "Selective fetch area calculation failed in pipe %c\n",
2688 pipe_name(crtc->pipe));
2693 goto skip_sel_fetch_set_loop;
2695 intel_psr_apply_su_area_workarounds(crtc_state);
2697 ret = drm_atomic_add_affected_planes(&state->base, &crtc->base);
2702 * Adjust su area to cover cursor fully as necessary (early
2703 * transport). This needs to be done after
2704 * drm_atomic_add_affected_planes to ensure visible cursor is added into
2705 * affected planes even when cursor is not updated by itself.
2707 intel_psr2_sel_fetch_et_alignment(state, crtc, &cursor_in_su_area);
2709 intel_psr2_sel_fetch_pipe_alignment(crtc_state);
2712 * Now that we have the pipe damaged area check if it intersect with
2713 * every plane, if it does set the plane selective fetch area.
2715 for_each_oldnew_intel_plane_in_state(state, plane, old_plane_state,
2716 new_plane_state, i) {
2717 struct drm_rect *sel_fetch_area, inter;
2718 struct intel_plane *linked = new_plane_state->planar_linked_plane;
2720 if (new_plane_state->uapi.crtc != crtc_state->uapi.crtc ||
2721 !new_plane_state->uapi.visible)
2724 inter = crtc_state->psr2_su_area;
2725 sel_fetch_area = &new_plane_state->psr2_sel_fetch_area;
2726 if (!drm_rect_intersect(&inter, &new_plane_state->uapi.dst)) {
2727 sel_fetch_area->y1 = -1;
2728 sel_fetch_area->y2 = -1;
2730 * if plane sel fetch was previously enabled ->
2733 if (drm_rect_height(&old_plane_state->psr2_sel_fetch_area) > 0)
2734 crtc_state->update_planes |= BIT(plane->id);
2739 if (!psr2_sel_fetch_plane_state_supported(new_plane_state)) {
2744 sel_fetch_area = &new_plane_state->psr2_sel_fetch_area;
2745 sel_fetch_area->y1 = inter.y1 - new_plane_state->uapi.dst.y1;
2746 sel_fetch_area->y2 = inter.y2 - new_plane_state->uapi.dst.y1;
2747 crtc_state->update_planes |= BIT(plane->id);
2750 * Sel_fetch_area is calculated for UV plane. Use
2751 * same area for Y plane as well.
2754 struct intel_plane_state *linked_new_plane_state;
2755 struct drm_rect *linked_sel_fetch_area;
2757 linked_new_plane_state = intel_atomic_get_plane_state(state, linked);
2758 if (IS_ERR(linked_new_plane_state))
2759 return PTR_ERR(linked_new_plane_state);
2761 linked_sel_fetch_area = &linked_new_plane_state->psr2_sel_fetch_area;
2762 linked_sel_fetch_area->y1 = sel_fetch_area->y1;
2763 linked_sel_fetch_area->y2 = sel_fetch_area->y2;
2764 crtc_state->update_planes |= BIT(linked->id);
2768 skip_sel_fetch_set_loop:
2769 psr2_man_trk_ctl_calc(crtc_state, full_update);
2770 crtc_state->pipe_srcsz_early_tpt =
2771 psr2_pipe_srcsz_early_tpt_calc(crtc_state, full_update);
2775 void intel_psr_pre_plane_update(struct intel_atomic_state *state,
2776 struct intel_crtc *crtc)
2778 struct intel_display *display = to_intel_display(state);
2779 struct drm_i915_private *i915 = to_i915(state->base.dev);
2780 const struct intel_crtc_state *old_crtc_state =
2781 intel_atomic_get_old_crtc_state(state, crtc);
2782 const struct intel_crtc_state *new_crtc_state =
2783 intel_atomic_get_new_crtc_state(state, crtc);
2784 struct intel_encoder *encoder;
2786 if (!HAS_PSR(display))
2789 for_each_intel_encoder_mask_with_psr(state->base.dev, encoder,
2790 old_crtc_state->uapi.encoder_mask) {
2791 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2792 struct intel_psr *psr = &intel_dp->psr;
2793 bool needs_to_disable = false;
2795 mutex_lock(&psr->lock);
2798 * Reasons to disable:
2799 * - PSR disabled in new state
2800 * - All planes will go inactive
2801 * - Changing between PSR versions
2802 * - Region Early Transport changing
2803 * - Display WA #1136: skl, bxt
2805 needs_to_disable |= intel_crtc_needs_modeset(new_crtc_state);
2806 needs_to_disable |= !new_crtc_state->has_psr;
2807 needs_to_disable |= !new_crtc_state->active_planes;
2808 needs_to_disable |= new_crtc_state->has_sel_update != psr->sel_update_enabled;
2809 needs_to_disable |= new_crtc_state->enable_psr2_su_region_et !=
2810 psr->su_region_et_enabled;
2811 needs_to_disable |= DISPLAY_VER(i915) < 11 &&
2812 new_crtc_state->wm_level_disabled;
2814 if (psr->enabled && needs_to_disable)
2815 intel_psr_disable_locked(intel_dp);
2816 else if (psr->enabled && new_crtc_state->wm_level_disabled)
2817 /* Wa_14015648006 */
2818 wm_optimization_wa(intel_dp, new_crtc_state);
2820 mutex_unlock(&psr->lock);
2824 void intel_psr_post_plane_update(struct intel_atomic_state *state,
2825 struct intel_crtc *crtc)
2827 struct intel_display *display = to_intel_display(state);
2828 const struct intel_crtc_state *crtc_state =
2829 intel_atomic_get_new_crtc_state(state, crtc);
2830 struct intel_encoder *encoder;
2832 if (!crtc_state->has_psr)
2835 for_each_intel_encoder_mask_with_psr(state->base.dev, encoder,
2836 crtc_state->uapi.encoder_mask) {
2837 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2838 struct intel_psr *psr = &intel_dp->psr;
2839 bool keep_disabled = false;
2841 mutex_lock(&psr->lock);
2843 drm_WARN_ON(display->drm,
2844 psr->enabled && !crtc_state->active_planes);
2846 keep_disabled |= psr->sink_not_reliable;
2847 keep_disabled |= !crtc_state->active_planes;
2849 /* Display WA #1136: skl, bxt */
2850 keep_disabled |= DISPLAY_VER(display) < 11 &&
2851 crtc_state->wm_level_disabled;
2853 if (!psr->enabled && !keep_disabled)
2854 intel_psr_enable_locked(intel_dp, crtc_state);
2855 else if (psr->enabled && !crtc_state->wm_level_disabled)
2856 /* Wa_14015648006 */
2857 wm_optimization_wa(intel_dp, crtc_state);
2859 /* Force a PSR exit when enabling CRC to avoid CRC timeouts */
2860 if (crtc_state->crc_enabled && psr->enabled)
2861 psr_force_hw_tracking_exit(intel_dp);
2864 * Clear possible busy bits in case we have
2865 * invalidate -> flip -> flush sequence.
2867 intel_dp->psr.busy_frontbuffer_bits = 0;
2869 mutex_unlock(&psr->lock);
2873 static int _psr2_ready_for_pipe_update_locked(struct intel_dp *intel_dp)
2875 struct intel_display *display = to_intel_display(intel_dp);
2876 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
2879 * Any state lower than EDP_PSR2_STATUS_STATE_DEEP_SLEEP is enough.
2880 * As all higher states has bit 4 of PSR2 state set we can just wait for
2881 * EDP_PSR2_STATUS_STATE_DEEP_SLEEP to be cleared.
2883 return intel_de_wait_for_clear(display,
2884 EDP_PSR2_STATUS(display, cpu_transcoder),
2885 EDP_PSR2_STATUS_STATE_DEEP_SLEEP, 50);
2888 static int _psr1_ready_for_pipe_update_locked(struct intel_dp *intel_dp)
2890 struct intel_display *display = to_intel_display(intel_dp);
2891 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
2894 * From bspec: Panel Self Refresh (BDW+)
2895 * Max. time for PSR to idle = Inverse of the refresh rate + 6 ms of
2896 * exit training time + 1.5 ms of aux channel handshake. 50 ms is
2897 * defensive enough to cover everything.
2899 return intel_de_wait_for_clear(display,
2900 psr_status_reg(display, cpu_transcoder),
2901 EDP_PSR_STATUS_STATE_MASK, 50);
2905 * intel_psr_wait_for_idle_locked - wait for PSR be ready for a pipe update
2906 * @new_crtc_state: new CRTC state
2908 * This function is expected to be called from pipe_update_start() where it is
2909 * not expected to race with PSR enable or disable.
2911 void intel_psr_wait_for_idle_locked(const struct intel_crtc_state *new_crtc_state)
2913 struct intel_display *display = to_intel_display(new_crtc_state);
2914 struct intel_encoder *encoder;
2916 if (!new_crtc_state->has_psr)
2919 for_each_intel_encoder_mask_with_psr(display->drm, encoder,
2920 new_crtc_state->uapi.encoder_mask) {
2921 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
2924 lockdep_assert_held(&intel_dp->psr.lock);
2926 if (!intel_dp->psr.enabled || intel_dp->psr.panel_replay_enabled)
2929 if (intel_dp->psr.sel_update_enabled)
2930 ret = _psr2_ready_for_pipe_update_locked(intel_dp);
2932 ret = _psr1_ready_for_pipe_update_locked(intel_dp);
2935 drm_err(display->drm,
2936 "PSR wait timed out, atomic update may fail\n");
2940 static bool __psr_wait_for_idle_locked(struct intel_dp *intel_dp)
2942 struct intel_display *display = to_intel_display(intel_dp);
2943 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
2948 if (!intel_dp->psr.enabled)
2951 if (intel_dp_is_edp(intel_dp) && (intel_dp->psr.sel_update_enabled ||
2952 intel_dp->psr.panel_replay_enabled)) {
2953 reg = EDP_PSR2_STATUS(display, cpu_transcoder);
2954 mask = EDP_PSR2_STATUS_STATE_MASK;
2956 reg = psr_status_reg(display, cpu_transcoder);
2957 mask = EDP_PSR_STATUS_STATE_MASK;
2960 mutex_unlock(&intel_dp->psr.lock);
2962 err = intel_de_wait_for_clear(display, reg, mask, 50);
2964 drm_err(display->drm,
2965 "Timed out waiting for PSR Idle for re-enable\n");
2967 /* After the unlocked wait, verify that PSR is still wanted! */
2968 mutex_lock(&intel_dp->psr.lock);
2969 return err == 0 && intel_dp->psr.enabled;
2972 static int intel_psr_fastset_force(struct intel_display *display)
2974 struct drm_connector_list_iter conn_iter;
2975 struct drm_modeset_acquire_ctx ctx;
2976 struct drm_atomic_state *state;
2977 struct drm_connector *conn;
2980 state = drm_atomic_state_alloc(display->drm);
2984 drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
2986 state->acquire_ctx = &ctx;
2987 to_intel_atomic_state(state)->internal = true;
2990 drm_connector_list_iter_begin(display->drm, &conn_iter);
2991 drm_for_each_connector_iter(conn, &conn_iter) {
2992 struct drm_connector_state *conn_state;
2993 struct drm_crtc_state *crtc_state;
2995 if (conn->connector_type != DRM_MODE_CONNECTOR_eDP)
2998 conn_state = drm_atomic_get_connector_state(state, conn);
2999 if (IS_ERR(conn_state)) {
3000 err = PTR_ERR(conn_state);
3004 if (!conn_state->crtc)
3007 crtc_state = drm_atomic_get_crtc_state(state, conn_state->crtc);
3008 if (IS_ERR(crtc_state)) {
3009 err = PTR_ERR(crtc_state);
3013 /* Mark mode as changed to trigger a pipe->update() */
3014 crtc_state->mode_changed = true;
3016 drm_connector_list_iter_end(&conn_iter);
3019 err = drm_atomic_commit(state);
3021 if (err == -EDEADLK) {
3022 drm_atomic_state_clear(state);
3023 err = drm_modeset_backoff(&ctx);
3028 drm_modeset_drop_locks(&ctx);
3029 drm_modeset_acquire_fini(&ctx);
3030 drm_atomic_state_put(state);
3035 int intel_psr_debug_set(struct intel_dp *intel_dp, u64 val)
3037 struct intel_display *display = to_intel_display(intel_dp);
3038 const u32 mode = val & I915_PSR_DEBUG_MODE_MASK;
3039 const u32 disable_bits = val & (I915_PSR_DEBUG_SU_REGION_ET_DISABLE |
3040 I915_PSR_DEBUG_PANEL_REPLAY_DISABLE);
3041 u32 old_mode, old_disable_bits;
3044 if (val & ~(I915_PSR_DEBUG_IRQ | I915_PSR_DEBUG_SU_REGION_ET_DISABLE |
3045 I915_PSR_DEBUG_PANEL_REPLAY_DISABLE |
3046 I915_PSR_DEBUG_MODE_MASK) ||
3047 mode > I915_PSR_DEBUG_ENABLE_SEL_FETCH) {
3048 drm_dbg_kms(display->drm, "Invalid debug mask %llx\n", val);
3052 ret = mutex_lock_interruptible(&intel_dp->psr.lock);
3056 old_mode = intel_dp->psr.debug & I915_PSR_DEBUG_MODE_MASK;
3057 old_disable_bits = intel_dp->psr.debug &
3058 (I915_PSR_DEBUG_SU_REGION_ET_DISABLE |
3059 I915_PSR_DEBUG_PANEL_REPLAY_DISABLE);
3061 intel_dp->psr.debug = val;
3064 * Do it right away if it's already enabled, otherwise it will be done
3065 * when enabling the source.
3067 if (intel_dp->psr.enabled)
3068 psr_irq_control(intel_dp);
3070 mutex_unlock(&intel_dp->psr.lock);
3072 if (old_mode != mode || old_disable_bits != disable_bits)
3073 ret = intel_psr_fastset_force(display);
3078 static void intel_psr_handle_irq(struct intel_dp *intel_dp)
3080 struct intel_psr *psr = &intel_dp->psr;
3082 intel_psr_disable_locked(intel_dp);
3083 psr->sink_not_reliable = true;
3084 /* let's make sure that sink is awaken */
3085 drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER, DP_SET_POWER_D0);
3088 static void intel_psr_work(struct work_struct *work)
3090 struct intel_dp *intel_dp =
3091 container_of(work, typeof(*intel_dp), psr.work);
3093 mutex_lock(&intel_dp->psr.lock);
3095 if (!intel_dp->psr.enabled)
3098 if (READ_ONCE(intel_dp->psr.irq_aux_error))
3099 intel_psr_handle_irq(intel_dp);
3102 * We have to make sure PSR is ready for re-enable
3103 * otherwise it keeps disabled until next full enable/disable cycle.
3104 * PSR might take some time to get fully disabled
3105 * and be ready for re-enable.
3107 if (!__psr_wait_for_idle_locked(intel_dp))
3111 * The delayed work can race with an invalidate hence we need to
3112 * recheck. Since psr_flush first clears this and then reschedules we
3113 * won't ever miss a flush when bailing out here.
3115 if (intel_dp->psr.busy_frontbuffer_bits || intel_dp->psr.active)
3118 intel_psr_activate(intel_dp);
3120 mutex_unlock(&intel_dp->psr.lock);
3123 static void _psr_invalidate_handle(struct intel_dp *intel_dp)
3125 struct intel_display *display = to_intel_display(intel_dp);
3126 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
3128 if (intel_dp->psr.psr2_sel_fetch_enabled) {
3131 if (intel_dp->psr.psr2_sel_fetch_cff_enabled) {
3132 /* Send one update otherwise lag is observed in screen */
3133 intel_de_write(display,
3134 CURSURFLIVE(display, intel_dp->psr.pipe),
3139 val = man_trk_ctl_enable_bit_get(display) |
3140 man_trk_ctl_partial_frame_bit_get(display) |
3141 man_trk_ctl_continuos_full_frame(display);
3142 intel_de_write(display,
3143 PSR2_MAN_TRK_CTL(display, cpu_transcoder),
3145 intel_de_write(display,
3146 CURSURFLIVE(display, intel_dp->psr.pipe), 0);
3147 intel_dp->psr.psr2_sel_fetch_cff_enabled = true;
3149 intel_psr_exit(intel_dp);
3154 * intel_psr_invalidate - Invalidate PSR
3155 * @display: display device
3156 * @frontbuffer_bits: frontbuffer plane tracking bits
3157 * @origin: which operation caused the invalidate
3159 * Since the hardware frontbuffer tracking has gaps we need to integrate
3160 * with the software frontbuffer tracking. This function gets called every
3161 * time frontbuffer rendering starts and a buffer gets dirtied. PSR must be
3162 * disabled if the frontbuffer mask contains a buffer relevant to PSR.
3164 * Dirty frontbuffers relevant to PSR are tracked in busy_frontbuffer_bits."
3166 void intel_psr_invalidate(struct intel_display *display,
3167 unsigned frontbuffer_bits, enum fb_op_origin origin)
3169 struct intel_encoder *encoder;
3171 if (origin == ORIGIN_FLIP)
3174 for_each_intel_encoder_with_psr(display->drm, encoder) {
3175 unsigned int pipe_frontbuffer_bits = frontbuffer_bits;
3176 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3178 mutex_lock(&intel_dp->psr.lock);
3179 if (!intel_dp->psr.enabled) {
3180 mutex_unlock(&intel_dp->psr.lock);
3184 pipe_frontbuffer_bits &=
3185 INTEL_FRONTBUFFER_ALL_MASK(intel_dp->psr.pipe);
3186 intel_dp->psr.busy_frontbuffer_bits |= pipe_frontbuffer_bits;
3188 if (pipe_frontbuffer_bits)
3189 _psr_invalidate_handle(intel_dp);
3191 mutex_unlock(&intel_dp->psr.lock);
3195 * When we will be completely rely on PSR2 S/W tracking in future,
3196 * intel_psr_flush() will invalidate and flush the PSR for ORIGIN_FLIP
3197 * event also therefore tgl_dc3co_flush_locked() require to be changed
3198 * accordingly in future.
3201 tgl_dc3co_flush_locked(struct intel_dp *intel_dp, unsigned int frontbuffer_bits,
3202 enum fb_op_origin origin)
3204 struct intel_display *display = to_intel_display(intel_dp);
3205 struct drm_i915_private *i915 = to_i915(display->drm);
3207 if (!intel_dp->psr.dc3co_exitline || !intel_dp->psr.sel_update_enabled ||
3208 !intel_dp->psr.active)
3212 * At every frontbuffer flush flip event modified delay of delayed work,
3213 * when delayed work schedules that means display has been idle.
3215 if (!(frontbuffer_bits &
3216 INTEL_FRONTBUFFER_ALL_MASK(intel_dp->psr.pipe)))
3219 tgl_psr2_enable_dc3co(intel_dp);
3220 mod_delayed_work(i915->unordered_wq, &intel_dp->psr.dc3co_work,
3221 intel_dp->psr.dc3co_exit_delay);
3224 static void _psr_flush_handle(struct intel_dp *intel_dp)
3226 struct intel_display *display = to_intel_display(intel_dp);
3227 struct drm_i915_private *dev_priv = to_i915(display->drm);
3228 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
3230 if (intel_dp->psr.psr2_sel_fetch_enabled) {
3231 if (intel_dp->psr.psr2_sel_fetch_cff_enabled) {
3232 /* can we turn CFF off? */
3233 if (intel_dp->psr.busy_frontbuffer_bits == 0) {
3234 u32 val = man_trk_ctl_enable_bit_get(display) |
3235 man_trk_ctl_partial_frame_bit_get(display) |
3236 man_trk_ctl_single_full_frame_bit_get(display) |
3237 man_trk_ctl_continuos_full_frame(display);
3240 * Set psr2_sel_fetch_cff_enabled as false to allow selective
3241 * updates. Still keep cff bit enabled as we don't have proper
3242 * SU configuration in case update is sent for any reason after
3243 * sff bit gets cleared by the HW on next vblank.
3245 intel_de_write(display,
3246 PSR2_MAN_TRK_CTL(display, cpu_transcoder),
3248 intel_de_write(display,
3249 CURSURFLIVE(display, intel_dp->psr.pipe),
3251 intel_dp->psr.psr2_sel_fetch_cff_enabled = false;
3255 * continuous full frame is disabled, only a single full
3258 psr_force_hw_tracking_exit(intel_dp);
3261 psr_force_hw_tracking_exit(intel_dp);
3263 if (!intel_dp->psr.active && !intel_dp->psr.busy_frontbuffer_bits)
3264 queue_work(dev_priv->unordered_wq, &intel_dp->psr.work);
3269 * intel_psr_flush - Flush PSR
3270 * @display: display device
3271 * @frontbuffer_bits: frontbuffer plane tracking bits
3272 * @origin: which operation caused the flush
3274 * Since the hardware frontbuffer tracking has gaps we need to integrate
3275 * with the software frontbuffer tracking. This function gets called every
3276 * time frontbuffer rendering has completed and flushed out to memory. PSR
3277 * can be enabled again if no other frontbuffer relevant to PSR is dirty.
3279 * Dirty frontbuffers relevant to PSR are tracked in busy_frontbuffer_bits.
3281 void intel_psr_flush(struct intel_display *display,
3282 unsigned frontbuffer_bits, enum fb_op_origin origin)
3284 struct intel_encoder *encoder;
3286 for_each_intel_encoder_with_psr(display->drm, encoder) {
3287 unsigned int pipe_frontbuffer_bits = frontbuffer_bits;
3288 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3290 mutex_lock(&intel_dp->psr.lock);
3291 if (!intel_dp->psr.enabled) {
3292 mutex_unlock(&intel_dp->psr.lock);
3296 pipe_frontbuffer_bits &=
3297 INTEL_FRONTBUFFER_ALL_MASK(intel_dp->psr.pipe);
3298 intel_dp->psr.busy_frontbuffer_bits &= ~pipe_frontbuffer_bits;
3301 * If the PSR is paused by an explicit intel_psr_paused() call,
3302 * we have to ensure that the PSR is not activated until
3303 * intel_psr_resume() is called.
3305 if (intel_dp->psr.paused)
3308 if (origin == ORIGIN_FLIP ||
3309 (origin == ORIGIN_CURSOR_UPDATE &&
3310 !intel_dp->psr.psr2_sel_fetch_enabled)) {
3311 tgl_dc3co_flush_locked(intel_dp, frontbuffer_bits, origin);
3315 if (pipe_frontbuffer_bits == 0)
3318 /* By definition flush = invalidate + flush */
3319 _psr_flush_handle(intel_dp);
3321 mutex_unlock(&intel_dp->psr.lock);
3326 * intel_psr_init - Init basic PSR work and mutex.
3327 * @intel_dp: Intel DP
3329 * This function is called after the initializing connector.
3330 * (the initializing of connector treats the handling of connector capabilities)
3331 * And it initializes basic PSR stuff for each DP Encoder.
3333 void intel_psr_init(struct intel_dp *intel_dp)
3335 struct intel_display *display = to_intel_display(intel_dp);
3336 struct intel_connector *connector = intel_dp->attached_connector;
3337 struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
3339 if (!(HAS_PSR(display) || HAS_DP20(display)))
3343 * HSW spec explicitly says PSR is tied to port A.
3344 * BDW+ platforms have a instance of PSR registers per transcoder but
3345 * BDW, GEN9 and GEN11 are not validated by HW team in other transcoder
3347 * For now it only supports one instance of PSR for BDW, GEN9 and GEN11.
3348 * So lets keep it hardcoded to PORT_A for BDW, GEN9 and GEN11.
3349 * But GEN12 supports a instance of PSR registers per transcoder.
3351 if (DISPLAY_VER(display) < 12 && dig_port->base.port != PORT_A) {
3352 drm_dbg_kms(display->drm,
3353 "PSR condition failed: Port not supported\n");
3357 if ((HAS_DP20(display) && !intel_dp_is_edp(intel_dp)) ||
3358 DISPLAY_VER(display) >= 20)
3359 intel_dp->psr.source_panel_replay_support = true;
3361 if (HAS_PSR(display) && intel_dp_is_edp(intel_dp))
3362 intel_dp->psr.source_support = true;
3364 /* Set link_standby x link_off defaults */
3365 if (DISPLAY_VER(display) < 12)
3366 /* For new platforms up to TGL let's respect VBT back again */
3367 intel_dp->psr.link_standby = connector->panel.vbt.psr.full_link;
3369 INIT_WORK(&intel_dp->psr.work, intel_psr_work);
3370 INIT_DELAYED_WORK(&intel_dp->psr.dc3co_work, tgl_dc3co_disable_work);
3371 mutex_init(&intel_dp->psr.lock);
3374 static int psr_get_status_and_error_status(struct intel_dp *intel_dp,
3375 u8 *status, u8 *error_status)
3377 struct drm_dp_aux *aux = &intel_dp->aux;
3379 unsigned int offset;
3381 offset = intel_dp->psr.panel_replay_enabled ?
3382 DP_SINK_DEVICE_PR_AND_FRAME_LOCK_STATUS : DP_PSR_STATUS;
3384 ret = drm_dp_dpcd_readb(aux, offset, status);
3388 offset = intel_dp->psr.panel_replay_enabled ?
3389 DP_PANEL_REPLAY_ERROR_STATUS : DP_PSR_ERROR_STATUS;
3391 ret = drm_dp_dpcd_readb(aux, offset, error_status);
3395 *status = *status & DP_PSR_SINK_STATE_MASK;
3400 static void psr_alpm_check(struct intel_dp *intel_dp)
3402 struct intel_display *display = to_intel_display(intel_dp);
3403 struct drm_dp_aux *aux = &intel_dp->aux;
3404 struct intel_psr *psr = &intel_dp->psr;
3408 if (!psr->sel_update_enabled)
3411 r = drm_dp_dpcd_readb(aux, DP_RECEIVER_ALPM_STATUS, &val);
3413 drm_err(display->drm, "Error reading ALPM status\n");
3417 if (val & DP_ALPM_LOCK_TIMEOUT_ERROR) {
3418 intel_psr_disable_locked(intel_dp);
3419 psr->sink_not_reliable = true;
3420 drm_dbg_kms(display->drm,
3421 "ALPM lock timeout error, disabling PSR\n");
3423 /* Clearing error */
3424 drm_dp_dpcd_writeb(aux, DP_RECEIVER_ALPM_STATUS, val);
3428 static void psr_capability_changed_check(struct intel_dp *intel_dp)
3430 struct intel_display *display = to_intel_display(intel_dp);
3431 struct intel_psr *psr = &intel_dp->psr;
3435 r = drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_ESI, &val);
3437 drm_err(display->drm, "Error reading DP_PSR_ESI\n");
3441 if (val & DP_PSR_CAPS_CHANGE) {
3442 intel_psr_disable_locked(intel_dp);
3443 psr->sink_not_reliable = true;
3444 drm_dbg_kms(display->drm,
3445 "Sink PSR capability changed, disabling PSR\n");
3448 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_ESI, val);
3454 * DP_PSR_RFB_STORAGE_ERROR == DP_PANEL_REPLAY_RFB_STORAGE_ERROR
3455 * DP_PSR_VSC_SDP_UNCORRECTABLE_ERROR == DP_PANEL_REPLAY_VSC_SDP_UNCORRECTABLE_ERROR
3456 * DP_PSR_LINK_CRC_ERROR == DP_PANEL_REPLAY_LINK_CRC_ERROR
3457 * this function is relying on PSR definitions
3459 void intel_psr_short_pulse(struct intel_dp *intel_dp)
3461 struct intel_display *display = to_intel_display(intel_dp);
3462 struct intel_psr *psr = &intel_dp->psr;
3463 u8 status, error_status;
3464 const u8 errors = DP_PSR_RFB_STORAGE_ERROR |
3465 DP_PSR_VSC_SDP_UNCORRECTABLE_ERROR |
3466 DP_PSR_LINK_CRC_ERROR;
3468 if (!CAN_PSR(intel_dp) && !CAN_PANEL_REPLAY(intel_dp))
3471 mutex_lock(&psr->lock);
3473 psr->link_ok = false;
3478 if (psr_get_status_and_error_status(intel_dp, &status, &error_status)) {
3479 drm_err(display->drm,
3480 "Error reading PSR status or error status\n");
3484 if ((!psr->panel_replay_enabled && status == DP_PSR_SINK_INTERNAL_ERROR) ||
3485 (error_status & errors)) {
3486 intel_psr_disable_locked(intel_dp);
3487 psr->sink_not_reliable = true;
3490 if (!psr->panel_replay_enabled && status == DP_PSR_SINK_INTERNAL_ERROR &&
3492 drm_dbg_kms(display->drm,
3493 "PSR sink internal error, disabling PSR\n");
3494 if (error_status & DP_PSR_RFB_STORAGE_ERROR)
3495 drm_dbg_kms(display->drm,
3496 "PSR RFB storage error, disabling PSR\n");
3497 if (error_status & DP_PSR_VSC_SDP_UNCORRECTABLE_ERROR)
3498 drm_dbg_kms(display->drm,
3499 "PSR VSC SDP uncorrectable error, disabling PSR\n");
3500 if (error_status & DP_PSR_LINK_CRC_ERROR)
3501 drm_dbg_kms(display->drm,
3502 "PSR Link CRC error, disabling PSR\n");
3504 if (error_status & ~errors)
3505 drm_err(display->drm,
3506 "PSR_ERROR_STATUS unhandled errors %x\n",
3507 error_status & ~errors);
3508 /* clear status register */
3509 drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_ERROR_STATUS, error_status);
3511 if (!psr->panel_replay_enabled) {
3512 psr_alpm_check(intel_dp);
3513 psr_capability_changed_check(intel_dp);
3517 mutex_unlock(&psr->lock);
3520 bool intel_psr_enabled(struct intel_dp *intel_dp)
3524 if (!CAN_PSR(intel_dp))
3527 mutex_lock(&intel_dp->psr.lock);
3528 ret = intel_dp->psr.enabled;
3529 mutex_unlock(&intel_dp->psr.lock);
3535 * intel_psr_link_ok - return psr->link_ok
3536 * @intel_dp: struct intel_dp
3538 * We are seeing unexpected link re-trainings with some panels. This is caused
3539 * by panel stating bad link status after PSR is enabled. Code checking link
3540 * status can call this to ensure it can ignore bad link status stated by the
3541 * panel I.e. if panel is stating bad link and intel_psr_link_ok is stating link
3542 * is ok caller should rely on latter.
3544 * Return value of link_ok
3546 bool intel_psr_link_ok(struct intel_dp *intel_dp)
3550 if ((!CAN_PSR(intel_dp) && !CAN_PANEL_REPLAY(intel_dp)) ||
3551 !intel_dp_is_edp(intel_dp))
3554 mutex_lock(&intel_dp->psr.lock);
3555 ret = intel_dp->psr.link_ok;
3556 mutex_unlock(&intel_dp->psr.lock);
3562 * intel_psr_lock - grab PSR lock
3563 * @crtc_state: the crtc state
3565 * This is initially meant to be used by around CRTC update, when
3566 * vblank sensitive registers are updated and we need grab the lock
3567 * before it to avoid vblank evasion.
3569 void intel_psr_lock(const struct intel_crtc_state *crtc_state)
3571 struct intel_display *display = to_intel_display(crtc_state);
3572 struct intel_encoder *encoder;
3574 if (!crtc_state->has_psr)
3577 for_each_intel_encoder_mask_with_psr(display->drm, encoder,
3578 crtc_state->uapi.encoder_mask) {
3579 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3581 mutex_lock(&intel_dp->psr.lock);
3587 * intel_psr_unlock - release PSR lock
3588 * @crtc_state: the crtc state
3590 * Release the PSR lock that was held during pipe update.
3592 void intel_psr_unlock(const struct intel_crtc_state *crtc_state)
3594 struct intel_display *display = to_intel_display(crtc_state);
3595 struct intel_encoder *encoder;
3597 if (!crtc_state->has_psr)
3600 for_each_intel_encoder_mask_with_psr(display->drm, encoder,
3601 crtc_state->uapi.encoder_mask) {
3602 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3604 mutex_unlock(&intel_dp->psr.lock);
3610 psr_source_status(struct intel_dp *intel_dp, struct seq_file *m)
3612 struct intel_display *display = to_intel_display(intel_dp);
3613 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
3614 const char *status = "unknown";
3615 u32 val, status_val;
3617 if (intel_dp_is_edp(intel_dp) && (intel_dp->psr.sel_update_enabled ||
3618 intel_dp->psr.panel_replay_enabled)) {
3619 static const char * const live_status[] = {
3632 val = intel_de_read(display,
3633 EDP_PSR2_STATUS(display, cpu_transcoder));
3634 status_val = REG_FIELD_GET(EDP_PSR2_STATUS_STATE_MASK, val);
3635 if (status_val < ARRAY_SIZE(live_status))
3636 status = live_status[status_val];
3638 static const char * const live_status[] = {
3648 val = intel_de_read(display,
3649 psr_status_reg(display, cpu_transcoder));
3650 status_val = REG_FIELD_GET(EDP_PSR_STATUS_STATE_MASK, val);
3651 if (status_val < ARRAY_SIZE(live_status))
3652 status = live_status[status_val];
3655 seq_printf(m, "Source PSR/PanelReplay status: %s [0x%08x]\n", status, val);
3658 static void intel_psr_sink_capability(struct intel_dp *intel_dp,
3661 struct intel_psr *psr = &intel_dp->psr;
3663 seq_printf(m, "Sink support: PSR = %s",
3664 str_yes_no(psr->sink_support));
3666 if (psr->sink_support)
3667 seq_printf(m, " [0x%02x]", intel_dp->psr_dpcd[0]);
3668 if (intel_dp->psr_dpcd[0] == DP_PSR2_WITH_Y_COORD_ET_SUPPORTED)
3669 seq_printf(m, " (Early Transport)");
3670 seq_printf(m, ", Panel Replay = %s", str_yes_no(psr->sink_panel_replay_support));
3671 seq_printf(m, ", Panel Replay Selective Update = %s",
3672 str_yes_no(psr->sink_panel_replay_su_support));
3673 if (intel_dp->pr_dpcd & DP_PANEL_REPLAY_EARLY_TRANSPORT_SUPPORT)
3674 seq_printf(m, " (Early Transport)");
3675 seq_printf(m, "\n");
3678 static void intel_psr_print_mode(struct intel_dp *intel_dp,
3681 struct intel_psr *psr = &intel_dp->psr;
3682 const char *status, *mode, *region_et;
3685 status = " enabled";
3687 status = "disabled";
3689 if (psr->panel_replay_enabled && psr->sel_update_enabled)
3690 mode = "Panel Replay Selective Update";
3691 else if (psr->panel_replay_enabled)
3692 mode = "Panel Replay";
3693 else if (psr->sel_update_enabled)
3695 else if (psr->enabled)
3700 if (psr->su_region_et_enabled)
3701 region_et = " (Early Transport)";
3705 seq_printf(m, "PSR mode: %s%s%s\n", mode, status, region_et);
3708 static int intel_psr_status(struct seq_file *m, struct intel_dp *intel_dp)
3710 struct intel_display *display = to_intel_display(intel_dp);
3711 struct drm_i915_private *dev_priv = to_i915(display->drm);
3712 enum transcoder cpu_transcoder = intel_dp->psr.transcoder;
3713 struct intel_psr *psr = &intel_dp->psr;
3714 intel_wakeref_t wakeref;
3718 intel_psr_sink_capability(intel_dp, m);
3720 if (!(psr->sink_support || psr->sink_panel_replay_support))
3723 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
3724 mutex_lock(&psr->lock);
3726 intel_psr_print_mode(intel_dp, m);
3728 if (!psr->enabled) {
3729 seq_printf(m, "PSR sink not reliable: %s\n",
3730 str_yes_no(psr->sink_not_reliable));
3735 if (psr->panel_replay_enabled) {
3736 val = intel_de_read(display, TRANS_DP2_CTL(cpu_transcoder));
3738 if (intel_dp_is_edp(intel_dp))
3739 psr2_ctl = intel_de_read(display,
3740 EDP_PSR2_CTL(display,
3743 enabled = val & TRANS_DP2_PANEL_REPLAY_ENABLE;
3744 } else if (psr->sel_update_enabled) {
3745 val = intel_de_read(display,
3746 EDP_PSR2_CTL(display, cpu_transcoder));
3747 enabled = val & EDP_PSR2_ENABLE;
3749 val = intel_de_read(display, psr_ctl_reg(display, cpu_transcoder));
3750 enabled = val & EDP_PSR_ENABLE;
3752 seq_printf(m, "Source PSR/PanelReplay ctl: %s [0x%08x]\n",
3753 str_enabled_disabled(enabled), val);
3754 if (psr->panel_replay_enabled && intel_dp_is_edp(intel_dp))
3755 seq_printf(m, "PSR2_CTL: 0x%08x\n",
3757 psr_source_status(intel_dp, m);
3758 seq_printf(m, "Busy frontbuffer bits: 0x%08x\n",
3759 psr->busy_frontbuffer_bits);
3762 * SKL+ Perf counter is reset to 0 everytime DC state is entered
3764 val = intel_de_read(display, psr_perf_cnt_reg(display, cpu_transcoder));
3765 seq_printf(m, "Performance counter: %u\n",
3766 REG_FIELD_GET(EDP_PSR_PERF_CNT_MASK, val));
3768 if (psr->debug & I915_PSR_DEBUG_IRQ) {
3769 seq_printf(m, "Last attempted entry at: %lld\n",
3770 psr->last_entry_attempt);
3771 seq_printf(m, "Last exit at: %lld\n", psr->last_exit);
3774 if (psr->sel_update_enabled) {
3775 u32 su_frames_val[3];
3779 * Reading all 3 registers before hand to minimize crossing a
3780 * frame boundary between register reads
3782 for (frame = 0; frame < PSR2_SU_STATUS_FRAMES; frame += 3) {
3783 val = intel_de_read(display,
3784 PSR2_SU_STATUS(display, cpu_transcoder, frame));
3785 su_frames_val[frame / 3] = val;
3788 seq_puts(m, "Frame:\tPSR2 SU blocks:\n");
3790 for (frame = 0; frame < PSR2_SU_STATUS_FRAMES; frame++) {
3793 su_blocks = su_frames_val[frame / 3] &
3794 PSR2_SU_STATUS_MASK(frame);
3795 su_blocks = su_blocks >> PSR2_SU_STATUS_SHIFT(frame);
3796 seq_printf(m, "%d\t%d\n", frame, su_blocks);
3799 seq_printf(m, "PSR2 selective fetch: %s\n",
3800 str_enabled_disabled(psr->psr2_sel_fetch_enabled));
3804 mutex_unlock(&psr->lock);
3805 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
3810 static int i915_edp_psr_status_show(struct seq_file *m, void *data)
3812 struct intel_display *display = m->private;
3813 struct intel_dp *intel_dp = NULL;
3814 struct intel_encoder *encoder;
3816 if (!HAS_PSR(display))
3819 /* Find the first EDP which supports PSR */
3820 for_each_intel_encoder_with_psr(display->drm, encoder) {
3821 intel_dp = enc_to_intel_dp(encoder);
3828 return intel_psr_status(m, intel_dp);
3830 DEFINE_SHOW_ATTRIBUTE(i915_edp_psr_status);
3833 i915_edp_psr_debug_set(void *data, u64 val)
3835 struct intel_display *display = data;
3836 struct drm_i915_private *dev_priv = to_i915(display->drm);
3837 struct intel_encoder *encoder;
3838 intel_wakeref_t wakeref;
3841 if (!HAS_PSR(display))
3844 for_each_intel_encoder_with_psr(display->drm, encoder) {
3845 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3847 drm_dbg_kms(display->drm, "Setting PSR debug to %llx\n", val);
3849 wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
3851 // TODO: split to each transcoder's PSR debug state
3852 ret = intel_psr_debug_set(intel_dp, val);
3854 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
3861 i915_edp_psr_debug_get(void *data, u64 *val)
3863 struct intel_display *display = data;
3864 struct intel_encoder *encoder;
3866 if (!HAS_PSR(display))
3869 for_each_intel_encoder_with_psr(display->drm, encoder) {
3870 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
3872 // TODO: split to each transcoder's PSR debug state
3873 *val = READ_ONCE(intel_dp->psr.debug);
3880 DEFINE_SIMPLE_ATTRIBUTE(i915_edp_psr_debug_fops,
3881 i915_edp_psr_debug_get, i915_edp_psr_debug_set,
3884 void intel_psr_debugfs_register(struct intel_display *display)
3886 struct drm_minor *minor = display->drm->primary;
3888 debugfs_create_file("i915_edp_psr_debug", 0644, minor->debugfs_root,
3889 display, &i915_edp_psr_debug_fops);
3891 debugfs_create_file("i915_edp_psr_status", 0444, minor->debugfs_root,
3892 display, &i915_edp_psr_status_fops);
3895 static const char *psr_mode_str(struct intel_dp *intel_dp)
3897 if (intel_dp->psr.panel_replay_enabled)
3898 return "PANEL-REPLAY";
3899 else if (intel_dp->psr.enabled)
3905 static int i915_psr_sink_status_show(struct seq_file *m, void *data)
3907 struct intel_connector *connector = m->private;
3908 struct intel_dp *intel_dp = intel_attached_dp(connector);
3909 static const char * const sink_status[] = {
3911 "transition to active, capture and display",
3912 "active, display from RFB",
3913 "active, capture and display on sink device timings",
3914 "transition to inactive, capture and display, timing re-sync",
3917 "sink internal error",
3921 u8 status, error_status;
3923 if (!(CAN_PSR(intel_dp) || CAN_PANEL_REPLAY(intel_dp))) {
3924 seq_puts(m, "PSR/Panel-Replay Unsupported\n");
3928 if (connector->base.status != connector_status_connected)
3931 ret = psr_get_status_and_error_status(intel_dp, &status, &error_status);
3935 status &= DP_PSR_SINK_STATE_MASK;
3936 if (status < ARRAY_SIZE(sink_status))
3937 str = sink_status[status];
3941 seq_printf(m, "Sink %s status: 0x%x [%s]\n", psr_mode_str(intel_dp), status, str);
3943 seq_printf(m, "Sink %s error status: 0x%x", psr_mode_str(intel_dp), error_status);
3945 if (error_status & (DP_PSR_RFB_STORAGE_ERROR |
3946 DP_PSR_VSC_SDP_UNCORRECTABLE_ERROR |
3947 DP_PSR_LINK_CRC_ERROR))
3951 if (error_status & DP_PSR_RFB_STORAGE_ERROR)
3952 seq_printf(m, "\t%s RFB storage error\n", psr_mode_str(intel_dp));
3953 if (error_status & DP_PSR_VSC_SDP_UNCORRECTABLE_ERROR)
3954 seq_printf(m, "\t%s VSC SDP uncorrectable error\n", psr_mode_str(intel_dp));
3955 if (error_status & DP_PSR_LINK_CRC_ERROR)
3956 seq_printf(m, "\t%s Link CRC error\n", psr_mode_str(intel_dp));
3960 DEFINE_SHOW_ATTRIBUTE(i915_psr_sink_status);
3962 static int i915_psr_status_show(struct seq_file *m, void *data)
3964 struct intel_connector *connector = m->private;
3965 struct intel_dp *intel_dp = intel_attached_dp(connector);
3967 return intel_psr_status(m, intel_dp);
3969 DEFINE_SHOW_ATTRIBUTE(i915_psr_status);
3971 void intel_psr_connector_debugfs_add(struct intel_connector *connector)
3973 struct intel_display *display = to_intel_display(connector);
3974 struct dentry *root = connector->base.debugfs_entry;
3976 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP &&
3977 connector->base.connector_type != DRM_MODE_CONNECTOR_DisplayPort)
3980 debugfs_create_file("i915_psr_sink_status", 0444, root,
3981 connector, &i915_psr_sink_status_fops);
3983 if (HAS_PSR(display) || HAS_DP20(display))
3984 debugfs_create_file("i915_psr_status", 0444, root,
3985 connector, &i915_psr_status_fops);