public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Imre Deak <imre.deak@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 21/23] drm/i915: Add state verification for the TypeC port mode
Date: Tue, 25 Jun 2019 17:12:52 +0300	[thread overview]
Message-ID: <20190625141252.GJ5942@intel.com> (raw)
In-Reply-To: <20190620140600.11357-22-imre.deak@intel.com>

On Thu, Jun 20, 2019 at 05:05:58PM +0300, Imre Deak wrote:
> Add state verification for the TypeC port mode wrt. the port's AUX power
> well enabling/disabling. Also check the correctness of changing the port
> mode:
> - When enabling/disabling the AUX power well for a TypeC port we must hold
>   already the TypeC port lock.
> - When changing the TypeC port mode the port's AUX power domain must be
>   disabled.
> 
> Cc: José Roberto de Souza <jose.souza@intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  .../drm/i915/display/intel_display_power.c    | 99 +++++++++++++++++--
>  drivers/gpu/drm/i915/display/intel_tc.c       |  2 +
>  drivers/gpu/drm/i915/display/intel_tc.h       | 10 +-
>  3 files changed, 102 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_display_power.c b/drivers/gpu/drm/i915/display/intel_display_power.c
> index fd13cd68deae..f4613e10c3b3 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_power.c
> +++ b/drivers/gpu/drm/i915/display/intel_display_power.c
> @@ -17,6 +17,7 @@
>  #include "intel_drv.h"
>  #include "intel_hotplug.h"
>  #include "intel_sideband.h"
> +#include "intel_tc.h"
>  
>  bool intel_display_power_well_is_enabled(struct drm_i915_private *dev_priv,
>  					 enum i915_power_well_id power_well_id);
> @@ -447,26 +448,110 @@ icl_combo_phy_aux_power_well_disable(struct drm_i915_private *dev_priv,
>  #define ICL_TBT_AUX_PW_TO_CH(pw_idx)	\
>  	((pw_idx) - ICL_PW_CTL_IDX_AUX_TBT1 + AUX_CH_C)
>  
> +static enum aux_ch icl_tc_phy_aux_ch(struct drm_i915_private *dev_priv,
> +				     struct i915_power_well *power_well)
> +{
> +	int pw_idx = power_well->desc->hsw.idx;
> +
> +	return power_well->desc->hsw.is_tc_tbt ? ICL_TBT_AUX_PW_TO_CH(pw_idx) :
> +						 ICL_AUX_PW_TO_CH(pw_idx);
> +}
> +
> +#if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
> +
> +static u64 async_put_domains_mask(struct i915_power_domains *power_domains);
> +
> +static int power_well_async_ref_count(struct drm_i915_private *dev_priv,
> +				      struct i915_power_well *power_well)
> +{
> +	enum intel_display_power_domain domain;
> +	u64 async_domains = async_put_domains_mask(&dev_priv->power_domains);
> +	int refs = 0;
> +
> +	for_each_power_domain(domain, power_well->desc->domains)
> +		refs += !!(async_domains & BIT_ULL(domain));
> +
> +	WARN_ON(refs > power_well->count);

hweight64() not sufficient here?

> +
> +	return refs;
> +}
> +
> +static void icl_tc_port_assert_ref_held(struct drm_i915_private *dev_priv,
> +					struct i915_power_well *power_well)
> +{
> +	enum aux_ch aux_ch = icl_tc_phy_aux_ch(dev_priv, power_well);
> +	struct intel_digital_port *dig_port = NULL;
> +	struct intel_encoder *encoder;
> +
> +	/* Bypass the check if all references are released asynchronously */
> +	if (power_well_async_ref_count(dev_priv, power_well) ==
> +	    power_well->count)
> +		return;
> +
> +	aux_ch = icl_tc_phy_aux_ch(dev_priv, power_well);
> +
> +	for_each_intel_encoder(&dev_priv->drm, encoder) {
> +		if (!intel_port_is_tc(dev_priv, encoder->port))
> +			continue;
> +
> +		/* We'll check the MST primary port */
> +		if (encoder->type == INTEL_OUTPUT_DP_MST)
> +			continue;
> +
> +		dig_port = enc_to_dig_port(&encoder->base);
> +		if (WARN_ON(!dig_port))
> +			continue;
> +
> +		if (dig_port->aux_ch != aux_ch) {
> +			dig_port = NULL;
> +			continue;
> +		}
> +
> +		break;
> +	}
> +
> +	if (WARN_ON(!dig_port))
> +		return;
> +
> +	WARN_ON(!intel_tc_port_ref_held(dig_port));
> +}
> +
> +#else
> +
> +static void icl_tc_port_assert_ref_held(struct drm_i915_private *dev_priv,
> +					struct i915_power_well *power_well)
> +{
> +}
> +
> +#endif
> +
>  static void
>  icl_tc_phy_aux_power_well_enable(struct drm_i915_private *dev_priv,
>  				 struct i915_power_well *power_well)
>  {
> -	int pw_idx = power_well->desc->hsw.idx;
> -	bool is_tbt = power_well->desc->hsw.is_tc_tbt;
> -	enum aux_ch aux_ch;
> +	enum aux_ch aux_ch = icl_tc_phy_aux_ch(dev_priv, power_well);
>  	u32 val;
>  
> -	aux_ch = is_tbt ? ICL_TBT_AUX_PW_TO_CH(pw_idx) :
> -			  ICL_AUX_PW_TO_CH(pw_idx);
> +	icl_tc_port_assert_ref_held(dev_priv, power_well);
> +
>  	val = I915_READ(DP_AUX_CH_CTL(aux_ch));
>  	val &= ~DP_AUX_CH_CTL_TBT_IO;
> -	if (is_tbt)
> +	if (power_well->desc->hsw.is_tc_tbt)
>  		val |= DP_AUX_CH_CTL_TBT_IO;
>  	I915_WRITE(DP_AUX_CH_CTL(aux_ch), val);
>  
>  	hsw_power_well_enable(dev_priv, power_well);
>  }
>  
> +static void
> +icl_tc_phy_aux_power_well_disable(struct drm_i915_private *dev_priv,
> +				  struct i915_power_well *power_well)
> +{
> +	icl_tc_port_assert_ref_held(dev_priv, power_well);
> +
> +	hsw_power_well_disable(dev_priv, power_well);
> +}
> +
>  /*
>   * We should only use the power well if we explicitly asked the hardware to
>   * enable it, so check if it's enabled and also check if we've requested it to
> @@ -3119,7 +3204,7 @@ static const struct i915_power_well_ops icl_combo_phy_aux_power_well_ops = {
>  static const struct i915_power_well_ops icl_tc_phy_aux_power_well_ops = {
>  	.sync_hw = hsw_power_well_sync_hw,
>  	.enable = icl_tc_phy_aux_power_well_enable,
> -	.disable = hsw_power_well_disable,
> +	.disable = icl_tc_phy_aux_power_well_disable,
>  	.is_enabled = hsw_power_well_enabled,
>  };
>  
> diff --git a/drivers/gpu/drm/i915/display/intel_tc.c b/drivers/gpu/drm/i915/display/intel_tc.c
> index c8904911e841..6c43becf97f7 100644
> --- a/drivers/gpu/drm/i915/display/intel_tc.c
> +++ b/drivers/gpu/drm/i915/display/intel_tc.c
> @@ -303,6 +303,8 @@ static void intel_tc_port_reset_mode(struct intel_digital_port *dig_port,
>  	enum tc_port_mode old_tc_mode = dig_port->tc_mode;
>  
>  	intel_display_power_flush_work(dev_priv);
> +	WARN_ON(intel_display_power_is_enabled(dev_priv,
> +					       intel_aux_power_domain(dig_port)));
>  
>  	icl_tc_phy_disconnect(dig_port);
>  	icl_tc_phy_connect(dig_port, required_lanes);
> diff --git a/drivers/gpu/drm/i915/display/intel_tc.h b/drivers/gpu/drm/i915/display/intel_tc.h
> index 31af7be96070..8adc107cdbcb 100644
> --- a/drivers/gpu/drm/i915/display/intel_tc.h
> +++ b/drivers/gpu/drm/i915/display/intel_tc.h
> @@ -7,8 +7,8 @@
>  #define __INTEL_TC_H__
>  
>  #include <linux/types.h>
> -
> -struct intel_digital_port;
> +#include <linux/mutex.h>
> +#include "intel_drv.h"
>  
>  void icl_tc_phy_disconnect(struct intel_digital_port *dig_port);
>  
> @@ -23,6 +23,12 @@ void intel_tc_port_get_link(struct intel_digital_port *dig_port,
>  			    int required_lanes);
>  void intel_tc_port_put_link(struct intel_digital_port *dig_port);
>  
> +static inline int intel_tc_port_ref_held(struct intel_digital_port *dig_port)
> +{
> +	return mutex_is_locked(&dig_port->tc_lock) ||
> +	       dig_port->tc_link_refcount;

This will allow tc_lock to not be held if the refcount is elevated. Was
that the intention? The commit message says the lock should always be
held.

Should we do a lockdep assert here if lockdep is enabled?

> +}
> +
>  void intel_tc_port_init(struct intel_digital_port *dig_port, bool is_legacy);
>  
>  #endif /* __INTEL_TC_H__ */
> -- 
> 2.17.1
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2019-06-25 14:12 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-20 14:05 [PATCH v2 00/23] drm/i915: Fix TypeC port mode switching Imre Deak
2019-06-20 14:05 ` [PATCH v2 01/23] drm/i915/icl: Add support to read out the TBT PLL HW state Imre Deak
2019-06-20 14:05 ` [PATCH v2 02/23] drm/i915: Tune down WARNs about TBT AUX power well enabling Imre Deak
2019-06-20 14:05 ` [PATCH v2 03/23] drm/i915: Move the TypeC port handling code to a separate file Imre Deak
2019-06-20 14:05 ` [PATCH v2 04/23] drm/i915: Sanitize the terminology used for TypeC port modes Imre Deak
2019-06-20 14:05 ` [PATCH v2 05/23] drm/i915: Don't enable the DDI-IO power in the TypeC TBT-alt mode Imre Deak
2019-06-20 14:05 ` [PATCH v2 06/23] drm/i915: Fix the TBT AUX power well enabling Imre Deak
2019-06-20 14:05 ` [PATCH v2 07/23] drm/i915: Use the correct AUX power domain in TypeC TBT-alt mode Imre Deak
2019-06-20 14:05 ` [PATCH v2 08/23] drm/i915: Unify the TypeC port notation in debug/error messages Imre Deak
2019-06-20 14:05 ` [PATCH v2 09/23] drm/i915: Factor out common parts from TypeC port handling functions Imre Deak
2019-06-25 13:05   ` Ville Syrjälä
2019-06-25 13:48     ` Imre Deak
2019-06-26 20:50   ` [CI v3 " Imre Deak
2019-06-26 22:55     ` Souza, Jose
2019-06-27 10:34       ` Imre Deak
2019-06-20 14:05 ` [PATCH v2 10/23] drm/i915: Wait for TypeC PHY complete flag to clear in safe mode Imre Deak
2019-06-20 14:05 ` [PATCH v2 11/23] drm/i915: Handle the TCCOLD power-down event Imre Deak
2019-06-25 13:17   ` Ville Syrjälä
2019-06-25 14:22     ` Imre Deak
2019-06-26 20:50   ` [CI v3 " Imre Deak
2019-06-20 14:05 ` [PATCH v2 12/23] drm/i915: Sanitize the TypeC connect/detect sequences Imre Deak
2019-06-25 13:42   ` Ville Syrjälä
2019-06-25 18:30     ` Imre Deak
2019-06-26 11:51       ` Ville Syrjälä
2019-06-26 23:55   ` Souza, Jose
2019-06-27  9:48     ` Imre Deak
2019-06-27 21:06       ` Souza, Jose
2019-06-20 14:05 ` [PATCH v2 13/23] drm/i915: Fix the TypeC port mode sanitization during loading/resume Imre Deak
2019-06-26 18:04   ` [PATCH v3 " Imre Deak
2019-06-26 20:50   ` [CI " Imre Deak
2019-06-27 20:38     ` Souza, Jose
2019-06-20 14:05 ` [PATCH v2 14/23] drm/i915: Keep the TypeC port mode fixed for detect/AUX transfers Imre Deak
2019-06-25 13:43   ` Ville Syrjälä
2019-06-20 14:05 ` [PATCH v2 15/23] drm/i915: Sanitize the TypeC FIA lane configuration decoding Imre Deak
2019-06-20 14:05 ` [PATCH v2 16/23] drm/i915: Sanitize the shared DPLL reserve/release interface Imre Deak
2019-06-25 13:53   ` Ville Syrjälä
2019-06-25 18:57     ` Imre Deak
2019-06-25 19:48       ` Imre Deak
2019-06-20 14:05 ` [PATCH v2 17/23] drm/i915: Sanitize the shared DPLL find/reference interface Imre Deak
2019-06-25 13:54   ` Ville Syrjälä
2019-06-20 14:05 ` [PATCH v2 18/23] drm/i915/icl: Split getting the DPLLs to port type specific functions Imre Deak
2019-06-25 13:55   ` Ville Syrjälä
2019-06-20 14:05 ` [PATCH v2 19/23] drm/i915/icl: Reserve all required PLLs for TypeC ports Imre Deak
2019-06-25 13:58   ` Ville Syrjälä
2019-06-20 14:05 ` [PATCH v2 20/23] drm/i915: Keep the TypeC port mode fixed when the port is active Imre Deak
2019-06-25 14:01   ` Ville Syrjälä
2019-06-20 14:05 ` [PATCH v2 21/23] drm/i915: Add state verification for the TypeC port mode Imre Deak
2019-06-25 14:12   ` Ville Syrjälä [this message]
2019-06-25 19:23     ` Imre Deak
2019-06-26 11:52       ` Ville Syrjälä
2019-06-26 18:04   ` [v3 " Imre Deak
2019-06-26 20:50   ` [CI v3 " Imre Deak
2019-06-20 14:05 ` [PATCH v2 22/23] drm/i915: Remove unneeded disconnect in TypeC legacy " Imre Deak
2019-06-20 14:06 ` [PATCH v2 23/23] drm/i915: WARN about invalid lane reversal in TBT-alt/DP-alt modes Imre Deak
2019-06-20 17:23 ` ✗ Fi.CI.CHECKPATCH: warning for drm/i915: Fix TypeC port mode switching (rev3) Patchwork
2019-06-20 17:32 ` ✗ Fi.CI.SPARSE: " Patchwork
2019-06-20 18:05 ` ✓ Fi.CI.BAT: success " Patchwork
2019-06-20 22:42 ` ✓ Fi.CI.IGT: " Patchwork
2019-06-26 22:00 ` ✗ Fi.CI.BAT: failure for drm/i915: Fix TypeC port mode switching (rev7) Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2019-06-26 18:04 [PATCH v3 09/23] drm/i915: Factor out common parts from TypeC port handling functions Imre Deak
2019-06-26 18:04 ` [PATCH v3 11/23] drm/i915: Handle the TCCOLD power-down event Imre Deak
2019-06-26 22:12   ` Souza, Jose
2019-06-27 10:09     ` Imre Deak
2019-06-27 12:59       ` Ville Syrjälä

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=20190625141252.GJ5942@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=imre.deak@intel.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox