diff mbox

[4/5] drm: Use mode_valid() in atomic modeset

Message ID dbb5d122bc0cd78916a4b6788b8ab250f43591d2.1493906290.git.joabreu@synopsys.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jose Abreu May 4, 2017, 2:11 p.m. UTC
This patches makes use of the new mode_valid() callbacks introduced
previously to validate the full video pipeline when modesetting.

This calls the connector->mode_valid(), encoder->mode_valid(),
bridge->mode_valid() and crtc->mode_valid() so that we can
make sure that the mode will be accepted in every components.

Signed-off-by: Jose Abreu <joabreu@synopsys.com>
Cc: Carlos Palminha <palminha@synopsys.com>
Cc: Alexey Brodkin <abrodkin@synopsys.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Dave Airlie <airlied@linux.ie>
Cc: Andrzej Hajda <a.hajda@samsung.com>
Cc: Archit Taneja <architt@codeaurora.org>
---
 drivers/gpu/drm/drm_atomic_helper.c | 92 +++++++++++++++++++++++++++++++++++--
 1 file changed, 89 insertions(+), 3 deletions(-)

Comments

Jose Abreu May 4, 2017, 3:13 p.m. UTC | #1
Hi Ville,


On 04-05-2017 15:40, Ville Syrjälä wrote:
> On Thu, May 04, 2017 at 03:11:41PM +0100, Jose Abreu wrote:
>> This patches makes use of the new mode_valid() callbacks introduced
>> previously to validate the full video pipeline when modesetting.
>>
>> This calls the connector->mode_valid(), encoder->mode_valid(),
>> bridge->mode_valid() and crtc->mode_valid() so that we can
>> make sure that the mode will be accepted in every components.
>>
>> Signed-off-by: Jose Abreu <joabreu@synopsys.com>
>> Cc: Carlos Palminha <palminha@synopsys.com>
>> Cc: Alexey Brodkin <abrodkin@synopsys.com>
>> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
>> Cc: Dave Airlie <airlied@linux.ie>
>> Cc: Andrzej Hajda <a.hajda@samsung.com>
>> Cc: Archit Taneja <architt@codeaurora.org>
>> ---
>>  drivers/gpu/drm/drm_atomic_helper.c | 92 +++++++++++++++++++++++++++++++++++--
>>  1 file changed, 89 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
>> index 8be9719..6eb305d 100644
>> --- a/drivers/gpu/drm/drm_atomic_helper.c
>> +++ b/drivers/gpu/drm/drm_atomic_helper.c
>> @@ -452,6 +452,85 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
>>  	return 0;
>>  }
>>  
>> +static enum drm_mode_status mode_valid_pipe(struct drm_connector *connector,
> The name feels off. Pipe means crtc for i915, and for drm_irq.c as well.

Hmmm, mode_valid_path, mode_valid_components ?

>
>> +					    struct drm_encoder *encoder,
>> +					    struct drm_crtc *crtc,
>> +					    struct drm_display_mode *mode)
>> +{
>> +	const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
>> +	const struct drm_connector_helper_funcs *connector_funcs =
>> +		connector->helper_private;
>> +	const struct drm_encoder_helper_funcs *encoder_funcs =
>> +		encoder->helper_private;
>> +	enum drm_mode_status ret = MODE_OK;
>> +
>> +	if (connector_funcs && connector_funcs->mode_valid)
>> +		ret = connector_funcs->mode_valid(connector, mode);
> As I mentioned earlier, this would break i915. We either can't call the 
> connector hook at all here, or we have to make it somehow opt-in if some
> drivers really want to do it.

Ok. You said you let users exceed the limits, but why doesn't it
fail in atomic_check and will fail in mode_valid? I guess I can
remove it, but this can lead to lots of confusion, i.e. with this
series the mode_valid callbacks for all components are called, if
I remove just one call the whole point will fall apart.

Can we think about something else ? I think making it opt-in is
not ideal, if the helper is there then it should be used, but if
thats the best solution then shall we add a flag which will call
or not *all* the mode_valid callbacks in this stage
(drm_device.allow_modevalid_call, ...) ?

>
>> +
>> +	if (ret != MODE_OK) {
>> +		DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] mode_valid() failed\n",
>> +				connector->base.id, connector->name);
>> +		return ret;
>> +	}
>> +
>> +	if (encoder_funcs && encoder_funcs->mode_valid)
>> +		ret = encoder_funcs->mode_valid(encoder, mode);
>> +
>> +	if (ret != MODE_OK) {
>> +		DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] mode_valid() failed\n",
>> +				encoder->base.id, encoder->name);
>> +		return ret;
>> +	}
>> +
>> +	ret = drm_bridge_mode_valid(encoder->bridge, mode);
>> +	if (ret != MODE_OK) {
>> +		DRM_DEBUG_ATOMIC("[BRIDGE] mode_valid() failed\n");
>> +		return ret;
>> +	}
>> +
>> +	if (crtc_funcs && crtc_funcs->mode_valid)
>> +		ret = crtc_funcs->mode_valid(crtc, mode);
>> +
>> +	if (ret != MODE_OK) {
>> +		DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode_valid() failed\n",
>> +				crtc->base.id, crtc->name);
>> +		return ret;
>> +	}
>> +
>> +	return ret;
>> +}
>> +
>> +static int
>> +mode_valid(struct drm_atomic_state *state)
>> +{
>> +	struct drm_connector_state *conn_state;
>> +	struct drm_connector *connector;
>> +	int i;
>> +
>> +	for_each_connector_in_state(state, connector, conn_state, i) {
> for_each_new...

Ok.

>
>> +		struct drm_encoder *encoder = conn_state->best_encoder;
>> +		struct drm_crtc *crtc = conn_state->crtc;
>> +		struct drm_crtc_state *crtc_state;
>> +		enum drm_mode_status mode_status;
>> +		struct drm_display_mode *mode;
>> +
>> +		if (!crtc || !encoder)
>> +			continue;
>> +
>> +		crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
>> +		if (!crtc_state)
>> +			continue;
>
> Maybe?
>
> if (!mode_changed && !connectors_changed)
> 	continue;

Yes, no point in checking if the mode and connector didn't change.

>
>> +
>> +		mode = &crtc_state->mode;
> Seems like a fairly pointless variable.

Yeah, this was to avoid the next function call to exceed 80
chars, I don't really like line breaks :) Thanks for the review!

Best regards,
Jose Miguel Abreu

>
>> +
>> +		mode_status = mode_valid_pipe(connector, encoder, crtc, mode);
>> +		if (mode_status != MODE_OK)
>> +			return -EINVAL;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>>  /**
>>   * drm_atomic_helper_check_modeset - validate state object for modeset changes
>>   * @dev: DRM device
>> @@ -466,13 +545,16 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
>>   * 2. &drm_connector_helper_funcs.atomic_check to validate the connector state.
>>   * 3. If it's determined a modeset is needed then all connectors on the affected crtc
>>   *    crtc are added and &drm_connector_helper_funcs.atomic_check is run on them.
>> - * 4. &drm_bridge_funcs.mode_fixup is called on all encoder bridges.
>> - * 5. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state.
>> + * 4. &drm_connector_helper_funcs.mode_valid, &drm_encoder_helper_funcs.mode_valid,
>> + *    &drm_bridge_funcs.mode_valid and &drm_crtc_helper_funcs.mode_valid are called
>> + *    on the affected components.
>> + * 5. &drm_bridge_funcs.mode_fixup is called on all encoder bridges.
>> + * 6. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state.
>>   *    This function is only called when the encoder will be part of a configured crtc,
>>   *    it must not be used for implementing connector property validation.
>>   *    If this function is NULL, &drm_atomic_encoder_helper_funcs.mode_fixup is called
>>   *    instead.
>> - * 6. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints.
>> + * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints.
>>   *
>>   * &drm_crtc_state.mode_changed is set when the input mode is changed.
>>   * &drm_crtc_state.connectors_changed is set when a connector is added or
>> @@ -617,6 +699,10 @@ static int handle_conflicting_encoders(struct drm_atomic_state *state,
>>  			return ret;
>>  	}
>>  
>> +	ret = mode_valid(state);
>> +	if (ret)
>> +		return ret;
>> +
>>  	return mode_fixup(state);
>>  }
>>  EXPORT_SYMBOL(drm_atomic_helper_check_modeset);
>> -- 
>> 1.9.1
>>
Daniel Vetter May 8, 2017, 7:55 a.m. UTC | #2
On Thu, May 04, 2017 at 04:13:51PM +0100, Jose Abreu wrote:
> On 04-05-2017 15:40, Ville Syrjälä wrote:
> > On Thu, May 04, 2017 at 03:11:41PM +0100, Jose Abreu wrote:
> >> +					    struct drm_encoder *encoder,
> >> +					    struct drm_crtc *crtc,
> >> +					    struct drm_display_mode *mode)
> >> +{
> >> +	const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
> >> +	const struct drm_connector_helper_funcs *connector_funcs =
> >> +		connector->helper_private;
> >> +	const struct drm_encoder_helper_funcs *encoder_funcs =
> >> +		encoder->helper_private;
> >> +	enum drm_mode_status ret = MODE_OK;
> >> +
> >> +	if (connector_funcs && connector_funcs->mode_valid)
> >> +		ret = connector_funcs->mode_valid(connector, mode);
> > As I mentioned earlier, this would break i915. We either can't call the 
> > connector hook at all here, or we have to make it somehow opt-in if some
> > drivers really want to do it.
> 
> Ok. You said you let users exceed the limits, but why doesn't it
> fail in atomic_check and will fail in mode_valid? I guess I can
> remove it, but this can lead to lots of confusion, i.e. with this
> series the mode_valid callbacks for all components are called, if
> I remove just one call the whole point will fall apart.
> 
> Can we think about something else ? I think making it opt-in is
> not ideal, if the helper is there then it should be used, but if
> thats the best solution then shall we add a flag which will call
> or not *all* the mode_valid callbacks in this stage
> (drm_device.allow_modevalid_call, ...) ?

This is a general issue, not a driver opt-in. With your new callbacks
ideally we'll have:
- all the source checks (clock limits, size limits) are in the
  crtc/encoder/bridge callbacks
- only the sink limit checks (derived from edid or DP aux) are in the
  connector callback

Letting userspace overwrite these seems like a reasonable idea that we
should support in general I think. See also my comment on patch 1 for the
connector's mode_valid kerneldoc.

For arcpgu that might mean that you need to move part of the connector's
mode_valid checks into the encoder, but since all the encoder modeset is
in there already, that seems like a good cleanup of the drm modeset
framework.
-Daniel
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 8be9719..6eb305d 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -452,6 +452,85 @@  static int handle_conflicting_encoders(struct drm_atomic_state *state,
 	return 0;
 }
 
+static enum drm_mode_status mode_valid_pipe(struct drm_connector *connector,
+					    struct drm_encoder *encoder,
+					    struct drm_crtc *crtc,
+					    struct drm_display_mode *mode)
+{
+	const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
+	const struct drm_connector_helper_funcs *connector_funcs =
+		connector->helper_private;
+	const struct drm_encoder_helper_funcs *encoder_funcs =
+		encoder->helper_private;
+	enum drm_mode_status ret = MODE_OK;
+
+	if (connector_funcs && connector_funcs->mode_valid)
+		ret = connector_funcs->mode_valid(connector, mode);
+
+	if (ret != MODE_OK) {
+		DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] mode_valid() failed\n",
+				connector->base.id, connector->name);
+		return ret;
+	}
+
+	if (encoder_funcs && encoder_funcs->mode_valid)
+		ret = encoder_funcs->mode_valid(encoder, mode);
+
+	if (ret != MODE_OK) {
+		DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] mode_valid() failed\n",
+				encoder->base.id, encoder->name);
+		return ret;
+	}
+
+	ret = drm_bridge_mode_valid(encoder->bridge, mode);
+	if (ret != MODE_OK) {
+		DRM_DEBUG_ATOMIC("[BRIDGE] mode_valid() failed\n");
+		return ret;
+	}
+
+	if (crtc_funcs && crtc_funcs->mode_valid)
+		ret = crtc_funcs->mode_valid(crtc, mode);
+
+	if (ret != MODE_OK) {
+		DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode_valid() failed\n",
+				crtc->base.id, crtc->name);
+		return ret;
+	}
+
+	return ret;
+}
+
+static int
+mode_valid(struct drm_atomic_state *state)
+{
+	struct drm_connector_state *conn_state;
+	struct drm_connector *connector;
+	int i;
+
+	for_each_connector_in_state(state, connector, conn_state, i) {
+		struct drm_encoder *encoder = conn_state->best_encoder;
+		struct drm_crtc *crtc = conn_state->crtc;
+		struct drm_crtc_state *crtc_state;
+		enum drm_mode_status mode_status;
+		struct drm_display_mode *mode;
+
+		if (!crtc || !encoder)
+			continue;
+
+		crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+		if (!crtc_state)
+			continue;
+
+		mode = &crtc_state->mode;
+
+		mode_status = mode_valid_pipe(connector, encoder, crtc, mode);
+		if (mode_status != MODE_OK)
+			return -EINVAL;
+	}
+
+	return 0;
+}
+
 /**
  * drm_atomic_helper_check_modeset - validate state object for modeset changes
  * @dev: DRM device
@@ -466,13 +545,16 @@  static int handle_conflicting_encoders(struct drm_atomic_state *state,
  * 2. &drm_connector_helper_funcs.atomic_check to validate the connector state.
  * 3. If it's determined a modeset is needed then all connectors on the affected crtc
  *    crtc are added and &drm_connector_helper_funcs.atomic_check is run on them.
- * 4. &drm_bridge_funcs.mode_fixup is called on all encoder bridges.
- * 5. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state.
+ * 4. &drm_connector_helper_funcs.mode_valid, &drm_encoder_helper_funcs.mode_valid,
+ *    &drm_bridge_funcs.mode_valid and &drm_crtc_helper_funcs.mode_valid are called
+ *    on the affected components.
+ * 5. &drm_bridge_funcs.mode_fixup is called on all encoder bridges.
+ * 6. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state.
  *    This function is only called when the encoder will be part of a configured crtc,
  *    it must not be used for implementing connector property validation.
  *    If this function is NULL, &drm_atomic_encoder_helper_funcs.mode_fixup is called
  *    instead.
- * 6. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints.
+ * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints.
  *
  * &drm_crtc_state.mode_changed is set when the input mode is changed.
  * &drm_crtc_state.connectors_changed is set when a connector is added or
@@ -617,6 +699,10 @@  static int handle_conflicting_encoders(struct drm_atomic_state *state,
 			return ret;
 	}
 
+	ret = mode_valid(state);
+	if (ret)
+		return ret;
+
 	return mode_fixup(state);
 }
 EXPORT_SYMBOL(drm_atomic_helper_check_modeset);