Message ID | 20210427124523.990938-13-tomi.valkeinen@ideasonboard.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | v4l: subdev internal routing | expand |
Hi Tomi, Thank you for the patch. On Tue, Apr 27, 2021 at 03:45:11PM +0300, Tomi Valkeinen wrote: > Add a helper macro for iterating over pads that are connected through > enabled routes. This can be used to find all the connected pads within an > entity, for instance starting from the pad which has been obtained during > the graph walk. > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> > > - Make __media_entity_next_routed_pad() return NULL and adjust the > iterator to handle that > Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > --- > include/media/media-entity.h | 28 ++++++++++++++++++++++++++++ > 1 file changed, 28 insertions(+) > > diff --git a/include/media/media-entity.h b/include/media/media-entity.h > index f8fa952fa38e..42193d6c58e9 100644 > --- a/include/media/media-entity.h > +++ b/include/media/media-entity.h > @@ -916,6 +916,34 @@ __must_check int media_graph_walk_init( > bool media_entity_has_route(struct media_entity *entity, unsigned int pad0, > unsigned int pad1); > > +static inline struct media_pad *__media_entity_next_routed_pad( > + struct media_pad *start, struct media_pad *iter) > +{ > + struct media_entity *entity = start->entity; > + > + for (; iter < &entity->pads[entity->num_pads]; iter++) { > + if (media_entity_has_route(entity, start->index, iter->index)) > + return iter; > + } > + > + return NULL; > +} > + > +/** > + * media_entity_for_each_routed_pad - Iterate over entity pads connected by routes > + * > + * @start: The starting pad > + * @iter: The iterator pad > + * > + * Iterate over all pads connected through routes from the @start pad > + * within an entity. The iteration will include the @start pad itself. > + */ I still think a better name would be, well, better :-) Let's continue the discussion in the v5 thread to avoid splitting it. > +#define media_entity_for_each_routed_pad(start, iter) \ > + for (iter = __media_entity_next_routed_pad( \ > + start, (start)->entity->pads); \ > + iter != NULL; \ > + iter = __media_entity_next_routed_pad(start, iter + 1)) > + > /** > * media_graph_walk_cleanup - Release resources used by graph walk. > *
On 29/04/2021 05:18, Laurent Pinchart wrote: > Hi Tomi, > > Thank you for the patch. > > On Tue, Apr 27, 2021 at 03:45:11PM +0300, Tomi Valkeinen wrote: >> Add a helper macro for iterating over pads that are connected through >> enabled routes. This can be used to find all the connected pads within an >> entity, for instance starting from the pad which has been obtained during >> the graph walk. >> >> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> >> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> >> >> - Make __media_entity_next_routed_pad() return NULL and adjust the >> iterator to handle that >> Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org> >> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> >> --- >> include/media/media-entity.h | 28 ++++++++++++++++++++++++++++ >> 1 file changed, 28 insertions(+) >> >> diff --git a/include/media/media-entity.h b/include/media/media-entity.h >> index f8fa952fa38e..42193d6c58e9 100644 >> --- a/include/media/media-entity.h >> +++ b/include/media/media-entity.h >> @@ -916,6 +916,34 @@ __must_check int media_graph_walk_init( >> bool media_entity_has_route(struct media_entity *entity, unsigned int pad0, >> unsigned int pad1); >> >> +static inline struct media_pad *__media_entity_next_routed_pad( >> + struct media_pad *start, struct media_pad *iter) >> +{ >> + struct media_entity *entity = start->entity; >> + >> + for (; iter < &entity->pads[entity->num_pads]; iter++) { >> + if (media_entity_has_route(entity, start->index, iter->index)) >> + return iter; >> + } >> + >> + return NULL; >> +} >> + >> +/** >> + * media_entity_for_each_routed_pad - Iterate over entity pads connected by routes >> + * >> + * @start: The starting pad >> + * @iter: The iterator pad >> + * >> + * Iterate over all pads connected through routes from the @start pad >> + * within an entity. The iteration will include the @start pad itself. >> + */ > > I still think a better name would be, well, better :-) Let's continue > the discussion in the v5 thread to avoid splitting it. I removed the inlining of __media_entity_next_routed_pad and renamed 'start' to 'root'. If anyone has a better name idea, let's hear it =). But I think this at least removes the confusion of the parameter somehow defining the start pad. Tomi >> +#define media_entity_for_each_routed_pad(start, iter) \ >> + for (iter = __media_entity_next_routed_pad( \ >> + start, (start)->entity->pads); \ >> + iter != NULL; \ >> + iter = __media_entity_next_routed_pad(start, iter + 1)) >> + >> /** >> * media_graph_walk_cleanup - Release resources used by graph walk. >> * >
diff --git a/include/media/media-entity.h b/include/media/media-entity.h index f8fa952fa38e..42193d6c58e9 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -916,6 +916,34 @@ __must_check int media_graph_walk_init( bool media_entity_has_route(struct media_entity *entity, unsigned int pad0, unsigned int pad1); +static inline struct media_pad *__media_entity_next_routed_pad( + struct media_pad *start, struct media_pad *iter) +{ + struct media_entity *entity = start->entity; + + for (; iter < &entity->pads[entity->num_pads]; iter++) { + if (media_entity_has_route(entity, start->index, iter->index)) + return iter; + } + + return NULL; +} + +/** + * media_entity_for_each_routed_pad - Iterate over entity pads connected by routes + * + * @start: The starting pad + * @iter: The iterator pad + * + * Iterate over all pads connected through routes from the @start pad + * within an entity. The iteration will include the @start pad itself. + */ +#define media_entity_for_each_routed_pad(start, iter) \ + for (iter = __media_entity_next_routed_pad( \ + start, (start)->entity->pads); \ + iter != NULL; \ + iter = __media_entity_next_routed_pad(start, iter + 1)) + /** * media_graph_walk_cleanup - Release resources used by graph walk. *