[v2,02/12] drm/i915: Update atomic state when removing mst connector.
diff mbox

Message ID 1438000541-3219-3-git-send-email-maarten.lankhorst@linux.intel.com
State New
Headers show

Commit Message

Maarten Lankhorst July 27, 2015, 12:35 p.m. UTC
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
 drivers/gpu/drm/i915/intel_display.c |  7 ------
 drivers/gpu/drm/i915/intel_dp_mst.c  | 45 +++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 8 deletions(-)

Comments

Ander Conselvan de Oliveira July 28, 2015, 12:13 p.m. UTC | #1
Reviewed-by: Ander Conselvan de Oliveira <conselvan2@gmail.com>

On Mon, 2015-07-27 at 14:35 +0200, Maarten Lankhorst wrote:
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>  drivers/gpu/drm/i915/intel_display.c |  7 ------
>  drivers/gpu/drm/i915/intel_dp_mst.c  | 45 
> +++++++++++++++++++++++++++++++++++-
>  2 files changed, 44 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_display.c 
> b/drivers/gpu/drm/i915/intel_display.c
> index 7747520bf9f6..3ab0a8a8e702 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -12751,13 +12751,6 @@ check_encoder_state(struct drm_device *dev)
>  					encoder->base.crtc,
>  			     "connector's crtc doesn't match encoder 
> crtc\n");
>  		}
> -		/*
> -		 * for MST connectors if we unplug the connector is 
> gone
> -		 * away but the encoder is still connected to a crtc
> -		 * until a modeset happens in response to the 
> hotplug.
> -		 */
> -		if (!enabled && encoder->base.encoder_type == 
> DRM_MODE_ENCODER_DPMST)
> -			continue;
>  
>  		I915_STATE_WARN(!!encoder->base.crtc != enabled,
>  		     "encoder's enabled state mismatch "
> diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c 
> b/drivers/gpu/drm/i915/intel_dp_mst.c
> index 585f0a45b3f1..35f2eb59818a 100644
> --- a/drivers/gpu/drm/i915/intel_dp_mst.c
> +++ b/drivers/gpu/drm/i915/intel_dp_mst.c
> @@ -448,6 +448,49 @@ static struct drm_connector 
> *intel_dp_add_mst_connector(struct drm_dp_mst_topolo
>  	return connector;
>  }
>  
> +static void
> +intel_dp_unbind_mst_connector(struct drm_device *dev,
> +			      struct drm_connector *connector)
> +{
> +	struct drm_atomic_state *state;
> +	struct drm_connector_state *conn_state;
> +	struct drm_crtc *crtc = connector->state->crtc;
> +	int ret;
> +
> +	if (!crtc)
> +		return;
> +
> +	state = drm_atomic_state_alloc(dev);
> +	if (!state)
> +		return;
> +
> +	state->acquire_ctx = dev->mode_config.acquire_ctx;
> +
> +	conn_state = drm_atomic_get_connector_state(state, 
> connector);
> +	ret = PTR_ERR_OR_ZERO(conn_state);
> +	if (!ret)
> +		ret = drm_atomic_set_crtc_for_connector(conn_state, 
> NULL);
> +
> +	if (!ret)
> +		ret = drm_atomic_add_affected_connectors(state, 
> crtc);
> +
> +	if (!ret && !drm_atomic_connectors_for_crtc(state, crtc)) {
> +		struct drm_crtc_state *crtc_state =
> +			drm_atomic_get_existing_crtc_state(state, 
> crtc);
> +
> +		crtc_state->active = false;
> +		ret = drm_atomic_set_mode_for_crtc(crtc_state, 
> NULL);
> +	}
> +
> +	if (!ret)
> +		ret = drm_atomic_commit(state);
> +
> +	if (ret)
> +		drm_atomic_state_free(state);
> +
> +	I915_STATE_WARN_ON(ret);
> +}
> +
>  static void intel_dp_destroy_mst_connector(struct 
> drm_dp_mst_topology_mgr *mgr,
>  					   struct drm_connector 
> *connector)
>  {
> @@ -455,7 +498,7 @@ static void intel_dp_destroy_mst_connector(struct 
> drm_dp_mst_topology_mgr *mgr,
>  	struct drm_device *dev = connector->dev;
>  	/* need to nuke the connector */
>  	drm_modeset_lock_all(dev);
> -	intel_connector_dpms(connector, DRM_MODE_DPMS_OFF);
> +	intel_dp_unbind_mst_connector(dev, connector);
>  	drm_modeset_unlock_all(dev);
>  
>  	intel_connector->unregister(intel_connector);
Sivakumar Thulasimani Aug. 6, 2015, 5:34 a.m. UTC | #2
On 7/27/2015 6:05 PM, Maarten Lankhorst wrote:
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/intel_display.c |  7 ------
>   drivers/gpu/drm/i915/intel_dp_mst.c  | 45 +++++++++++++++++++++++++++++++++++-
>   2 files changed, 44 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 7747520bf9f6..3ab0a8a8e702 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -12751,13 +12751,6 @@ check_encoder_state(struct drm_device *dev)
>   					encoder->base.crtc,
>   			     "connector's crtc doesn't match encoder crtc\n");
>   		}
> -		/*
> -		 * for MST connectors if we unplug the connector is gone
> -		 * away but the encoder is still connected to a crtc
> -		 * until a modeset happens in response to the hotplug.
> -		 */
> -		if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
> -			continue;
>   
>   		I915_STATE_WARN(!!encoder->base.crtc != enabled,
>   		     "encoder's enabled state mismatch "
> diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
> index 585f0a45b3f1..35f2eb59818a 100644
> --- a/drivers/gpu/drm/i915/intel_dp_mst.c
> +++ b/drivers/gpu/drm/i915/intel_dp_mst.c
> @@ -448,6 +448,49 @@ static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topolo
>   	return connector;
>   }
>   
> +static void
> +intel_dp_unbind_mst_connector(struct drm_device *dev,
> +			      struct drm_connector *connector)
> +{
> +	struct drm_atomic_state *state;
> +	struct drm_connector_state *conn_state;
> +	struct drm_crtc *crtc = connector->state->crtc;
> +	int ret;
> +
> +	if (!crtc)
> +		return;
> +
why cant we call drm_atomic_helper_set_config with just crtc copied into 
struct drm_mode_set ?
> +	state = drm_atomic_state_alloc(dev);
> +	if (!state)
> +		return;
> +
> +	state->acquire_ctx = dev->mode_config.acquire_ctx;
> +
> +	conn_state = drm_atomic_get_connector_state(state, connector);
> +	ret = PTR_ERR_OR_ZERO(conn_state);
> +	if (!ret)
> +		ret = drm_atomic_set_crtc_for_connector(conn_state, NULL);
> +
> +	if (!ret)
> +		ret = drm_atomic_add_affected_connectors(state, crtc);
> +
> +	if (!ret && !drm_atomic_connectors_for_crtc(state, crtc)) {
> +		struct drm_crtc_state *crtc_state =
> +			drm_atomic_get_existing_crtc_state(state, crtc);
> +
> +		crtc_state->active = false;
> +		ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
> +	}
> +
> +	if (!ret)
> +		ret = drm_atomic_commit(state);
> +
> +	if (ret)
> +		drm_atomic_state_free(state);
> +
> +	I915_STATE_WARN_ON(ret);
> +}
> +
>   static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
>   					   struct drm_connector *connector)
>   {
> @@ -455,7 +498,7 @@ static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
>   	struct drm_device *dev = connector->dev;
>   	/* need to nuke the connector */
>   	drm_modeset_lock_all(dev);
> -	intel_connector_dpms(connector, DRM_MODE_DPMS_OFF);
> +	intel_dp_unbind_mst_connector(dev, connector);
>   	drm_modeset_unlock_all(dev);
>   
>   	intel_connector->unregister(intel_connector);
Maarten Lankhorst Aug. 6, 2015, 7:28 a.m. UTC | #3
Op 06-08-15 om 07:34 schreef Sivakumar Thulasimani:
>
>
> On 7/27/2015 6:05 PM, Maarten Lankhorst wrote:
>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>> ---
>>   drivers/gpu/drm/i915/intel_display.c |  7 ------
>>   drivers/gpu/drm/i915/intel_dp_mst.c  | 45 +++++++++++++++++++++++++++++++++++-
>>   2 files changed, 44 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
>> index 7747520bf9f6..3ab0a8a8e702 100644
>> --- a/drivers/gpu/drm/i915/intel_display.c
>> +++ b/drivers/gpu/drm/i915/intel_display.c
>> @@ -12751,13 +12751,6 @@ check_encoder_state(struct drm_device *dev)
>>                       encoder->base.crtc,
>>                    "connector's crtc doesn't match encoder crtc\n");
>>           }
>> -        /*
>> -         * for MST connectors if we unplug the connector is gone
>> -         * away but the encoder is still connected to a crtc
>> -         * until a modeset happens in response to the hotplug.
>> -         */
>> -        if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
>> -            continue;
>>             I915_STATE_WARN(!!encoder->base.crtc != enabled,
>>                "encoder's enabled state mismatch "
>> diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
>> index 585f0a45b3f1..35f2eb59818a 100644
>> --- a/drivers/gpu/drm/i915/intel_dp_mst.c
>> +++ b/drivers/gpu/drm/i915/intel_dp_mst.c
>> @@ -448,6 +448,49 @@ static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topolo
>>       return connector;
>>   }
>>   +static void
>> +intel_dp_unbind_mst_connector(struct drm_device *dev,
>> +                  struct drm_connector *connector)
>> +{
>> +    struct drm_atomic_state *state;
>> +    struct drm_connector_state *conn_state;
>> +    struct drm_crtc *crtc = connector->state->crtc;
>> +    int ret;
>> +
>> +    if (!crtc)
>> +        return;
>> +
> why cant we call drm_atomic_helper_set_config with just crtc copied into struct drm_mode_set ?

Excellent idea! I think I overengineered this a little by trying to keep the crtc active after disabling if there are other connectors.

However I don't think it's allowed because cloneable is not set on the mst encoder. So new version coming up!

~Maarten

Patch
diff mbox

diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 7747520bf9f6..3ab0a8a8e702 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -12751,13 +12751,6 @@  check_encoder_state(struct drm_device *dev)
 					encoder->base.crtc,
 			     "connector's crtc doesn't match encoder crtc\n");
 		}
-		/*
-		 * for MST connectors if we unplug the connector is gone
-		 * away but the encoder is still connected to a crtc
-		 * until a modeset happens in response to the hotplug.
-		 */
-		if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST)
-			continue;
 
 		I915_STATE_WARN(!!encoder->base.crtc != enabled,
 		     "encoder's enabled state mismatch "
diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c
index 585f0a45b3f1..35f2eb59818a 100644
--- a/drivers/gpu/drm/i915/intel_dp_mst.c
+++ b/drivers/gpu/drm/i915/intel_dp_mst.c
@@ -448,6 +448,49 @@  static struct drm_connector *intel_dp_add_mst_connector(struct drm_dp_mst_topolo
 	return connector;
 }
 
+static void
+intel_dp_unbind_mst_connector(struct drm_device *dev,
+			      struct drm_connector *connector)
+{
+	struct drm_atomic_state *state;
+	struct drm_connector_state *conn_state;
+	struct drm_crtc *crtc = connector->state->crtc;
+	int ret;
+
+	if (!crtc)
+		return;
+
+	state = drm_atomic_state_alloc(dev);
+	if (!state)
+		return;
+
+	state->acquire_ctx = dev->mode_config.acquire_ctx;
+
+	conn_state = drm_atomic_get_connector_state(state, connector);
+	ret = PTR_ERR_OR_ZERO(conn_state);
+	if (!ret)
+		ret = drm_atomic_set_crtc_for_connector(conn_state, NULL);
+
+	if (!ret)
+		ret = drm_atomic_add_affected_connectors(state, crtc);
+
+	if (!ret && !drm_atomic_connectors_for_crtc(state, crtc)) {
+		struct drm_crtc_state *crtc_state =
+			drm_atomic_get_existing_crtc_state(state, crtc);
+
+		crtc_state->active = false;
+		ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
+	}
+
+	if (!ret)
+		ret = drm_atomic_commit(state);
+
+	if (ret)
+		drm_atomic_state_free(state);
+
+	I915_STATE_WARN_ON(ret);
+}
+
 static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
 					   struct drm_connector *connector)
 {
@@ -455,7 +498,7 @@  static void intel_dp_destroy_mst_connector(struct drm_dp_mst_topology_mgr *mgr,
 	struct drm_device *dev = connector->dev;
 	/* need to nuke the connector */
 	drm_modeset_lock_all(dev);
-	intel_connector_dpms(connector, DRM_MODE_DPMS_OFF);
+	intel_dp_unbind_mst_connector(dev, connector);
 	drm_modeset_unlock_all(dev);
 
 	intel_connector->unregister(intel_connector);