All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesse Barnes <jbarnes@virtuousgeek.org>
To: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 30/58] drm/i915: read out the modeset hw state at load and resume time
Date: Wed, 5 Sep 2012 09:14:06 -0700	[thread overview]
Message-ID: <20120905091406.1ade3baa@jbarnes-desktop> (raw)
In-Reply-To: <1345403595-9678-31-git-send-email-daniel.vetter@ffwll.ch>

On Sun, 19 Aug 2012 21:12:47 +0200
Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> +static void
> +intel_connector_break_all_links(struct intel_connector *connector)
> +{
> +	connector->base.dpms = DRM_MODE_DPMS_OFF;
> +	connector->base.encoder = NULL;
> +	connector->encoder->connectors_active = false;
> +	connector->encoder->base.crtc = NULL;
> +}

Maybe connector_clear_state() or init_state()? instead?

> +
> +static void intel_sanitize_crtc(struct intel_crtc *crtc)
> +{
> +	struct drm_device *dev = crtc->base.dev;
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	u32 reg, val;
> +
> +	/* Clear the dpms state for compatibility with code still using that
> +	 * deprecated state variable. */
> +	crtc->dpms_mode = -1;
> +
> +	/* Clear any frame start delays used for debugging left by the BIOS */
> +	reg = PIPECONF(crtc->pipe);
> +	I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
> +
> +	/* We need to sanitize the plane -> pipe mapping first because this will
> +	 * disable the crtc (and hence change the state) if it is wrong. */
> +	if (!HAS_PCH_SPLIT(dev)) {
> +		struct intel_connector *connector;
> +		bool plane;
> +
> +		reg = DSPCNTR(crtc->plane);
> +		val = I915_READ(reg);
> +
> +		if ((val & DISPLAY_PLANE_ENABLE) == 0 &&
> +		    (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
> +			goto ok;
> +
> +		DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
> +			      crtc->base.base.id);
> +
> +		/* Pipe has the wrong plane attached and the plane is active.
> +		 * Temporarily change the plane mapping and disable everything
> +		 * ...  */
> +		plane = crtc->plane;
> +		crtc->plane = !plane;
> +		dev_priv->display.crtc_disable(&crtc->base);
> +		crtc->plane = plane;
> +
> +		/* ... and break all links. */
> +		list_for_each_entry(connector, &dev->mode_config.connector_list,
> +				    base.head) {
> +			if (connector->encoder->base.crtc != &crtc->base)
> +				continue;
> +
> +			intel_connector_break_all_links(connector);
> +		}
> +
> +		WARN_ON(crtc->active);
> +		crtc->base.enabled = false;
> +	}
> +ok:
> +
> +	/* Adjust the state of the output pipe according to whether we
> +	 * have active connectors/encoders. */
> +	intel_crtc_update_dpms(&crtc->base);
> +
> +	if (crtc->active != crtc->base.enabled) {
> +		struct intel_encoder *encoder;
> +
> +		/* This can happen either due to bugs in the get_hw_state
> +		 * functions or because the pipe is force-enabled due to the
> +		 * pipe A quirk. */
> +		DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
> +			      crtc->base.base.id,
> +			      crtc->base.enabled ? "enabled" : "disabled",
> +			      crtc->active ? "enabled" : "disabled");
> +
> +		crtc->base.enabled = crtc->active;
> +
> +		/* Because we only establish the connector -> encoder ->
> +		 * crtc links if something is active, this means the
> +		 * crtc is now deactivated. Break the links. connector
> +		 * -> encoder links are only establish when things are
> +		 *  actually up, hence no need to break them. */
> +		WARN_ON(crtc->active);
> +
> +		for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
> +			WARN_ON(encoder->connectors_active);
> +			encoder->base.crtc = NULL;
> +		}
> +	}
> +}
> +
> +static void intel_sanitize_encoder(struct intel_encoder *encoder)
> +{
> +	struct intel_connector *connector;
> +	struct drm_device *dev = encoder->base.dev;
> +
> +	/* We need to check both for a crtc link (meaning that the
> +	 * encoder is active and trying to read from a pipe) and the
> +	 * pipe itself being active. */
> +	bool has_active_crtc = encoder->base.crtc &&
> +		to_intel_crtc(encoder->base.crtc)->active;
> +
> +	if (encoder->connectors_active && !has_active_crtc) {
> +		DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
> +			      encoder->base.base.id,
> +			      drm_get_encoder_name(&encoder->base));
> +
> +		/* Connector is active, but has no active pipe. This is
> +		 * fallout from our resume register restoring. Disable
> +		 * the encoder manually again. */
> +		if (encoder->base.crtc) {
> +			DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
> +				      encoder->base.base.id,
> +				      drm_get_encoder_name(&encoder->base));
> +			encoder->disable(encoder);
> +		}
> +
> +		/* Inconsisten output/port/pipe state happens presumably due to
> +		 * a bug in one of the get_hw_state functions. Or someplace else
> +		 * in our code, like the register restore mess on resume. Clamp
> +		 * things to off as a safer default. */
> +		list_for_each_entry(connector,
> +				    &dev->mode_config.connector_list,
> +				    base.head) {
> +			if (connector->encoder != encoder)
> +				continue;
> +
> +			intel_connector_break_all_links(connector);
> +		}
> +	}
> +	/* Enabled encoders without active connectors will be fixed in
> +	 * the crtc fixup. */
> +}
> +
> +/* Scan out the current hw modeset state, sanitizes it and maps it into the drm
> + * and i915 state tracking structures. */
> +void intel_modeset_setup_hw_state(struct drm_device *dev)
> +{
> +	struct drm_i915_private *dev_priv = dev->dev_private;
> +	enum pipe pipe;
> +	u32 tmp;
> +	struct intel_crtc *crtc;
> +	struct intel_encoder *encoder;
> +	struct intel_connector *connector;
> +
> +	for_each_pipe(pipe) {
> +		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
> +
> +		tmp = I915_READ(PIPECONF(pipe));
> +		if (tmp & PIPECONF_ENABLE)
> +			crtc->active = true;
> +		else
> +			crtc->active = false;
> +
> +		crtc->base.enabled = crtc->active;
> +
> +		DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
> +			      crtc->base.base.id,
> +			      crtc->active ? "enabled" : "disabled");
> +	}
> +
> +	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
> +			    base.head) {
> +		pipe = 0;
> +
> +		if (encoder->get_hw_state(encoder, &pipe)) {
> +			encoder->base.crtc =
> +				dev_priv->pipe_to_crtc_mapping[pipe];
> +		} else {
> +			encoder->base.crtc = NULL;
> +		}
> +
> +		encoder->connectors_active = false;
> +		DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
> +			      encoder->base.base.id,
> +			      drm_get_encoder_name(&encoder->base),
> +			      encoder->base.crtc ? "enabled" : "disabled",
> +			      pipe);
> +	}
> +
> +	list_for_each_entry(connector, &dev->mode_config.connector_list,
> +			    base.head) {
> +		if (connector->get_hw_state(connector)) {
> +			connector->base.dpms = DRM_MODE_DPMS_ON;
> +			connector->encoder->connectors_active = true;
> +			connector->base.encoder = &connector->encoder->base;
> +		} else {
> +			connector->base.dpms = DRM_MODE_DPMS_OFF;
> +			connector->base.encoder = NULL;
> +		}
> +		DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
> +			      connector->base.base.id,
> +			      drm_get_connector_name(&connector->base),
> +			      connector->base.encoder ? "enabled" : "disabled");
> +	}
> +
> +	/* HW state is read out, now we need to sanitize this mess. */
> +	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
> +			    base.head) {
> +		intel_sanitize_encoder(encoder);
> +	}
> +
> +	for_each_pipe(pipe) {
> +		crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
> +		intel_sanitize_crtc(crtc);
> +	}
> +}

I was going to suggest calling this fetch_hw_state or something, but it
really does do some sanitizing, so maybe setup_hw_state is ok...

Reviewed-by: Jesse Barnes <jbarnes@virtuousgeek.org>

-- 
Jesse Barnes, Intel Open Source Technology Center

  reply	other threads:[~2012-09-05 16:14 UTC|newest]

Thread overview: 173+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-19 19:12 [PATCH 00/58] modeset-rework, the basic conversion Daniel Vetter
2012-08-19 19:12 ` [PATCH 01/58] drm/i915: add crtc->enable/disable vfuncs insted of dpms Daniel Vetter
2012-08-29 17:51   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 02/58] drm/i915: rip out crtc prepare/commit indirection Daniel Vetter
2012-08-29 17:52   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 03/58] drm/i915: add direct encoder disable/enable infrastructure Daniel Vetter
2012-08-29 18:01   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 04/58] drm/i915/hdmi: convert to encoder->disable/enable Daniel Vetter
2012-09-04 19:24   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 05/58] drm/i915/tv: convert to encoder enable/disable Daniel Vetter
2012-09-04 19:25   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 06/58] drm/i915/lvds: convert to encoder disable/enable Daniel Vetter
2012-09-04 19:26   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 07/58] drm/i915/dp: " Daniel Vetter
2012-09-04 19:33   ` Jesse Barnes
2012-09-04 19:42     ` Daniel Vetter
2012-08-19 19:12 ` [PATCH 08/58] drm/i915/crt: " Daniel Vetter
2012-09-04 19:50   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 09/58] drm/i915/sdvo: " Daniel Vetter
2012-09-04 19:52   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 10/58] drm/i915/dvo: " Daniel Vetter
2012-09-04 19:53   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 11/58] drm/i915: convert dpms functions of dvo/sdvo/crt Daniel Vetter
2012-08-29  7:12   ` [PATCH] " Daniel Vetter
2012-09-04 20:10     ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 12/58] drm/i915: rip out encoder->disable/enable checks Daniel Vetter
2012-09-04 20:11   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 13/58] drm/i915: clean up encoder_prepare/commit Daniel Vetter
2012-09-04 20:12   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 14/58] drm/i915: copy&paste drm_crtc_helper_set_config Daniel Vetter
2012-09-04 20:13   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 15/58] drm/i915: call set_base directly Daniel Vetter
2012-09-04 20:15   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 16/58] drm/i915: inline intel_best_encoder Daniel Vetter
2012-09-04 20:18   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 17/58] drm/i915: copy&paste drm_crtc_helper_set_mode Daniel Vetter
2012-09-04 20:19   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 18/58] drm/i915: simplify intel_crtc_prepare_encoders Daniel Vetter
2012-09-04 20:20   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 19/58] drm/i915: rip out encoder->prepare/commit Daniel Vetter
2012-09-04 20:21   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 20/58] drm/i915: call crtc functions directly Daniel Vetter
2012-09-04 20:22   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 21/58] drm/i915: WARN when trying to enabled an unused crtc Daniel Vetter
2012-09-04 20:23   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 22/58] drm/i915: Add interfaces to read out encoder/connector hw state Daniel Vetter
2012-09-04 20:25   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 23/58] drm/i915/dp: implement get_hw_state Daniel Vetter
2012-09-04 20:26   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 24/58] drm/i915/hdmi: " Daniel Vetter
2012-09-04 20:28   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 25/58] drm/i915/tv: " Daniel Vetter
2012-09-04 20:28   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 26/58] drm/i915/lvds: " Daniel Vetter
2012-09-04 20:28   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 27/58] drm/i915/crt: " Daniel Vetter
2012-09-04 20:29   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 28/58] drm/i915/sdvo: " Daniel Vetter
2012-09-04 20:31   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 29/58] drm/i915/dvo: " Daniel Vetter
2012-09-04 20:32   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 30/58] drm/i915: read out the modeset hw state at load and resume time Daniel Vetter
2012-09-05 16:14   ` Jesse Barnes [this message]
2012-08-19 19:12 ` [PATCH 31/58] drm/i915: check connector hw/sw state Daniel Vetter
2012-09-05 16:26   ` Jesse Barnes
2012-09-05 19:10     ` Daniel Vetter
2012-08-19 19:12 ` [PATCH 32/58] drm/i915: rip out intel_crtc->dpms_mode Daniel Vetter
2012-09-05 16:27   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 33/58] drm/i915: rip out intel_dp->dpms_mode Daniel Vetter
2012-09-05 16:28   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 34/58] drm/i915: ensure the force pipe A quirk is actually followed Daniel Vetter
2012-09-05 16:32   ` Jesse Barnes
2012-09-05 19:12     ` Daniel Vetter
2012-08-19 19:12 ` [PATCH 35/58] drm/i915: introduce struct intel_set_config Daniel Vetter
2012-09-05 16:34   ` Jesse Barnes
2012-09-05 19:27     ` Daniel Vetter
2012-08-19 19:12 ` [PATCH 36/58] drm/i915: extract modeset config save/restore code Daniel Vetter
2012-09-05 16:36   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 37/58] drm/i915: extract intel_set_config_compute_mode_changes Daniel Vetter
2012-09-05 16:42   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 38/58] drm/i915: extract intel_set_config_update_output_state Daniel Vetter
2012-09-05 16:44   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 39/58] drm/i915: implement crtc helper semantics relied upon by the fb helper Daniel Vetter
2012-09-05 16:45   ` Jesse Barnes
2012-09-05 19:15     ` Daniel Vetter
2012-08-19 19:12 ` [PATCH 40/58] drm/i915: don't update the fb base if there is no fb Daniel Vetter
2012-09-05 16:47   ` Jesse Barnes
2012-08-19 19:12 ` [PATCH 41/58] drm/i915: convert pointless error checks in set_config to BUGs Daniel Vetter
2012-09-05 16:50   ` Jesse Barnes
2012-09-05 19:19     ` Daniel Vetter
2012-08-19 19:12 ` [PATCH 42/58] drm/i915: don't save all the encoder/crtc state in set_config Daniel Vetter
2012-09-05 16:52   ` Jesse Barnes
2012-09-05 19:21     ` Daniel Vetter
2012-08-19 19:13 ` [PATCH 43/58] drm/i915: stage modeset output changes Daniel Vetter
2012-09-05 17:51   ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 44/58] drm/i915: push crtc->fb update into pipe_set_base Daniel Vetter
2012-09-04 19:33   ` [PATCH] " Daniel Vetter
2012-09-05 17:55     ` Jesse Barnes
2012-09-05 19:59       ` Daniel Vetter
2012-09-05 17:54   ` [PATCH 44/58] " Jesse Barnes
2012-08-19 19:13 ` [PATCH 45/58] drm/i915: remove crtc disabling special case Daniel Vetter
2012-09-05 17:56   ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 46/58] drm/i915: move output commit and crtc disabling into set_mode Daniel Vetter
2012-09-05 17:58   ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 47/58] drm/i915: extract adjusted mode computation Daniel Vetter
2012-09-05 18:00   ` Jesse Barnes
2012-09-05 19:30     ` Daniel Vetter
2012-08-19 19:13 ` [PATCH 48/58] drm/i915: use staged outuput config in tv->mode_fixup Daniel Vetter
2012-09-05 18:02   ` Jesse Barnes
2012-09-06  7:30     ` Daniel Vetter
2012-08-19 19:13 ` [PATCH 49/58] drm/i915: use staged outuput config in lvds->mode_fixup Daniel Vetter
2012-09-05 18:02   ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 50/58] drm/i915: compute masks of crtcs affected in set_mode Daniel Vetter
2012-08-29 10:34   ` [PATCH] " Daniel Vetter
2012-09-05 18:09     ` Jesse Barnes
2012-09-05 19:38       ` Daniel Vetter
2012-09-05 19:45         ` Jesse Barnes
2012-09-05 18:07   ` [PATCH 50/58] " Jesse Barnes
2012-08-19 19:13 ` [PATCH 51/58] drm/i915: implement new set_mode code flow Daniel Vetter
2012-09-05 18:14   ` Jesse Barnes
2012-09-05 19:43     ` Daniel Vetter
2012-09-05 19:49       ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 52/58] drm/i915: push commit_output_state past crtc disabling Daniel Vetter
2012-09-05 18:17   ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 53/58] drm/i915: s/intel_encoder_disable/intel_encoder_noop Daniel Vetter
2012-09-05 18:17   ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 54/58] drm/i915: WARN if the pipe won't turn off Daniel Vetter
2012-09-05 18:18   ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 55/58] drm/i915: switch the load detect code to the staged modeset config Daniel Vetter
2012-09-05 18:19   ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 56/58] drm/i915: push commit_output_state past the crtc/encoder preparing Daniel Vetter
2012-08-31 18:12   ` [PATCH] " Daniel Vetter
2012-09-04 19:32     ` Daniel Vetter
2012-09-05 18:28       ` Jesse Barnes
2012-09-05 19:48         ` Daniel Vetter
2012-09-05 18:56           ` [PATCH] drm/i915: push crtc->fb update into pipe_set_base Daniel Vetter
2012-09-05 19:50           ` [PATCH] drm/i915: push commit_output_state past the crtc/encoder preparing Jesse Barnes
2012-09-06 20:46             ` Jesse Barnes
2012-08-19 19:13 ` [PATCH 57/58] drm/i915: disable all crtcs at suspend time Daniel Vetter
2012-08-29 21:13   ` [PATCH] drm/i915: no longer call drm_helper_resume_force_mode Daniel Vetter
2012-09-05 18:31     ` Jesse Barnes
2012-09-05 19:56       ` Daniel Vetter
2012-09-05 20:04         ` Jesse Barnes
2012-09-06 20:47           ` Jesse Barnes
2012-09-05 18:29   ` [PATCH 57/58] drm/i915: disable all crtcs at suspend time Jesse Barnes
2012-08-19 19:13 ` [PATCH 58/58] drm/i915: add tons of modeset state checks Daniel Vetter
2012-08-20  8:24   ` [PATCH] " Daniel Vetter
2012-08-20 12:22   ` Daniel Vetter
2012-08-31 18:12     ` [PATCH 1/2] " Daniel Vetter
2012-08-31 18:12       ` [PATCH 2/2] drm/i915: improve modeset state checking after dpms calls Daniel Vetter
2012-09-05 18:34         ` Jesse Barnes
2012-09-05 18:33       ` [PATCH 1/2] drm/i915: add tons of modeset state checks Jesse Barnes
2012-08-20 13:17 ` [PATCH 00/58] modeset-rework, the basic conversion Jani Nikula
2012-08-21  3:27 ` Ben Widawsky
2012-08-21 17:48 ` Lespiau, Damien
2012-08-21 18:11   ` Daniel Vetter
2012-08-22 10:46     ` Lespiau, Damien
2012-08-22 11:03       ` Lespiau, Damien
2012-08-22 19:13         ` Lespiau, Damien
2012-08-22 21:21           ` Daniel Vetter
2012-08-23 12:26             ` Lespiau, Damien
2012-08-23 22:39               ` Daniel Vetter
2012-08-29 12:26                 ` Lespiau, Damien
2012-08-30 10:40                   ` Rodrigo Vivi
2012-08-21 19:48 ` Chris Wilson
2012-08-27  8:04 ` Vijay Purushothaman
2012-09-03 17:50 ` Paulo Zanoni
2012-09-05 23:23 ` Jesse Barnes
2012-09-06  6:55   ` Daniel Vetter
2012-09-06  7:23     ` Daniel Vetter
2012-09-07  1:08   ` Jesse Barnes
2012-09-07  8:55     ` Daniel Vetter
2012-09-06 21:00 ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120905091406.1ade3baa@jbarnes-desktop \
    --to=jbarnes@virtuousgeek.org \
    --cc=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.