1 // SPDX-License-Identifier: MIT
3 * Copyright © 2022 Intel Corporation
5 * High level crtc/connector/encoder modeset state verification.
8 #include <drm/drm_atomic_state_helper.h>
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_types.h"
17 #include "intel_fdi.h"
18 #include "intel_modeset_verify.h"
19 #include "intel_snps_phy.h"
20 #include "skl_watermark.h"
23 * Cross check the actual hw state with our own modeset state tracking (and its
24 * internal consistency).
26 static void intel_connector_verify_state(const struct intel_crtc_state *crtc_state,
27 const struct drm_connector_state *conn_state)
29 struct intel_connector *connector = to_intel_connector(conn_state->connector);
30 struct drm_i915_private *i915 = to_i915(connector->base.dev);
32 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n",
33 connector->base.base.id, connector->base.name);
35 if (connector->get_hw_state(connector)) {
36 struct intel_encoder *encoder = intel_attached_encoder(connector);
38 I915_STATE_WARN(i915, !crtc_state,
39 "connector enabled without attached crtc\n");
44 I915_STATE_WARN(i915, !crtc_state->hw.active,
45 "connector is active, but attached crtc isn't\n");
47 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
51 conn_state->best_encoder != &encoder->base,
52 "atomic encoder doesn't match attached encoder\n");
54 I915_STATE_WARN(i915, conn_state->crtc != encoder->base.crtc,
55 "attached encoder crtc differs from connector crtc\n");
57 I915_STATE_WARN(i915, crtc_state && crtc_state->hw.active,
58 "attached crtc is active, but connector isn't\n");
59 I915_STATE_WARN(i915, !crtc_state && conn_state->best_encoder,
60 "best encoder set without crtc!\n");
65 verify_connector_state(struct intel_atomic_state *state,
66 struct intel_crtc *crtc)
68 struct drm_connector *connector;
69 const struct drm_connector_state *new_conn_state;
72 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
73 struct drm_encoder *encoder = connector->encoder;
74 const struct intel_crtc_state *crtc_state = NULL;
76 if (new_conn_state->crtc != &crtc->base)
80 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
82 intel_connector_verify_state(crtc_state, new_conn_state);
84 I915_STATE_WARN(to_i915(connector->dev), new_conn_state->best_encoder != encoder,
85 "connector's atomic encoder doesn't match legacy encoder\n");
89 static void intel_pipe_config_sanity_check(const struct intel_crtc_state *crtc_state)
91 struct drm_i915_private *i915 = to_i915(crtc_state->uapi.crtc->dev);
93 if (crtc_state->has_pch_encoder) {
94 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(i915, crtc_state),
95 &crtc_state->fdi_m_n);
96 int dotclock = crtc_state->hw.adjusted_mode.crtc_clock;
99 * FDI already provided one idea for the dotclock.
100 * Yell if the encoder disagrees. Allow for slight
101 * rounding differences.
103 drm_WARN(&i915->drm, abs(fdi_dotclock - dotclock) > 1,
104 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
105 fdi_dotclock, dotclock);
110 verify_encoder_state(struct intel_atomic_state *state)
112 struct drm_i915_private *i915 = to_i915(state->base.dev);
113 struct intel_encoder *encoder;
114 struct drm_connector *connector;
115 const struct drm_connector_state *old_conn_state, *new_conn_state;
118 for_each_intel_encoder(&i915->drm, encoder) {
119 bool enabled = false, found = false;
122 drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s]\n",
123 encoder->base.base.id,
126 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
128 if (old_conn_state->best_encoder == &encoder->base)
131 if (new_conn_state->best_encoder != &encoder->base)
137 I915_STATE_WARN(i915,
138 new_conn_state->crtc != encoder->base.crtc,
139 "connector's crtc doesn't match encoder crtc\n");
145 I915_STATE_WARN(i915, !!encoder->base.crtc != enabled,
146 "encoder's enabled state mismatch (expected %i, found %i)\n",
147 !!encoder->base.crtc, enabled);
149 if (!encoder->base.crtc) {
152 active = encoder->get_hw_state(encoder, &pipe);
153 I915_STATE_WARN(i915, active,
154 "encoder detached but still enabled on pipe %c.\n",
161 verify_crtc_state(struct intel_atomic_state *state,
162 struct intel_crtc *crtc)
164 struct drm_device *dev = crtc->base.dev;
165 struct drm_i915_private *i915 = to_i915(dev);
166 const struct intel_crtc_state *sw_crtc_state =
167 intel_atomic_get_new_crtc_state(state, crtc);
168 struct intel_crtc_state *hw_crtc_state;
169 struct intel_crtc *master_crtc;
170 struct intel_encoder *encoder;
172 hw_crtc_state = intel_crtc_state_alloc(crtc);
176 drm_dbg_kms(&i915->drm, "[CRTC:%d:%s]\n", crtc->base.base.id,
179 hw_crtc_state->hw.enable = sw_crtc_state->hw.enable;
181 intel_crtc_get_pipe_config(hw_crtc_state);
183 /* we keep both pipes enabled on 830 */
184 if (IS_I830(i915) && hw_crtc_state->hw.active)
185 hw_crtc_state->hw.active = sw_crtc_state->hw.active;
187 I915_STATE_WARN(i915,
188 sw_crtc_state->hw.active != hw_crtc_state->hw.active,
189 "crtc active state doesn't match with hw state (expected %i, found %i)\n",
190 sw_crtc_state->hw.active, hw_crtc_state->hw.active);
192 I915_STATE_WARN(i915, crtc->active != sw_crtc_state->hw.active,
193 "transitional active state does not match atomic hw state (expected %i, found %i)\n",
194 sw_crtc_state->hw.active, crtc->active);
196 master_crtc = intel_master_crtc(sw_crtc_state);
198 for_each_encoder_on_crtc(dev, &master_crtc->base, encoder) {
202 active = encoder->get_hw_state(encoder, &pipe);
203 I915_STATE_WARN(i915, active != sw_crtc_state->hw.active,
204 "[ENCODER:%i] active %i with crtc active %i\n",
205 encoder->base.base.id, active,
206 sw_crtc_state->hw.active);
208 I915_STATE_WARN(i915, active && master_crtc->pipe != pipe,
209 "Encoder connected to wrong pipe %c\n",
213 intel_encoder_get_config(encoder, hw_crtc_state);
216 if (!sw_crtc_state->hw.active)
219 intel_pipe_config_sanity_check(hw_crtc_state);
221 if (!intel_pipe_config_compare(sw_crtc_state,
222 hw_crtc_state, false)) {
223 I915_STATE_WARN(i915, 1, "pipe state doesn't match!\n");
224 intel_crtc_state_dump(hw_crtc_state, NULL, "hw state");
225 intel_crtc_state_dump(sw_crtc_state, NULL, "sw state");
229 intel_crtc_destroy_state(&crtc->base, &hw_crtc_state->uapi);
232 void intel_modeset_verify_crtc(struct intel_atomic_state *state,
233 struct intel_crtc *crtc)
235 const struct intel_crtc_state *new_crtc_state =
236 intel_atomic_get_new_crtc_state(state, crtc);
238 if (!intel_crtc_needs_modeset(new_crtc_state) &&
239 !intel_crtc_needs_fastset(new_crtc_state))
242 intel_wm_state_verify(state, crtc);
243 verify_connector_state(state, crtc);
244 verify_crtc_state(state, crtc);
245 intel_shared_dpll_state_verify(state, crtc);
246 intel_mpllb_state_verify(state, crtc);
247 intel_cx0pll_state_verify(state, crtc);
250 void intel_modeset_verify_disabled(struct intel_atomic_state *state)
252 verify_encoder_state(state);
253 verify_connector_state(state, NULL);
254 intel_shared_dpll_verify_disabled(state);