]> Pileus Git - ~andy/linux/blobdiff - drivers/gpu/drm/i915/intel_display.c
drm/i915: WARN if the pipe won't turn off
[~andy/linux] / drivers / gpu / drm / i915 / intel_display.c
index d354aa0b8eed3ab3e9c4f53b369264e97e651f07..453bc7cf1841ac18f3fcfdf364e2b360472dec26 100644 (file)
@@ -1006,7 +1006,7 @@ void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
                /* Wait for the Pipe State to go off */
                if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
                             100))
-                       DRM_DEBUG_KMS("pipe_off wait timed out\n");
+                       WARN(1, "pipe_off wait timed out\n");
        } else {
                u32 last_line, line_mask;
                int reg = PIPEDSL(pipe);
@@ -1024,7 +1024,7 @@ void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
                } while (((I915_READ(reg) & line_mask) != last_line) &&
                         time_after(timeout, jiffies));
                if (time_after(jiffies, timeout))
-                       DRM_DEBUG_KMS("pipe_off wait timed out\n");
+                       WARN(1, "pipe_off wait timed out\n");
        }
 }
 
@@ -3462,26 +3462,13 @@ static void i9xx_crtc_off(struct drm_crtc *crtc)
 {
 }
 
-/**
- * Sets the power management mode of the pipe and plane.
- */
-void intel_crtc_update_dpms(struct drm_crtc *crtc)
+static void intel_crtc_update_sarea(struct drm_crtc *crtc,
+                                   bool enabled)
 {
        struct drm_device *dev = crtc->dev;
-       struct drm_i915_private *dev_priv = dev->dev_private;
        struct drm_i915_master_private *master_priv;
        struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-       struct intel_encoder *intel_encoder;
        int pipe = intel_crtc->pipe;
-       bool enabled, enable = false;
-
-       for_each_encoder_on_crtc(dev, crtc, intel_encoder)
-               enable |= intel_encoder->connectors_active;
-
-       if (enable)
-               dev_priv->display.crtc_enable(crtc);
-       else
-               dev_priv->display.crtc_disable(crtc);
 
        if (!dev->primary->master)
                return;
@@ -3490,8 +3477,6 @@ void intel_crtc_update_dpms(struct drm_crtc *crtc)
        if (!master_priv->sarea_priv)
                return;
 
-       enabled = crtc->enabled && enable;
-
        switch (pipe) {
        case 0:
                master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
@@ -3507,14 +3492,42 @@ void intel_crtc_update_dpms(struct drm_crtc *crtc)
        }
 }
 
+/**
+ * Sets the power management mode of the pipe and plane.
+ */
+void intel_crtc_update_dpms(struct drm_crtc *crtc)
+{
+       struct drm_device *dev = crtc->dev;
+       struct drm_i915_private *dev_priv = dev->dev_private;
+       struct intel_encoder *intel_encoder;
+       bool enable = false;
+
+       for_each_encoder_on_crtc(dev, crtc, intel_encoder)
+               enable |= intel_encoder->connectors_active;
+
+       if (enable)
+               dev_priv->display.crtc_enable(crtc);
+       else
+               dev_priv->display.crtc_disable(crtc);
+
+       intel_crtc_update_sarea(crtc, enable);
+}
+
+static void intel_crtc_noop(struct drm_crtc *crtc)
+{
+}
+
 static void intel_crtc_disable(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
+       struct drm_connector *connector;
        struct drm_i915_private *dev_priv = dev->dev_private;
 
-       /* crtc->disable is only called when we have no encoders, hence this
-        * will disable the pipe. */
-       intel_crtc_update_dpms(crtc);
+       /* crtc should still be enabled when we disable it. */
+       WARN_ON(!crtc->enabled);
+
+       dev_priv->display.crtc_disable(crtc);
+       intel_crtc_update_sarea(crtc, false);
        dev_priv->display.off(crtc);
 
        assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
@@ -3524,14 +3537,24 @@ static void intel_crtc_disable(struct drm_crtc *crtc)
                mutex_lock(&dev->struct_mutex);
                intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
                mutex_unlock(&dev->struct_mutex);
+               crtc->fb = NULL;
+       }
+
+       /* Update computed state. */
+       list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
+               if (!connector->encoder || !connector->encoder->crtc)
+                       continue;
+
+               if (connector->encoder->crtc != crtc)
+                       continue;
+
+               connector->dpms = DRM_MODE_DPMS_OFF;
+               to_intel_encoder(connector->encoder)->connectors_active = false;
        }
 }
 
-void intel_encoder_disable(struct drm_encoder *encoder)
+void intel_encoder_noop(struct drm_encoder *encoder)
 {
-       struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
-
-       intel_encoder->disable(intel_encoder);
 }
 
 void intel_encoder_destroy(struct drm_encoder *encoder)
@@ -6560,7 +6583,7 @@ free_work:
 static struct drm_crtc_helper_funcs intel_helper_funcs = {
        .mode_set_base_atomic = intel_pipe_set_base_atomic,
        .load_lut = intel_crtc_load_lut,
-       .disable = intel_crtc_disable,
+       .disable = intel_crtc_noop,
 };
 
 bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
@@ -6798,6 +6821,12 @@ intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
        *prepare_pipes &= ~(*disable_pipes);
 }
 
+#define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
+       list_for_each_entry((intel_crtc), \
+                           &(dev)->mode_config.crtc_list, \
+                           base.head) \
+               if (mask & (1 <<(intel_crtc)->pipe)) \
+
 bool intel_set_mode(struct drm_crtc *crtc,
                    struct drm_display_mode *mode,
                    int x, int y, struct drm_framebuffer *fb)
@@ -6807,73 +6836,94 @@ bool intel_set_mode(struct drm_crtc *crtc,
        struct drm_display_mode *adjusted_mode, saved_mode, saved_hwmode;
        struct drm_encoder_helper_funcs *encoder_funcs;
        struct drm_encoder *encoder;
-       unsigned disable_pipe, prepare_pipes, modeset_pipes;
+       struct intel_crtc *intel_crtc;
+       unsigned disable_pipes, prepare_pipes, modeset_pipes;
        bool ret = true;
 
        intel_modeset_affected_pipes(crtc, &modeset_pipes,
-                                    &prepare_pipes, &disable_pipe);
+                                    &prepare_pipes, &disable_pipes);
 
-       intel_modeset_commit_output_state(dev);
+       DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
+                     modeset_pipes, prepare_pipes, disable_pipes);
 
-       crtc->enabled = drm_helper_crtc_in_use(crtc);
-       if (!crtc->enabled) {
-               drm_helper_disable_unused_functions(dev);
-               return true;
-       }
+       for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
+               intel_crtc_disable(&intel_crtc->base);
 
+       intel_modeset_commit_output_state(dev);
+
+       list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
+                           base.head)
+               intel_crtc->base.enabled = drm_helper_crtc_in_use(crtc);
 
        saved_hwmode = crtc->hwmode;
        saved_mode = crtc->mode;
 
-       adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
-       if (IS_ERR(adjusted_mode)) {
-               return false;
-       }
+       /* Hack: Because we don't (yet) support global modeset on multiple
+        * crtcs, we don't keep track of the new mode for more than one crtc.
+        * Hence simply check whether any bit is set in modeset_pipes in all the
+        * pieces of code that are not yet converted to deal with mutliple crtcs
+        * changing their mode at the same time. */
+       adjusted_mode = NULL;
+       if (modeset_pipes) {
+               adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
+               if (IS_ERR(adjusted_mode)) {
+                       return false;
+               }
 
-       intel_crtc_prepare_encoders(dev);
+               intel_crtc_prepare_encoders(dev);
+       }
 
-       dev_priv->display.crtc_disable(crtc);
+       for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
+               dev_priv->display.crtc_disable(&intel_crtc->base);
 
-       crtc->mode = *mode;
+       if (modeset_pipes) {
+               crtc->mode = *mode;
+               crtc->x = x;
+               crtc->y = y;
+       }
 
        /* Set up the DPLL and any encoders state that needs to adjust or depend
         * on the DPLL.
         */
-       ret = !intel_crtc_mode_set(crtc, mode, adjusted_mode, x, y, fb);
-       if (!ret)
-           goto done;
+       for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
+               ret = !intel_crtc_mode_set(&intel_crtc->base,
+                                          mode, adjusted_mode,
+                                          x, y, fb);
+               if (!ret)
+                   goto done;
 
-       list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
+               list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
 
-               if (encoder->crtc != crtc)
-                       continue;
+                       if (encoder->crtc != &intel_crtc->base)
+                               continue;
 
-               DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
-                       encoder->base.id, drm_get_encoder_name(encoder),
-                       mode->base.id, mode->name);
-               encoder_funcs = encoder->helper_private;
-               encoder_funcs->mode_set(encoder, mode, adjusted_mode);
+                       DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
+                               encoder->base.id, drm_get_encoder_name(encoder),
+                               mode->base.id, mode->name);
+                       encoder_funcs = encoder->helper_private;
+                       encoder_funcs->mode_set(encoder, mode, adjusted_mode);
+               }
        }
 
-       crtc->x = x;
-       crtc->y = y;
-
        /* Now enable the clocks, plane, pipe, and connectors that we set up. */
-       dev_priv->display.crtc_enable(crtc);
+       for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
+               dev_priv->display.crtc_enable(&intel_crtc->base);
 
-       /* Store real post-adjustment hardware mode. */
-       crtc->hwmode = *adjusted_mode;
+       if (modeset_pipes) {
+               /* Store real post-adjustment hardware mode. */
+               crtc->hwmode = *adjusted_mode;
 
-       /* Calculate and store various constants which
-        * are later needed by vblank and swap-completion
-        * timestamping. They are derived from true hwmode.
-        */
-       drm_calc_timestamping_constants(crtc);
+               /* Calculate and store various constants which
+                * are later needed by vblank and swap-completion
+                * timestamping. They are derived from true hwmode.
+                */
+               drm_calc_timestamping_constants(crtc);
+       }
 
        /* FIXME: add subpixel order */
 done:
        drm_mode_destroy(dev, adjusted_mode);
-       if (!ret) {
+       if (!ret && crtc->enabled) {
                crtc->hwmode = saved_hwmode;
                crtc->mode = saved_mode;
        }
@@ -6881,6 +6931,8 @@ done:
        return ret;
 }
 
+#undef for_each_intel_crtc_masked
+
 static void intel_set_config_free(struct intel_set_config *config)
 {
        if (!config)