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