1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2022 Intel Corporation 4 * 5 * High level crtc/connector/encoder modeset state verification. 6 */ 7 8 #include <drm/drm_atomic_state_helper.h> 9 #include <drm/drm_print.h> 10 11 #include "intel_atomic.h" 12 #include "intel_crtc.h" 13 #include "intel_crtc_state_dump.h" 14 #include "intel_cx0_phy.h" 15 #include "intel_display.h" 16 #include "intel_display_core.h" 17 #include "intel_display_types.h" 18 #include "intel_fdi.h" 19 #include "intel_modeset_verify.h" 20 #include "intel_snps_phy.h" 21 #include "skl_watermark.h" 22 23 /* 24 * Cross check the actual hw state with our own modeset state tracking (and its 25 * internal consistency). 26 */ 27 static void intel_connector_verify_state(const struct intel_crtc_state *crtc_state, 28 const struct drm_connector_state *conn_state) 29 { 30 struct intel_connector *connector = to_intel_connector(conn_state->connector); 31 struct intel_display *display = to_intel_display(connector); 32 33 drm_dbg_kms(display->drm, "[CONNECTOR:%d:%s]\n", 34 connector->base.base.id, connector->base.name); 35 36 if (connector->get_hw_state(connector)) { 37 struct intel_encoder *encoder = intel_attached_encoder(connector); 38 39 INTEL_DISPLAY_STATE_WARN(display, !crtc_state, 40 "connector enabled without attached crtc\n"); 41 42 if (!crtc_state) 43 return; 44 45 INTEL_DISPLAY_STATE_WARN(display, !crtc_state->hw.active, 46 "connector is active, but attached crtc isn't\n"); 47 48 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) 49 return; 50 51 INTEL_DISPLAY_STATE_WARN(display, 52 conn_state->best_encoder != &encoder->base, 53 "atomic encoder doesn't match attached encoder\n"); 54 55 INTEL_DISPLAY_STATE_WARN(display, conn_state->crtc != encoder->base.crtc, 56 "attached encoder crtc differs from connector crtc\n"); 57 } else { 58 INTEL_DISPLAY_STATE_WARN(display, crtc_state && crtc_state->hw.active, 59 "attached crtc is active, but connector isn't\n"); 60 INTEL_DISPLAY_STATE_WARN(display, !crtc_state && conn_state->best_encoder, 61 "best encoder set without crtc!\n"); 62 } 63 } 64 65 static void 66 verify_connector_state(struct intel_atomic_state *state, 67 struct intel_crtc *crtc) 68 { 69 struct intel_display *display = to_intel_display(state); 70 struct drm_connector *connector; 71 const struct drm_connector_state *new_conn_state; 72 int i; 73 74 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) { 75 struct drm_encoder *encoder = connector->encoder; 76 const struct intel_crtc_state *crtc_state = NULL; 77 78 if (new_conn_state->crtc != &crtc->base) 79 continue; 80 81 if (crtc) 82 crtc_state = intel_atomic_get_new_crtc_state(state, crtc); 83 84 intel_connector_verify_state(crtc_state, new_conn_state); 85 86 INTEL_DISPLAY_STATE_WARN(display, new_conn_state->best_encoder != encoder, 87 "connector's atomic encoder doesn't match legacy encoder\n"); 88 } 89 } 90 91 static void intel_pipe_config_sanity_check(const struct intel_crtc_state *crtc_state) 92 { 93 struct intel_display *display = to_intel_display(crtc_state); 94 95 if (crtc_state->has_pch_encoder) { 96 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(display, crtc_state), 97 &crtc_state->fdi_m_n); 98 int dotclock = crtc_state->hw.adjusted_mode.crtc_clock; 99 100 /* 101 * FDI already provided one idea for the dotclock. 102 * Yell if the encoder disagrees. Allow for slight 103 * rounding differences. 104 */ 105 drm_WARN(display->drm, abs(fdi_dotclock - dotclock) > 1, 106 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", 107 fdi_dotclock, dotclock); 108 } 109 } 110 111 static void 112 verify_encoder_state(struct intel_atomic_state *state) 113 { 114 struct intel_display *display = to_intel_display(state); 115 struct intel_encoder *encoder; 116 struct drm_connector *connector; 117 const struct drm_connector_state *old_conn_state, *new_conn_state; 118 int i; 119 120 for_each_intel_encoder(display->drm, encoder) { 121 bool enabled = false, found = false; 122 enum pipe pipe; 123 124 drm_dbg_kms(display->drm, "[ENCODER:%d:%s]\n", 125 encoder->base.base.id, 126 encoder->base.name); 127 128 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state, 129 new_conn_state, i) { 130 if (old_conn_state->best_encoder == &encoder->base) 131 found = true; 132 133 if (new_conn_state->best_encoder != &encoder->base) 134 continue; 135 136 found = true; 137 enabled = true; 138 139 INTEL_DISPLAY_STATE_WARN(display, 140 new_conn_state->crtc != encoder->base.crtc, 141 "connector's crtc doesn't match encoder crtc\n"); 142 } 143 144 if (!found) 145 continue; 146 147 INTEL_DISPLAY_STATE_WARN(display, !!encoder->base.crtc != enabled, 148 "encoder's enabled state mismatch (expected %i, found %i)\n", 149 !!encoder->base.crtc, enabled); 150 151 if (!encoder->base.crtc) { 152 bool active; 153 154 active = encoder->get_hw_state(encoder, &pipe); 155 INTEL_DISPLAY_STATE_WARN(display, active, 156 "encoder detached but still enabled on pipe %c.\n", 157 pipe_name(pipe)); 158 } 159 } 160 } 161 162 static void 163 verify_crtc_state(struct intel_atomic_state *state, 164 struct intel_crtc *crtc) 165 { 166 struct intel_display *display = to_intel_display(state); 167 const struct intel_crtc_state *sw_crtc_state = 168 intel_atomic_get_new_crtc_state(state, crtc); 169 struct intel_crtc_state *hw_crtc_state; 170 struct intel_crtc *primary_crtc; 171 struct intel_encoder *encoder; 172 173 hw_crtc_state = intel_crtc_state_alloc(crtc); 174 if (!hw_crtc_state) 175 return; 176 177 drm_dbg_kms(display->drm, "[CRTC:%d:%s]\n", crtc->base.base.id, 178 crtc->base.name); 179 180 hw_crtc_state->hw.enable = sw_crtc_state->hw.enable; 181 182 intel_crtc_get_pipe_config(hw_crtc_state); 183 184 /* we keep both pipes enabled on 830 */ 185 if (display->platform.i830 && hw_crtc_state->hw.active) 186 hw_crtc_state->hw.active = sw_crtc_state->hw.active; 187 188 INTEL_DISPLAY_STATE_WARN(display, 189 sw_crtc_state->hw.active != hw_crtc_state->hw.active, 190 "crtc active state doesn't match with hw state (expected %i, found %i)\n", 191 sw_crtc_state->hw.active, hw_crtc_state->hw.active); 192 193 INTEL_DISPLAY_STATE_WARN(display, crtc->active != sw_crtc_state->hw.active, 194 "transitional active state does not match atomic hw state (expected %i, found %i)\n", 195 sw_crtc_state->hw.active, crtc->active); 196 197 primary_crtc = intel_primary_crtc(sw_crtc_state); 198 199 for_each_encoder_on_crtc(display->drm, &primary_crtc->base, encoder) { 200 enum pipe pipe; 201 bool active; 202 203 active = encoder->get_hw_state(encoder, &pipe); 204 INTEL_DISPLAY_STATE_WARN(display, active != sw_crtc_state->hw.active, 205 "[ENCODER:%i] active %i with crtc active %i\n", 206 encoder->base.base.id, active, 207 sw_crtc_state->hw.active); 208 209 INTEL_DISPLAY_STATE_WARN(display, active && primary_crtc->pipe != pipe, 210 "Encoder connected to wrong pipe %c\n", 211 pipe_name(pipe)); 212 213 if (active) 214 intel_encoder_get_config(encoder, hw_crtc_state); 215 } 216 217 if (!sw_crtc_state->hw.active) 218 goto destroy_state; 219 220 intel_pipe_config_sanity_check(hw_crtc_state); 221 222 if (!intel_pipe_config_compare(sw_crtc_state, 223 hw_crtc_state, false)) { 224 INTEL_DISPLAY_STATE_WARN(display, 1, "pipe state doesn't match!\n"); 225 intel_crtc_state_dump(hw_crtc_state, NULL, "hw state"); 226 intel_crtc_state_dump(sw_crtc_state, NULL, "sw state"); 227 } 228 229 destroy_state: 230 intel_crtc_destroy_state(&crtc->base, &hw_crtc_state->uapi); 231 } 232 233 void intel_modeset_verify_crtc(struct intel_atomic_state *state, 234 struct intel_crtc *crtc) 235 { 236 const struct intel_crtc_state *new_crtc_state = 237 intel_atomic_get_new_crtc_state(state, crtc); 238 239 if (!intel_crtc_needs_modeset(new_crtc_state) && 240 !intel_crtc_needs_fastset(new_crtc_state)) 241 return; 242 243 intel_wm_state_verify(state, crtc); 244 verify_connector_state(state, crtc); 245 verify_crtc_state(state, crtc); 246 intel_dpll_state_verify(state, crtc); 247 intel_mpllb_state_verify(state, crtc); 248 intel_cx0pll_state_verify(state, crtc); 249 } 250 251 void intel_modeset_verify_disabled(struct intel_atomic_state *state) 252 { 253 verify_encoder_state(state); 254 verify_connector_state(state, NULL); 255 intel_dpll_verify_disabled(state); 256 } 257