All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Jernej Skrabec <jernej.skrabec@siol.net>,
	Neil Armstrong <narmstrong@baylibre.com>,
	Jonas Karlman <jonas@kwiboo.se>,
	Seung-Woo Kim <sw0312.kim@samsung.com>,
	dri-devel@lists.freedesktop.org,
	Kyungmin Park <kyungmin.park@samsung.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Chris Healy <Chris.Healy@zii.aero>,
	kernel@collabora.com, Sam Ravnborg <sam@ravnborg.org>
Subject: Re: [PATCH RFC 10/19] drm/bridge: Add a drm_bridge_state object
Date: Thu, 22 Aug 2019 11:00:56 +0200	[thread overview]
Message-ID: <20190822110056.5be93d0a@collabora.com> (raw)
In-Reply-To: <20190821201456.GF26759@pendragon.ideasonboard.com>

On Wed, 21 Aug 2019 23:14:56 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote:

> > +int
> > +drm_atomic_add_encoder_bridges(struct drm_atomic_state *state,
> > +			       struct drm_encoder *encoder)
> > +{
> > +	struct drm_bridge_state *bridge_state;
> > +	struct drm_bridge *bridge;
> > +
> > +	if (!encoder)
> > +		return 0;
> > +
> > +	DRM_DEBUG_ATOMIC("Adding all bridges for [encoder:%d:%s] to %p\n",
> > +			 encoder->base.id, encoder->name, state);
> > +
> > +	for (bridge = drm_bridge_chain_get_first_bridge(encoder); bridge;
> > +	     bridge = drm_bridge_chain_get_next_bridge(bridge)) {  
> 
> Would a for_each_bridge() macro make sense ? I'd implement it on top of
> list_for_each_entry() to make it simple.

I can add this helper. Note that for_each_bridge() will iterate over
the whole bridge chain, and we might need a for_each_bridge_from() at
some point if we want to iterate over a sub-chain.

> 
> > +		bridge_state = drm_atomic_get_bridge_state(state, bridge);
> > +		if (IS_ERR(bridge_state))
> > +			return PTR_ERR(bridge_state);
> > +	}
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_atomic_add_encoder_bridges);

[...]

> >  
> > +/**
> > + * drm_atomic_helper_init_bridge_state() - Initializes a bridge state  
> 
> s/Initializes/Initialize/
> 
> > + * @bridge this state is referring to  
> 
> Did you mean
> 
>  * @bridge: the bridge this state is referring to ?

Yes.

> 
> > + * @state: bridge state to initialize
> > + *
> > + * For now it's just a memset(0) plus a state->bridge assignment. Might
> > + * be extended in the future.
> > + */
> > +void drm_atomic_helper_init_bridge_state(struct drm_bridge *bridge,
> > +					 struct drm_bridge_state *state)
> > +{
> > +	memset(state, 0, sizeof(*state));
> > +	state->bridge = bridge;
> > +}
> > +EXPORT_SYMBOL(drm_atomic_helper_init_bridge_state);  
> 
> Other objects don't export a state init function helper, but state reset
> and state duplicate helpers. Is there a reason to depart from that model
> ? Same for the copy helper below.

I thought those names better reflect what the helpers do.
__drm_atomic_helper_crtc_duplicate_state() for instance, it actually
does not duplicate the state, but just copies current state info into
the new state object which has been allocated by the caller. Same for
the reset helpers, they actually do not reset anything but just
initialize the state to a default. I also try to avoid prefixing
functions with __ when I can (names can be clarified/extended to avoid
conflicts most of the time).
Will switch back to reset/dup names if you prefer.

> 
> > +
> > +/**
> > + * drm_atomic_helper_copy_bridge_state() - Copy the content of a bridge state
> > + * @bridge: bridge the old and new state are referring to
> > + * @old: previous bridge state to copy from
> > + * @new: new bridge state to copy to
> > + *
> > + * Should be used by custom &drm_bridge_funcs.atomic_duplicate() implementation
> > + * to copy the previous state into the new object.
> > + */
> > +void drm_atomic_helper_copy_bridge_state(struct drm_bridge *bridge,
> > +					 const struct drm_bridge_state *old,
> > +					 struct drm_bridge_state *new)
> > +{
> > +	*new = *old;
> > +}
> > +EXPORT_SYMBOL(drm_atomic_helper_copy_bridge_state);
> > +
> > +/**
> > + * drm_atomic_helper_duplicate_bridge_state() - Default duplicate state helper
> > + * @bridge: bridge containing the state to duplicate
> > + *
> > + * Default implementation of &drm_bridge_funcs.atomic_duplicate().
> > + *
> > + * RETURNS:
> > + * a valid state object or NULL if the allocation fails.
> > + */
> > +struct drm_bridge_state *
> > +drm_atomic_helper_duplicate_bridge_state(struct drm_bridge *bridge)
> > +{
> > +	struct drm_bridge_state *old = NULL, *new;
> > +
> > +	new = kzalloc(sizeof(*new), GFP_KERNEL);
> > +	if (!new)
> > +		return NULL;
> > +
> > +	if (bridge->base.state) {
> > +		old = drm_priv_to_bridge_state(bridge->base.state);
> > +		drm_atomic_helper_copy_bridge_state(bridge, old, new);
> > +	} else {
> > +		drm_atomic_helper_init_bridge_state(bridge, new);
> > +	}
> > +
> > +	return new;
> > +}
> > +EXPORT_SYMBOL(drm_atomic_helper_duplicate_bridge_state);
> > +
> > +/**
> > + * drm_atomic_helper_destroy_bridge_state() - Default destroy state helper
> > + * @bridge: the bridge this state refers to
> > + * @state: state object to destroy
> > + *
> > + * Just a simple kfree() for now.
> > + */
> > +void drm_atomic_helper_destroy_bridge_state(struct drm_bridge *bridge,
> > +					    struct drm_bridge_state *state)
> > +{
> > +	kfree(state);
> > +}
> > +EXPORT_SYMBOL(drm_atomic_helper_destroy_bridge_state);
> > +
> >  #ifdef CONFIG_OF
> >  /**
> >   * of_drm_find_bridge - find the bridge corresponding to the device node in
> > diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
> > index 927e1205d7aa..5ee25fd51e80 100644
> > --- a/include/drm/drm_atomic.h
> > +++ b/include/drm/drm_atomic.h
> > @@ -660,6 +660,9 @@ __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
> >  	return plane->state;
> >  }
> >  
> > +int __must_check
> > +drm_atomic_add_encoder_bridges(struct drm_atomic_state *state,
> > +                               struct drm_encoder *encoder);
> >  int __must_check
> >  drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
> >  				   struct drm_crtc *crtc);
> > diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
> > index f40181274ed7..8ca25d266d0c 100644
> > --- a/include/drm/drm_bridge.h
> > +++ b/include/drm/drm_bridge.h
> > @@ -25,6 +25,7 @@
> >  
> >  #include <linux/list.h>
> >  #include <linux/ctype.h>
> > +#include <drm/drm_atomic.h>
> >  #include <drm/drm_mode_object.h>
> >  #include <drm/drm_modes.h>
> >  
> > @@ -32,6 +33,23 @@ struct drm_bridge;
> >  struct drm_bridge_timings;
> >  struct drm_panel;
> >  
> > +/**
> > + * struct drm_bridge_state - Atomic bridge state object
> > + * @base: inherit from &drm_private_state
> > + * @bridge: the bridge this state refers to
> > + */
> > +struct drm_bridge_state {
> > +	struct drm_private_state base;
> > +
> > +	struct drm_bridge *bridge;
> > +};
> > +
> > +static inline struct drm_bridge_state *
> > +drm_priv_to_bridge_state(struct drm_private_state *priv)
> > +{
> > +	return container_of(priv, struct drm_bridge_state, base);
> > +}
> > +
> >  /**
> >   * struct drm_bridge_funcs - drm_bridge control functions
> >   */
> > @@ -337,6 +355,30 @@ struct drm_bridge_funcs {
> >  	 */
> >  	void (*atomic_post_disable)(struct drm_bridge *bridge,
> >  				    struct drm_atomic_state *state);
> > +
> > +	/**
> > +	 * @atomic_duplicate_state:
> > +	 *
> > +	 * Duplicate the current bridge state object.
> > +	 *
> > +	 * Note that this function can be called when current bridge state is
> > +	 * NULL. In this case, implementations should either implement HW
> > +	 * readback or initialize the state with sensible default values.  
> 
> Related to the question above, shouldn't we have a reset state operation
> instead ?

I had a version with a reset hook and a helper that was falling back to
->duplicate_state() when not specified, but I decided to drop it to
simplify things (I think most drivers will just use the default
helper, and those that actually want to implement HW readback can
easily do it from their ->duplicate_state() hook by testing
bridge->state value).
I can re-introduce it if you like.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2019-08-22  9:01 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 15:11 [PATCH RFC 00/19] drm: Add support for bus-format negotiation Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 01/19] drm: Stop including drm_bridge.h from drm_crtc.h Boris Brezillon
2019-08-08 18:05   ` Sam Ravnborg
2019-08-20 18:53   ` Laurent Pinchart
2019-08-21 15:44     ` Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 02/19] drm: Support custom encoder/bridge enable/disable sequences officially Boris Brezillon
2019-08-20 19:05   ` Laurent Pinchart
2019-08-21  8:21     ` Daniel Vetter
2019-08-21 13:57       ` Laurent Pinchart
2019-08-21 15:39       ` Boris Brezillon
2019-08-21 15:30     ` Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 03/19] drm/vc4: Get rid of the dsi->bridge field Boris Brezillon
2019-08-08 20:31   ` Eric Anholt
2019-08-08 15:11 ` [PATCH RFC 04/19] drm/exynos: Get rid of exynos_dsi->out_bridge Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 05/19] drm/exynos: Don't reset bridge->next Boris Brezillon
2019-08-08 21:04   ` Boris Brezillon
2019-08-21 14:01   ` Laurent Pinchart
2019-08-08 15:11 ` [PATCH RFC 06/19] drm/bridge: Create drm_bridge_chain_xx() wrappers Boris Brezillon
2019-08-21 14:45   ` Laurent Pinchart
2019-08-21 15:53     ` Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 07/19] drm/msm: Use drm_attach_bridge() to attach a bridge to an encoder Boris Brezillon
2019-08-19 17:19   ` Sam Ravnborg
2019-08-21 14:46     ` Laurent Pinchart
2019-08-08 15:11 ` [PATCH RFC 08/19] drm/bridge: Introduce drm_bridge_chain_get_{first, last, next}_bridge() Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 09/19] drm/bridge: Make the bridge chain a double-linked list Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 10/19] drm/bridge: Add a drm_bridge_state object Boris Brezillon
2019-08-21 20:14   ` Laurent Pinchart
2019-08-22  9:00     ` Boris Brezillon [this message]
2019-12-02 15:52       ` Laurent Pinchart
2019-08-08 15:11 ` [PATCH RFC 11/19] drm/bridge: Patch atomic hooks to take a drm_bridge_state Boris Brezillon
2019-08-22  0:02   ` Laurent Pinchart
2019-08-22  8:25     ` Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 12/19] drm/bridge: Add an ->atomic_check() hook Boris Brezillon
2019-08-22  0:12   ` Laurent Pinchart
2019-08-22  7:58     ` Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 13/19] drm/bridge: Add the drm_bridge_chain_get_prev_bridge() helper Boris Brezillon
2019-08-22  0:17   ` Laurent Pinchart
2019-08-22  8:04     ` Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 14/19] drm/bridge: Add the necessary bits to support bus format negotiation Boris Brezillon
2019-08-14  7:51   ` Neil Armstrong
2019-08-21 18:31     ` Boris Brezillon
2019-08-22  0:55   ` Laurent Pinchart
2019-08-22  7:48     ` Boris Brezillon
2019-08-22  9:29       ` Neil Armstrong
2019-08-22 10:09         ` Boris Brezillon
2019-08-22 10:22           ` Neil Armstrong
2019-08-22 10:34             ` Boris Brezillon
2019-08-22 11:30               ` Neil Armstrong
2019-08-08 15:11 ` [PATCH RFC 15/19] drm/imx: pd: Use bus format/flags provided by the bridge when available Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 16/19] drm/bridge: lvds-encoder: Add a way to support custom ->atomic_check() implem Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 17/19] drm/bridge: lvds-encoder: Implement bus format negotiation for sn75lvds83 Boris Brezillon
2019-08-22  0:32   ` Laurent Pinchart
2019-08-22  8:12     ` Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 18/19] drm/panel: simple: Add support for Toshiba LTA089AC29000 panel Boris Brezillon
2019-08-22  0:36   ` Laurent Pinchart
2019-08-22  8:15     ` Boris Brezillon
2019-08-08 15:11 ` [PATCH RFC 19/19] ARM: dts: imx: imx51-zii-rdu1: Fix the display pipeline definition Boris Brezillon
2019-08-09  6:58 ` [PATCH RFC 00/19] drm: Add support for bus-format negotiation Neil Armstrong

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=20190822110056.5be93d0a@collabora.com \
    --to=boris.brezillon@collabora.com \
    --cc=Chris.Healy@zii.aero \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jernej.skrabec@siol.net \
    --cc=jonas@kwiboo.se \
    --cc=kernel@collabora.com \
    --cc=kyungmin.park@samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=narmstrong@baylibre.com \
    --cc=sam@ravnborg.org \
    --cc=sw0312.kim@samsung.com \
    --cc=thierry.reding@gmail.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.