All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Andrzej Hajda <a.hajda@samsung.com>
Cc: Jose Abreu <Jose.Abreu@synopsys.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Alexey Brodkin <abrodkin@synopsys.com>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Jose Abreu <joabreu@synopsys.com>,
	Carlos Palminha <palminha@synopsys.com>
Subject: Re: [PATCH] drm: Add crtc/encoder/bridge->mode_valid() callbacks
Date: Mon, 15 May 2017 08:56:40 +0200	[thread overview]
Message-ID: <20170515065640.2w5mf2zogvkzbcmq@phenom.ffwll.local> (raw)
In-Reply-To: <8e1d3954-ea7f-4cb9-9f0e-19ae771e0497@samsung.com>

On Fri, May 12, 2017 at 02:37:17PM +0200, Andrzej Hajda wrote:
> On 12.05.2017 09:31, Daniel Vetter wrote:
> > From: Jose Abreu <Jose.Abreu@synopsys.com>
> >
> > This adds a new callback to crtc, encoder and bridge helper functions
> > called mode_valid(). This callback shall be implemented if the
> > corresponding component has some sort of restriction in the modes
> > that can be displayed. A NULL callback implicates that the component
> > can display all the modes.
> >
> > We also change the documentation so that the new and old callbacks
> > are correctly documented.
> >
> > Only the callbacks were implemented to simplify review process,
> > following patches will make use of them.
> >
> > Changes in v2 from Daniel:
> > - Update the warning about how modes aren't filtered in atomic_check -
> >   the heleprs help out a lot more now.
> > - Consistenly roll out that warning, crtc/encoder's atomic_check
> >   missed it.
> > - Sprinkle more links all over the place, so it's easier to see where
> >   this stuff is used and how the differen hooks are related.
> > - Note that ->mode_valid is optional everywhere.
> > - Explain why the connector's mode_valid is special and does _not_ get
> >   called in atomic_check.
> >
> > Signed-off-by: Jose Abreu <joabreu@synopsys.com>
> > Cc: 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>
> > Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> (v2)
> > ---
> >  include/drm/drm_bridge.h                 |  31 +++++++++
> >  include/drm/drm_modeset_helper_vtables.h | 116 ++++++++++++++++++++++---------
> >  2 files changed, 114 insertions(+), 33 deletions(-)
> >
> > diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
> > index fdd82fcbf168..f694de756ecf 100644
> > --- a/include/drm/drm_bridge.h
> > +++ b/include/drm/drm_bridge.h
> > @@ -59,6 +59,31 @@ struct drm_bridge_funcs {
> >  	void (*detach)(struct drm_bridge *bridge);
> >  
> >  	/**
> > +	 * @mode_valid:
> > +	 *
> > +	 * This callback is used to check if a specific mode is valid in this
> > +	 * bridge. This should be implemented if the bridge has some sort of
> > +	 * restriction in the modes it can display. For example, a given bridge
> > +	 * may be responsible to set a clock value. If the clock can not
> > +	 * produce all the values for the available modes then this callback
> > +	 * can be used to restrict the number of modes to only the ones that
> > +	 * can be displayed.
> > +	 *
> > +	 * This hook is used by the probe helpers to filter the mode list in
> > +	 * drm_helper_probe_single_connector_modes(), and it is used by the
> > +	 * atomic helpers to validate modes supplied by userspace in
> > +	 * drm_atomic_helper_check_modeset().
> > +	 *
> > +	 * This function is optional.
> > +	 *
> > +	 * RETURNS:
> > +	 *
> > +	 * drm_mode_status Enum
> > +	 */
> > +	enum drm_mode_status (*mode_valid)(struct drm_bridge *crtc,
> > +					   const struct drm_display_mode *mode);
> 
> I have put my concerns here but it touches all mode_valid callbacks.
> As the callback can be called in mode probe and atomic check it could
> only inspect common set of properties for both contexts, for example
> crtc cannot check to which encoder it is connected, am I right?
> Maybe it would be good to emphasize it here, as it is emphasized in case
> of mode_fixup callbacks.

You can inspect nothing else but the mode here. Looking at anything else
is not allowed since this is the generic check which should work for any
config. Good question, so I'll augment the docs to address this.

> > +
> > +	/**
> >  	 * @mode_fixup:
> >  	 *
> >  	 * This callback is used to validate and adjust a mode. The paramater
> > @@ -82,6 +107,12 @@ struct drm_bridge_funcs {
> >  	 * NOT touch any persistent state (hardware or software) or data
> >  	 * structures except the passed in @state parameter.
> >  	 *
> > +	 * Also beware that userspace can request its own custom modes, neither
> > +	 * core nor helpers filter modes to the list of probe modes reported by
> > +	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
> > +	 * that modes are filtered consistently put any bridge constraints and
> > +	 * limits checks into @mode_valid.
> > +	 *
> >  	 * RETURNS:
> >  	 *
> >  	 * True if an acceptable configuration is possible, false if the modeset
> > diff --git a/include/drm/drm_modeset_helper_vtables.h b/include/drm/drm_modeset_helper_vtables.h
> > index c01c328f6cc8..91d071ff1232 100644
> > --- a/include/drm/drm_modeset_helper_vtables.h
> > +++ b/include/drm/drm_modeset_helper_vtables.h
> > @@ -106,6 +106,31 @@ struct drm_crtc_helper_funcs {
> >  	void (*commit)(struct drm_crtc *crtc);
> >  
> >  	/**
> > +	 * @mode_valid:
> > +	 *
> > +	 * This callback is used to check if a specific mode is valid in this
> > +	 * crtc. This should be implemented if the crtc has some sort of
> > +	 * restriction in the modes it can display. For example, a given crtc
> > +	 * may be responsible to set a clock value. If the clock can not
> > +	 * produce all the values for the available modes then this callback
> > +	 * can be used to restrict the number of modes to only the ones that
> > +	 * can be displayed.
> > +	 *
> > +	 * This hook is used by the probe helpers to filter the mode list in
> > +	 * drm_helper_probe_single_connector_modes(), and it is used by the
> > +	 * atomic helpers to validate modes supplied by userspace in
> > +	 * drm_atomic_helper_check_modeset().
> > +	 *
> > +	 * This function is optional.
> > +	 *
> > +	 * RETURNS:
> > +	 *
> > +	 * drm_mode_status Enum
> > +	 */
> > +	enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
> > +					   const struct drm_display_mode *mode);
> > +
> > +	/**
> >  	 * @mode_fixup:
> >  	 *
> >  	 * This callback is used to validate a mode. The parameter mode is the
> > @@ -132,20 +157,11 @@ struct drm_crtc_helper_funcs {
> >  	 * Atomic drivers which need to inspect and adjust more state should
> >  	 * instead use the @atomic_check callback.
> >  	 *
> > -	 * Also beware that neither core nor helpers filter modes before
> > -	 * passing them to the driver: While the list of modes that is
> > -	 * advertised to userspace is filtered using the
> > -	 * &drm_connector.mode_valid callback, neither the core nor the helpers
> > -	 * do any filtering on modes passed in from userspace when setting a
> > -	 * mode. It is therefore possible for userspace to pass in a mode that
> > -	 * was previously filtered out using &drm_connector.mode_valid or add a
> > -	 * custom mode that wasn't probed from EDID or similar to begin with.
> > -	 * Even though this is an advanced feature and rarely used nowadays,
> > -	 * some users rely on being able to specify modes manually so drivers
> > -	 * must be prepared to deal with it. Specifically this means that all
> > -	 * drivers need not only validate modes in &drm_connector.mode_valid but
> > -	 * also in this or in the &drm_encoder_helper_funcs.mode_fixup callback
> > -	 * to make sure invalid modes passed in from userspace are rejected.
> > +	 * Also beware that userspace can request its own custom modes, neither
> > +	 * core nor helpers filter modes to the list of probe modes reported by
> > +	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
> > +	 * that modes are filtered consistently put any CRTC constraints and
> > +	 * limits checks into @mode_valid.
> 
> Why we do not make mode_fixup obsolete for atomic drivers as
> atomic_check can do the same and is more powerful, this way we could
> avoid the overlapped functionality of mode_valid and mode_fixup.

What do you mean with "make obselete"? mode_fixup is the compat callback,
atomic_check is the shiny new one, so it is already obselete.

> >  	 *
> >  	 * RETURNS:
> >  	 *
> > @@ -341,6 +357,12 @@ struct drm_crtc_helper_funcs {
> >  	 * state objects passed-in or assembled in the overall &drm_atomic_state
> >  	 * update tracking structure.
> >  	 *
> > +	 * Also beware that userspace can request its own custom modes, neither
> > +	 * core nor helpers filter modes to the list of probe modes reported by
> > +	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
> > +	 * that modes are filtered consistently put any CRTC constraints and
> > +	 * limits checks into @mode_valid.
> > +	 *
> >  	 * RETURNS:
> >  	 *
> >  	 * 0 on success, -EINVAL if the state or the transition can't be
> > @@ -457,6 +479,31 @@ struct drm_encoder_helper_funcs {
> >  	void (*dpms)(struct drm_encoder *encoder, int mode);
> >  
> >  	/**
> > +	 * @mode_valid:
> > +	 *
> > +	 * This callback is used to check if a specific mode is valid in this
> > +	 * encoder. This should be implemented if the encoder has some sort
> > +	 * of restriction in the modes it can display. For example, a given
> > +	 * encoder may be responsible to set a clock value. If the clock can
> > +	 * not produce all the values for the available modes then this callback
> > +	 * can be used to restrict the number of modes to only the ones that
> > +	 * can be displayed.
> > +	 *
> > +	 * This hook is used by the probe helpers to filter the mode list in
> > +	 * drm_helper_probe_single_connector_modes(), and it is used by the
> > +	 * atomic helpers to validate modes supplied by userspace in
> > +	 * drm_atomic_helper_check_modeset().
> > +	 *
> > +	 * This function is optional.
> > +	 *
> > +	 * RETURNS:
> > +	 *
> > +	 * drm_mode_status Enum
> > +	 */
> > +	enum drm_mode_status (*mode_valid)(struct drm_encoder *crtc,
> > +					   const struct drm_display_mode *mode);
> > +
> > +	/**
> >  	 * @mode_fixup:
> >  	 *
> >  	 * This callback is used to validate and adjust a mode. The parameter
> > @@ -482,21 +529,11 @@ struct drm_encoder_helper_funcs {
> >  	 * Atomic drivers which need to inspect and adjust more state should
> >  	 * instead use the @atomic_check callback.
> >  	 *
> > -	 * Also beware that neither core nor helpers filter modes before
> > -	 * passing them to the driver: While the list of modes that is
> > -	 * advertised to userspace is filtered using the connector's
> > -	 * &drm_connector_helper_funcs.mode_valid callback, neither the core nor
> > -	 * the helpers do any filtering on modes passed in from userspace when
> > -	 * setting a mode. It is therefore possible for userspace to pass in a
> > -	 * mode that was previously filtered out using
> > -	 * &drm_connector_helper_funcs.mode_valid or add a custom mode that
> > -	 * wasn't probed from EDID or similar to begin with.  Even though this
> > -	 * is an advanced feature and rarely used nowadays, some users rely on
> > -	 * being able to specify modes manually so drivers must be prepared to
> > -	 * deal with it. Specifically this means that all drivers need not only
> > -	 * validate modes in &drm_connector.mode_valid but also in this or in
> > -	 * the &drm_crtc_helper_funcs.mode_fixup callback to make sure
> > -	 * invalid modes passed in from userspace are rejected.
> > +	 * Also beware that userspace can request its own custom modes, neither
> > +	 * core nor helpers filter modes to the list of probe modes reported by
> > +	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
> > +	 * that modes are filtered consistently put any encoder constraints and
> > +	 * limits checks into @mode_valid.
> >  	 *
> >  	 * RETURNS:
> >  	 *
> > @@ -686,6 +723,12 @@ struct drm_encoder_helper_funcs {
> >  	 * state objects passed-in or assembled in the overall &drm_atomic_state
> >  	 * update tracking structure.
> >  	 *
> > +	 * Also beware that userspace can request its own custom modes, neither
> > +	 * core nor helpers filter modes to the list of probe modes reported by
> > +	 * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
> > +	 * that modes are filtered consistently put any encoder constraints and
> > +	 * limits checks into @mode_valid.
> > +	 *
> >  	 * RETURNS:
> >  	 *
> >  	 * 0 on success, -EINVAL if the state or the transition can't be
> > @@ -795,13 +838,20 @@ struct drm_connector_helper_funcs {
> >  	 * (which is usually derived from the EDID data block from the sink).
> >  	 * See e.g. drm_helper_probe_single_connector_modes().
> >  	 *
> > +	 * This function is optional.
> > +	 *
> >  	 * NOTE:
> >  	 *
> >  	 * This only filters the mode list supplied to userspace in the
> > -	 * GETCONNECOTR IOCTL. Userspace is free to create modes of its own and
> > -	 * ask the kernel to use them. It this case the atomic helpers or legacy
> > -	 * CRTC helpers will not call this function. Drivers therefore must
> > -	 * still fully validate any mode passed in in a modeset request.
> > +	 * GETCONNECTOR IOCTL. Compared to &drm_encoder_helper_funcs.mode_valid,
> > +	 * &drm_crtc_helper_funcs.mode_valid and &drm_bridge_funcs.mode_valid,
> > +	 * which are also called by the atomic helpers from
> > +	 * drm_atomic_helper_check_modeset(). This allows userspace to force and
> > +	 * ignore sink constraint (like the pixel clock limits in the screen's
> > +	 * EDID), which is useful for e.g. testing, or working around a broken
> > +	 * EDID. Any source hardware constraint (which always need to be
> > +	 * enforced) therefore should be checked in one of the above callbacks,
> > +	 * and not this one here.
> 
> The callback has the same name but different semantic, little bit weird.
> But do we really need connector::mode_valid then? I mean: are there
> connectors not bound to bridge/encoder which have their own constraints?
> If there are no such connectors, we can remove this callback.

Yes. And the pixel clock limit is exactly the current real-world use-case:
There are hdmi screens which have a pixel clock limit set, but in reality
can take higher modes. There's users out there who want to use these
higher modes on these peculiar screens. But for everyone else (and for all
other screens), we do need to filter modes correctly (the example here is
dual-link vs. single-link limits, which is an interaction between sink and
source).

> If they are rare, maybe just adding loop to connector::get_modes would
> be enough.

What do you mean with "adding a loop"?
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2017-05-15  6:56 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-11  9:05 [PATCH v3 0/6] Introduce new mode validation callbacks Jose Abreu
2017-05-11  9:05 ` [PATCH v3 1/6] drm: Add crtc/encoder/bridge->mode_valid() callbacks Jose Abreu
2017-05-12  7:00   ` Daniel Vetter
2017-05-12  7:00     ` Daniel Vetter
2017-05-12  7:31   ` [PATCH] " Daniel Vetter
2017-05-12 11:29     ` Laurent Pinchart
2017-05-15  6:50       ` Daniel Vetter
2017-05-12 12:37     ` Andrzej Hajda
2017-05-15  6:56       ` Daniel Vetter [this message]
2017-05-15  8:10         ` Andrzej Hajda
2017-05-15  8:14           ` Daniel Vetter
2017-05-12 15:59     ` Jose Abreu
2017-05-15  9:11     ` [PATCH 1/2] drm/doc: Document adjusted/request modes a bit better Daniel Vetter
2017-05-15  9:11       ` [PATCH 2/2] drm/doc: Clarify mode_fixup vs. atomic_check a bit more Daniel Vetter
2017-05-16  2:41         ` Jose Abreu
2017-05-16 13:14         ` Andrzej Hajda
2017-05-16  2:38       ` [PATCH 1/2] drm/doc: Document adjusted/request modes a bit better Jose Abreu
2017-05-16 13:17       ` Andrzej Hajda
2017-05-15  9:33     ` [PATCH] drm: Add crtc/encoder/bridge->mode_valid() callbacks Daniel Vetter
2017-05-16 13:15       ` Andrzej Hajda
2017-05-11  9:05 ` [PATCH v3 2/6] drm: Add drm_{crtc/encoder/connector}_mode_valid() Jose Abreu
2017-05-15  8:27   ` Andrzej Hajda
2017-05-15  8:27     ` Andrzej Hajda
2017-05-11  9:05 ` [PATCH v3 3/6] drm: Introduce drm_bridge_mode_valid() Jose Abreu
2017-05-11  9:06 ` [PATCH v3 4/6] drm: Use new mode_valid() helpers in connector probe helper Jose Abreu
2017-05-15  8:39   ` Andrzej Hajda
2017-05-15  8:39     ` Andrzej Hajda
2017-05-15  9:30     ` Daniel Vetter
2017-05-15  9:30       ` Daniel Vetter
2017-05-15  9:51       ` Andrzej Hajda
2017-05-15  9:51         ` Andrzej Hajda
2017-05-11  9:06 ` [PATCH v3 5/6] drm: Use mode_valid() in atomic modeset Jose Abreu
2017-05-15  8:45   ` Andrzej Hajda
2017-05-11  9:06 ` [PATCH v3 6/6] drm: arc: Use crtc->mode_valid() callback Jose Abreu
2017-05-15  8:53   ` Daniel Vetter
2017-05-15  8:53     ` Daniel Vetter
2017-05-15 15:52     ` Daniel Vetter
2017-05-15 15:52       ` Daniel Vetter
2017-05-15 23:55       ` Jose Abreu
2017-05-15 23:55         ` Jose Abreu
2017-05-15  8:54   ` Andrzej Hajda
2017-05-15  8:54     ` Andrzej Hajda
2017-05-12  7:32 ` [PATCH v3 0/6] Introduce new mode validation callbacks Daniel Vetter
2017-05-12  7:32   ` Daniel Vetter
2017-05-12 13:37   ` Andrzej Hajda
2017-05-12 13:37     ` Andrzej Hajda

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=20170515065640.2w5mf2zogvkzbcmq@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=Jose.Abreu@synopsys.com \
    --cc=a.hajda@samsung.com \
    --cc=abrodkin@synopsys.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=joabreu@synopsys.com \
    --cc=palminha@synopsys.com \
    /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.