linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Paul Elder <paul.elder@ideasonboard.com>,
	linux-media@vger.kernel.org, dafna@fastmail.com, heiko@sntech.de,
	jeanmichel.hautbois@ideasonboard.com, jacopo@jmondi.org,
	djrscally@gmail.com, helen.koike@collabora.com,
	linux-rockchip@lists.infradead.org
Subject: Re: [PATCH 37/55] media: mc-entity: Add a new helper function to get a remote pad
Date: Thu, 7 Jul 2022 14:50:46 +0300	[thread overview]
Message-ID: <YsbIltES0oblIsDb@pendragon.ideasonboard.com> (raw)
In-Reply-To: <c8f5c146-10d2-dcc8-f492-62fa34a1d648@xs4all.nl>

Hi Hans,

On Thu, Jul 07, 2022 at 08:52:16AM +0200, Hans Verkuil wrote:
> On 6/25/22 19:00, Laurent Pinchart wrote:
> > On Fri, Jun 17, 2022 at 01:48:05PM +0200, Hans Verkuil wrote:
> >> On 6/14/22 21:11, Paul Elder wrote:
> >>> From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >>>
> >>> The media_entity_remote_pad() helper function returns the first remote
> >>> pad it find connected to a given pad. Beside being possibly ill-named
> >>> (as it operates on a pad, not an entity) and non-deterministic (as it
> >>> stops at the first enabled link), the fact that it returns the first
> >>> match makes it unsuitable for drivers that need to guarantee that a
> >>> single link is enabled, for instance when an entity can process data
> >>> from one of multiple sources at a time.
> >>
> >> Question: of all the callers of this function, are there any that really
> >> need media_entity_remote_pad() instead of media_pad_remote_pad_unique()?
> >>
> >> Would it be possible to replace all callers of the old function with the
> >> new function? If that's the case, then the _unique suffix can be dropped,
> >> since that would effectively be the default. And if a function is needed
> >> to handle the case where there are multiple enabled links, then a new
> >> function should be created.
> > 
> > I don't think so. media_entity_remote_pad() operates on a pad, switching
> > to media_pad_remote_pad_unique() wouldn't work on subdevs that have
> > multiple sink or source pads with one active link each.
> 
> Do we have those today in the mainline kernel? Just checking...

Re-reading my reply, it seems I may have been mistaken. We may be able
to ditch media_pad_remote_pad_first() and replace it with
media_pad_remote_pad_unique() (at least in the majority of cases), but
we'll need to carefully review each user.

> >> Also, media_entity_remote_pad() should really be renamed to
> >> media_pad_remote_pad_first() or something like that, right? I'm not saying
> >> you should, but that's really what it does, as I understand it.
> > 
> > Yes, I think that would make sense, and it would freethe
> > media_entity_remote_pad() name, so the new function wouldn't need the
> > _unique suffix. I'll give it a try.
> > 
> >>> For those use cases, add a new helper function,
> >>> media_entity_remote_pad_unique(), that operates on an entity and returns
> >>> a remote pad, with a guarantee that only one link is enabled. To ease
> >>> its use in drivers, also add an inline wrapper that locates source pads
> >>> specifically. A wrapper that locates sink pads can easily be added when
> >>> needed.
> >>>
> >>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >>> ---
> >>>  Documentation/driver-api/media/mc-core.rst |  4 +-
> >>>  drivers/media/mc/mc-entity.c               | 38 ++++++++++++++++++
> >>>  include/media/media-entity.h               | 45 ++++++++++++++++++++++
> >>>  3 files changed, 85 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/Documentation/driver-api/media/mc-core.rst b/Documentation/driver-api/media/mc-core.rst
> >>> index 02481a2513b9..a2d1e32e3abb 100644
> >>> --- a/Documentation/driver-api/media/mc-core.rst
> >>> +++ b/Documentation/driver-api/media/mc-core.rst
> >>> @@ -186,8 +186,8 @@ is required and the graph structure can be freed normally.
> >>>  
> >>>  Helper functions can be used to find a link between two given pads, or a pad
> >>>  connected to another pad through an enabled link
> >>> -:c:func:`media_entity_find_link()` and
> >>> -:c:func:`media_entity_remote_pad()`.
> >>> +(:c:func:`media_entity_find_link()`, :c:func:`media_entity_remote_pad()` and
> >>> +:c:func:`media_entity_remote_source_pad()`).
> >>>  
> >>>  Use count and power handling
> >>>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >>> diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
> >>> index 11f5207f73aa..1febf5a86be6 100644
> >>> --- a/drivers/media/mc/mc-entity.c
> >>> +++ b/drivers/media/mc/mc-entity.c
> >>> @@ -9,6 +9,7 @@
> >>>   */
> >>>  
> >>>  #include <linux/bitmap.h>
> >>> +#include <linux/list.h>
> >>>  #include <linux/property.h>
> >>>  #include <linux/slab.h>
> >>>  #include <media/media-entity.h>
> >>> @@ -920,6 +921,43 @@ struct media_pad *media_entity_remote_pad(const struct media_pad *pad)
> >>>  }
> >>>  EXPORT_SYMBOL_GPL(media_entity_remote_pad);
> >>>  
> >>> +struct media_pad *
> >>> +media_entity_remote_pad_unique(const struct media_entity *entity,
> >>> +			       unsigned int type)
> >>> +{
> >>> +	struct media_pad *pad = NULL;
> >>> +	struct media_link *link;
> >>> +
> >>> +	list_for_each_entry(link, &entity->links, list) {
> >>> +		struct media_pad *local_pad;
> >>> +		struct media_pad *remote_pad;
> >>> +
> >>> +		if (!(link->flags & MEDIA_LNK_FL_ENABLED))
> >>> +			continue;
> >>> +
> >>> +		if (type == MEDIA_PAD_FL_SOURCE) {
> >>> +			local_pad = link->sink;
> >>> +			remote_pad = link->source;
> >>> +		} else {
> >>> +			local_pad = link->source;
> >>> +			remote_pad = link->sink;
> >>> +		}
> >>> +
> >>> +		if (local_pad->entity == entity) {
> >>> +			if (pad)
> >>> +				return ERR_PTR(-ENOTUNIQ);
> >>> +
> >>> +			pad = remote_pad;
> >>> +		}
> >>> +	}
> >>> +
> >>> +	if (!pad)
> >>> +		return ERR_PTR(-ENOLINK);
> >>> +
> >>> +	return pad;
> >>> +}
> >>> +EXPORT_SYMBOL_GPL(media_entity_remote_pad_unique);
> >>> +
> >>>  static void media_interface_init(struct media_device *mdev,
> >>>  				 struct media_interface *intf,
> >>>  				 u32 gobj_type,
> >>> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> >>> index a9a1c0ec5d1c..33d5f52719a0 100644
> >>> --- a/include/media/media-entity.h
> >>> +++ b/include/media/media-entity.h
> >>> @@ -859,6 +859,51 @@ struct media_link *media_entity_find_link(struct media_pad *source,
> >>>   */
> >>>  struct media_pad *media_entity_remote_pad(const struct media_pad *pad);
> >>>  
> >>> +/**
> >>> + * media_entity_remote_pad_unique - Find a remote pad connected to an entity
> >>> + * @entity: The entity
> >>> + * @type: The type of pad to find (MEDIA_PAD_FL_SINK or MEDIA_PAD_FL_SOURCE)
> >>> + *
> >>> + * Search for and return a remote pad of @type connected to @entity through an
> >>> + * enabled link. If multiple (or no) remote pads match these criteria, an error
> >>> + * is returned.
> >>> + *
> >>> + * The uniqueness constraint makes this helper function suitable for entities
> >>> + * that support a single active source or sink at a time.
> >>> + *
> >>> + * Return: A pointer to the remote pad, or one of the following error pointers
> >>> + * if an error occurs:
> >>> + *
> >>> + * * -ENOTUNIQ - Multiple links are enabled
> >>> + * * -ENOLINK - No connected pad found
> >>> + */
> >>> +struct media_pad *
> >>> +media_entity_remote_pad_unique(const struct media_entity *entity,
> >>> +			       unsigned int type);
> >>> +
> >>> +/**
> >>> + * media_entity_remote_source_pad - Find a remote source pad connected to an entity
> >>> + * @entity: The entity
> >>> + *
> >>> + * Search for and return a remote source pad connected to @entity through an
> >>> + * enabled link. If multiple (or no) remote pads match these criteria, an error
> >>> + * is returned.
> >>> + *
> >>> + * The uniqueness constraint makes this helper function suitable for entities
> >>> + * that support a single active source at a time.
> >>> + *
> >>> + * Return: A pointer to the remote pad, or one of the following error pointers
> >>> + * if an error occurs:
> >>> + *
> >>> + * * -ENOTUNIQ - Multiple links are enabled
> >>> + * * -ENOLINK - No connected pad found
> >>> + */
> >>> +static inline struct media_pad *
> >>> +media_entity_remote_source_pad(const struct media_entity *entity)
> >>> +{
> >>> +	return media_entity_remote_pad_unique(entity, MEDIA_PAD_FL_SOURCE);
> >>> +}
> >>> +
> >>>  /**
> >>>   * media_entity_is_streaming - Test if an entity is part of a streaming pipeline
> >>>   * @entity: The entity

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2022-07-07 11:51 UTC|newest]

Thread overview: 149+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14 19:10 [PATCH 00/55] media: rkisp1: Cleanups and add support for i.MX8MP Paul Elder
2022-06-14 19:10 ` [PATCH 01/55] media: rkisp1: debug: Add dump file in debugfs for MI buffer registers Paul Elder
2022-06-15 22:41   ` Laurent Pinchart
2022-06-25 17:59     ` Laurent Pinchart
2022-07-04  3:46       ` paul.elder
2022-06-14 19:10 ` [PATCH 02/55] media: rkisp1: Enable compilation on ARCH_MXC Paul Elder
2022-06-24 14:17   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 03/55] media: rkisp1: debug: Add debugfs files to monitor MI and ISP interrupts Paul Elder
2022-06-16  0:44   ` Laurent Pinchart
2022-07-04  3:47     ` paul.elder
2022-06-14 19:10 ` [PATCH 04/55] media: rkisp1: Disable runtime PM in probe error path Paul Elder
2022-06-24 14:21   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 05/55] media: rkisp1: Read the ID register at probe time instead of streamon Paul Elder
2022-06-24 14:26   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 06/55] media: rkisp1: Rename rkisp1_match_data to rkisp1_info Paul Elder
2022-06-24 14:29   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 07/55] media: rkisp1: Save info pointer in rkisp1_device Paul Elder
2022-06-24 14:34   ` Dafna Hirschfeld
2022-06-24 14:47     ` Laurent Pinchart
2022-06-30 21:28       ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 08/55] media: rkisp1: Access ISP version from info pointer Paul Elder
2022-06-24 14:35   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 09/55] media: rkisp1: Make rkisp1_isp_mbus_info common Paul Elder
2022-06-16  0:50   ` Laurent Pinchart
2022-06-24 14:54   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 10/55] media: rkisp1: cap: Print debug message on failed link validation Paul Elder
2022-06-16  7:32   ` (EXT) " Alexander Stein
2022-06-16  7:41     ` Laurent Pinchart
2022-06-16  7:59       ` (EXT) " Alexander Stein
2022-06-24 15:00   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 11/55] media: rkisp1: Move sensor .s_stream() call to ISP Paul Elder
2022-06-24 15:14   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 12/55] media: rkisp1: Reject sensors without pixel rate control at bound time Paul Elder
2022-06-24 18:20   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 13/55] media: rkisp1: Create link from sensor to ISP at notifier " Paul Elder
2022-06-24 18:40   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 14/55] media: rkisp1: Create internal links at probe time Paul Elder
2022-06-24 18:43   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 15/55] media: rkisp1: Rename rkisp1_subdev_notifier() to rkisp1_subdev_notifier_register() Paul Elder
2022-06-24 18:44   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 16/55] media: v4l2-async: Add notifier operation to destroy asd instances Paul Elder
2022-06-15 22:36   ` Laurent Pinchart
2022-06-20 14:27   ` Hans Verkuil
2022-06-14 19:10 ` [PATCH 17/55] media: rkisp1: Fix sensor source pad retrieval at bound time Paul Elder
2022-07-01  4:36   ` Dafna Hirschfeld
2022-07-01 11:29     ` Laurent Pinchart
2022-06-14 19:10 ` [PATCH 18/55] media: rkisp1: Split CSI handling to separate file Paul Elder
2022-06-25  3:48   ` Dafna Hirschfeld
2022-06-25 10:18     ` Laurent Pinchart
2022-06-14 19:10 ` [PATCH 19/55] media: rkisp1: isp: Start CSI-2 receiver before ISP Paul Elder
2022-06-25  3:51   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 20/55] media: rkisp1: csi: Handle CSI-2 RX configuration fully in rkisp1-csi.c Paul Elder
2022-06-25  4:00   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 21/55] media: rkisp1: csi: Rename CSI functions with a common rkisp1_csi prefix Paul Elder
2022-06-25  4:03   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 22/55] media: rkisp1: csi: Move start delay to rkisp1_csi_start() Paul Elder
2022-06-25  4:05   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 23/55] media: rkisp1: csi: Pass sensor pointer to rkisp1_csi_config() Paul Elder
2022-06-25  4:28   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 24/55] media: rkisp1: csi: Constify argument to rkisp1_csi_start() Paul Elder
2022-06-25  4:29   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 25/55] media: rkisp1: isp: Don't initialize ret to 0 in rkisp1_isp_s_stream() Paul Elder
2022-06-25  4:46   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 26/55] media: rkisp1: isp: Pass mbus type and flags to rkisp1_config_cif() Paul Elder
2022-06-25  4:32   ` Dafna Hirschfeld
2022-06-14 19:10 ` [PATCH 27/55] media: rkisp1: isp: Rename rkisp1_device.active_sensor to source Paul Elder
2022-06-30 21:57   ` Dafna Hirschfeld
2022-07-01  4:42   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 28/55] media: rkisp1: isp: Add container_of wrapper to cast subdev to rkisp1_isp Paul Elder
2022-06-25  4:48   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 29/55] media: rkisp1: isp: Add rkisp1_device backpointer " Paul Elder
2022-06-25  4:50   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 30/55] media: rkisp1: isp: Pass rkisp1_isp pointer to internal ISP functions Paul Elder
2022-06-25  4:52   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 31/55] media: rkisp1: isp: Move input configuration to rkisp1_config_isp() Paul Elder
2022-06-25  5:00   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 32/55] media: rkisp1: isp: Merge ISP_ACQ_PROP configuration in single variable Paul Elder
2022-06-25  5:03   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 33/55] media: rkisp1: isp: Initialize some variables at declaration time Paul Elder
2022-06-25  5:04   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 34/55] media: rkisp1: isp: Fix whitespace issues Paul Elder
2022-06-25  5:05   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 35/55] media: rkisp1: isp: Constify various local variables Paul Elder
2022-06-25  5:07   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 36/55] media: rkisp1: isp: Rename rkisp1_get_remote_source() Paul Elder
2022-06-25  5:09   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 37/55] media: mc-entity: Add a new helper function to get a remote pad Paul Elder
2022-06-15 22:38   ` Laurent Pinchart
2022-06-17 11:38   ` Hans Verkuil
2022-06-17 11:48   ` Hans Verkuil
2022-06-25 17:00     ` Laurent Pinchart
2022-06-25 17:28       ` Laurent Pinchart
2022-07-07  6:52       ` Hans Verkuil
2022-07-07 11:50         ` Laurent Pinchart [this message]
2022-06-17 21:34   ` Daniel Scally
2022-06-17 22:33     ` Daniel Scally
2022-06-17 22:40       ` Laurent Pinchart
2022-06-18  9:35         ` Daniel Scally
2022-06-25 17:34           ` Laurent Pinchart
2022-06-14 19:11 ` [PATCH 38/55] media: mc-entity: Add a new helper function to get a remote pad for a pad Paul Elder
2022-06-15 22:38   ` Laurent Pinchart
2022-06-17 11:41   ` Hans Verkuil
2022-06-17 11:48     ` Laurent Pinchart
2022-06-14 19:11 ` [PATCH 39/55] media: rkisp1: isp: Disallow multiple active sources Paul Elder
2022-06-14 19:11 ` [PATCH 40/55] media: rkisp1: csi: Implement a V4L2 subdev for the CSI receiver Paul Elder
2022-06-25  7:00   ` Dafna Hirschfeld
2022-06-25 11:03     ` Laurent Pinchart
2022-07-01  4:48       ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 41/55] media: rkisp1: csi: Plumb the CSI RX subdev Paul Elder
2022-06-15 23:10   ` Laurent Pinchart
2022-06-25  7:45   ` Dafna Hirschfeld
2022-06-25 16:07     ` Laurent Pinchart
2022-06-14 19:11 ` [PATCH 42/55] media: rkisp1: Use fwnode_graph_for_each_endpoint Paul Elder
2022-06-17 22:56   ` Laurent Pinchart
2022-06-14 19:11 ` [PATCH 43/55] dt-bindings: media: rkisp1: Add port for parallel interface Paul Elder
2022-06-17 23:13   ` Laurent Pinchart
2022-07-01  5:22   ` Dafna Hirschfeld
2022-07-01  9:19     ` Laurent Pinchart
2022-06-14 19:11 ` [PATCH 44/55] media: rkisp1: Support the ISP parallel input Paul Elder
2022-06-14 19:11 ` [PATCH 45/55] media: rkisp1: Add infrastructure to support ISP features Paul Elder
2022-06-14 19:11 ` [PATCH 46/55] media: rkisp1: Make the internal CSI-2 receiver optional Paul Elder
2022-06-14 19:11 ` [PATCH 47/55] dt-bindings: media: rkisp1: Add i.MX8MP ISP to compatible Paul Elder
2022-06-17 23:14   ` Laurent Pinchart
2022-06-14 19:11 ` [PATCH 48/55] media: rkisp1: Add match data for i.MX8MP ISP Paul Elder
2022-06-17 23:26   ` Laurent Pinchart
2022-06-26  4:05     ` Dafna Hirschfeld
2022-06-26 11:07       ` Laurent Pinchart
2022-07-04 10:36         ` paul.elder
2022-06-14 19:11 ` [PATCH 49/55] media: rkisp1: Configure gasket on i.MX8MP Paul Elder
2022-06-14 19:11 ` [PATCH 50/55] media: rkisp1: Add and set registers for crop for i.MX8MP Paul Elder
2022-06-26 11:59   ` Laurent Pinchart
2022-07-04 10:37     ` paul.elder
2022-07-01  5:37   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 51/55] media: rkisp1: Add and set registers for output size config on i.MX8MP Paul Elder
2022-06-26 11:46   ` Laurent Pinchart
2022-07-01  5:40   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 52/55] media: rkisp1: Add i.MX8MP-specific registers for MI and resizer Paul Elder
2022-07-01  5:45   ` Dafna Hirschfeld
2022-06-14 19:11 ` [PATCH 53/55] media: rkisp1: Shift DMA buffer addresses on i.MX8MP Paul Elder
2022-06-26 11:38   ` Laurent Pinchart
2022-07-01  5:53     ` Dafna Hirschfeld
2022-07-01  8:38       ` Laurent Pinchart
2022-06-14 19:11 ` [PATCH 54/55] media: rkisp1: Add register definitions for the test pattern generator Paul Elder
2022-06-14 19:11 ` [PATCH 55/55] media: rkisp1: Fix RSZ_CTRL bits for i.MX8MP Paul Elder
2022-06-16  8:05   ` (EXT) " Alexander Stein
2022-06-17 23:03     ` Laurent Pinchart
2022-06-26 11:40       ` Laurent Pinchart
2022-07-04 10:40       ` paul.elder
2022-06-16  0:19 ` [PATCH 00/55] media: rkisp1: Cleanups and add support " Laurent Pinchart

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=YsbIltES0oblIsDb@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dafna@fastmail.com \
    --cc=djrscally@gmail.com \
    --cc=heiko@sntech.de \
    --cc=helen.koike@collabora.com \
    --cc=hverkuil@xs4all.nl \
    --cc=jacopo@jmondi.org \
    --cc=jeanmichel.hautbois@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=paul.elder@ideasonboard.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).