0001
0002
0003
0004
0005
0006
0007
0008 #include <drm/drm_atomic_state_helper.h>
0009
0010 #include "i915_drv.h"
0011 #include "intel_atomic.h"
0012 #include "intel_crtc.h"
0013 #include "intel_crtc_state_dump.h"
0014 #include "intel_display.h"
0015 #include "intel_display_types.h"
0016 #include "intel_fdi.h"
0017 #include "intel_modeset_verify.h"
0018 #include "intel_pm.h"
0019 #include "intel_snps_phy.h"
0020
0021
0022
0023
0024
0025 static void intel_connector_verify_state(struct intel_crtc_state *crtc_state,
0026 struct drm_connector_state *conn_state)
0027 {
0028 struct intel_connector *connector = to_intel_connector(conn_state->connector);
0029 struct drm_i915_private *i915 = to_i915(connector->base.dev);
0030
0031 drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s]\n",
0032 connector->base.base.id, connector->base.name);
0033
0034 if (connector->get_hw_state(connector)) {
0035 struct intel_encoder *encoder = intel_attached_encoder(connector);
0036
0037 I915_STATE_WARN(!crtc_state,
0038 "connector enabled without attached crtc\n");
0039
0040 if (!crtc_state)
0041 return;
0042
0043 I915_STATE_WARN(!crtc_state->hw.active,
0044 "connector is active, but attached crtc isn't\n");
0045
0046 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
0047 return;
0048
0049 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
0050 "atomic encoder doesn't match attached encoder\n");
0051
0052 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
0053 "attached encoder crtc differs from connector crtc\n");
0054 } else {
0055 I915_STATE_WARN(crtc_state && crtc_state->hw.active,
0056 "attached crtc is active, but connector isn't\n");
0057 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
0058 "best encoder set without crtc!\n");
0059 }
0060 }
0061
0062 static void
0063 verify_connector_state(struct intel_atomic_state *state,
0064 struct intel_crtc *crtc)
0065 {
0066 struct drm_connector *connector;
0067 struct drm_connector_state *new_conn_state;
0068 int i;
0069
0070 for_each_new_connector_in_state(&state->base, connector, new_conn_state, i) {
0071 struct drm_encoder *encoder = connector->encoder;
0072 struct intel_crtc_state *crtc_state = NULL;
0073
0074 if (new_conn_state->crtc != &crtc->base)
0075 continue;
0076
0077 if (crtc)
0078 crtc_state = intel_atomic_get_new_crtc_state(state, crtc);
0079
0080 intel_connector_verify_state(crtc_state, new_conn_state);
0081
0082 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
0083 "connector's atomic encoder doesn't match legacy encoder\n");
0084 }
0085 }
0086
0087 static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
0088 const struct intel_crtc_state *pipe_config)
0089 {
0090 if (pipe_config->has_pch_encoder) {
0091 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
0092 &pipe_config->fdi_m_n);
0093 int dotclock = pipe_config->hw.adjusted_mode.crtc_clock;
0094
0095
0096
0097
0098
0099 drm_WARN(&dev_priv->drm,
0100 !intel_fuzzy_clock_check(fdi_dotclock, dotclock),
0101 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
0102 fdi_dotclock, dotclock);
0103 }
0104 }
0105
0106 static void
0107 verify_encoder_state(struct drm_i915_private *dev_priv, struct intel_atomic_state *state)
0108 {
0109 struct intel_encoder *encoder;
0110 struct drm_connector *connector;
0111 struct drm_connector_state *old_conn_state, *new_conn_state;
0112 int i;
0113
0114 for_each_intel_encoder(&dev_priv->drm, encoder) {
0115 bool enabled = false, found = false;
0116 enum pipe pipe;
0117
0118 drm_dbg_kms(&dev_priv->drm, "[ENCODER:%d:%s]\n",
0119 encoder->base.base.id,
0120 encoder->base.name);
0121
0122 for_each_oldnew_connector_in_state(&state->base, connector, old_conn_state,
0123 new_conn_state, i) {
0124 if (old_conn_state->best_encoder == &encoder->base)
0125 found = true;
0126
0127 if (new_conn_state->best_encoder != &encoder->base)
0128 continue;
0129
0130 found = true;
0131 enabled = true;
0132
0133 I915_STATE_WARN(new_conn_state->crtc !=
0134 encoder->base.crtc,
0135 "connector's crtc doesn't match encoder crtc\n");
0136 }
0137
0138 if (!found)
0139 continue;
0140
0141 I915_STATE_WARN(!!encoder->base.crtc != enabled,
0142 "encoder's enabled state mismatch (expected %i, found %i)\n",
0143 !!encoder->base.crtc, enabled);
0144
0145 if (!encoder->base.crtc) {
0146 bool active;
0147
0148 active = encoder->get_hw_state(encoder, &pipe);
0149 I915_STATE_WARN(active,
0150 "encoder detached but still enabled on pipe %c.\n",
0151 pipe_name(pipe));
0152 }
0153 }
0154 }
0155
0156 static void
0157 verify_crtc_state(struct intel_crtc *crtc,
0158 struct intel_crtc_state *old_crtc_state,
0159 struct intel_crtc_state *new_crtc_state)
0160 {
0161 struct drm_device *dev = crtc->base.dev;
0162 struct drm_i915_private *dev_priv = to_i915(dev);
0163 struct intel_encoder *encoder;
0164 struct intel_crtc_state *pipe_config = old_crtc_state;
0165 struct drm_atomic_state *state = old_crtc_state->uapi.state;
0166 struct intel_crtc *master_crtc;
0167
0168 __drm_atomic_helper_crtc_destroy_state(&old_crtc_state->uapi);
0169 intel_crtc_free_hw_state(old_crtc_state);
0170 intel_crtc_state_reset(old_crtc_state, crtc);
0171 old_crtc_state->uapi.state = state;
0172
0173 drm_dbg_kms(&dev_priv->drm, "[CRTC:%d:%s]\n", crtc->base.base.id,
0174 crtc->base.name);
0175
0176 pipe_config->hw.enable = new_crtc_state->hw.enable;
0177
0178 intel_crtc_get_pipe_config(pipe_config);
0179
0180
0181 if (IS_I830(dev_priv) && pipe_config->hw.active)
0182 pipe_config->hw.active = new_crtc_state->hw.active;
0183
0184 I915_STATE_WARN(new_crtc_state->hw.active != pipe_config->hw.active,
0185 "crtc active state doesn't match with hw state (expected %i, found %i)\n",
0186 new_crtc_state->hw.active, pipe_config->hw.active);
0187
0188 I915_STATE_WARN(crtc->active != new_crtc_state->hw.active,
0189 "transitional active state does not match atomic hw state (expected %i, found %i)\n",
0190 new_crtc_state->hw.active, crtc->active);
0191
0192 master_crtc = intel_master_crtc(new_crtc_state);
0193
0194 for_each_encoder_on_crtc(dev, &master_crtc->base, encoder) {
0195 enum pipe pipe;
0196 bool active;
0197
0198 active = encoder->get_hw_state(encoder, &pipe);
0199 I915_STATE_WARN(active != new_crtc_state->hw.active,
0200 "[ENCODER:%i] active %i with crtc active %i\n",
0201 encoder->base.base.id, active,
0202 new_crtc_state->hw.active);
0203
0204 I915_STATE_WARN(active && master_crtc->pipe != pipe,
0205 "Encoder connected to wrong pipe %c\n",
0206 pipe_name(pipe));
0207
0208 if (active)
0209 intel_encoder_get_config(encoder, pipe_config);
0210 }
0211
0212 if (!new_crtc_state->hw.active)
0213 return;
0214
0215 intel_pipe_config_sanity_check(dev_priv, pipe_config);
0216
0217 if (!intel_pipe_config_compare(new_crtc_state,
0218 pipe_config, false)) {
0219 I915_STATE_WARN(1, "pipe state doesn't match!\n");
0220 intel_crtc_state_dump(pipe_config, NULL, "hw state");
0221 intel_crtc_state_dump(new_crtc_state, NULL, "sw state");
0222 }
0223 }
0224
0225 void intel_modeset_verify_crtc(struct intel_crtc *crtc,
0226 struct intel_atomic_state *state,
0227 struct intel_crtc_state *old_crtc_state,
0228 struct intel_crtc_state *new_crtc_state)
0229 {
0230 if (!intel_crtc_needs_modeset(new_crtc_state) && !new_crtc_state->update_pipe)
0231 return;
0232
0233 intel_wm_state_verify(crtc, new_crtc_state);
0234 verify_connector_state(state, crtc);
0235 verify_crtc_state(crtc, old_crtc_state, new_crtc_state);
0236 intel_shared_dpll_state_verify(crtc, old_crtc_state, new_crtc_state);
0237 intel_mpllb_state_verify(state, new_crtc_state);
0238 }
0239
0240 void intel_modeset_verify_disabled(struct drm_i915_private *dev_priv,
0241 struct intel_atomic_state *state)
0242 {
0243 verify_encoder_state(dev_priv, state);
0244 verify_connector_state(state, NULL);
0245 intel_shared_dpll_verify_disabled(dev_priv);
0246 }