Lines Matching refs:entity

2  * Media entity
26 #include <media/media-entity.h>
30 * media_entity_init - Initialize a media entity
37 * entity driver, while the total number of links depends on hardware design
38 * and is an extrinsic property unknown to the entity driver. However, in most
39 * use cases the entity driver can guess the number of links which can safely
42 * For those reasons the links array can be preallocated based on the entity
50 * The pads array is managed by the entity driver and passed to
51 * media_entity_init() where its pointer will be stored in the entity structure.
54 media_entity_init(struct media_entity *entity, u16 num_pads,
65 entity->group_id = 0;
66 entity->max_links = max_links;
67 entity->num_links = 0;
68 entity->num_backlinks = 0;
69 entity->num_pads = num_pads;
70 entity->pads = pads;
71 entity->links = links;
74 pads[i].entity = entity;
83 media_entity_cleanup(struct media_entity *entity)
85 kfree(entity->links);
94 media_entity_other(struct media_entity *entity, struct media_link *link)
96 if (link->source->entity == entity)
97 return link->sink->entity;
99 return link->source->entity;
102 /* push an entity to traversal stack */
104 struct media_entity *entity)
112 graph->stack[graph->top].entity = entity;
117 struct media_entity *entity;
119 entity = graph->stack[graph->top].entity;
122 return entity;
126 #define stack_top(en) ((en)->stack[(en)->top].entity)
129 * media_entity_graph_walk_start - Start walking the media graph at a given entity
131 * @entity: Starting entity
134 * graph starting at the given entity. The traversal structure must not be
139 struct media_entity *entity)
142 graph->stack[graph->top].entity = NULL;
145 if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
148 __set_bit(entity->id, graph->entities);
149 stack_push(graph, entity);
154 * media_entity_graph_walk_next - Get the next entity in the graph
162 * Return the next entity in the graph or NULL if the whole graph have been
172 * Depth first search. Push entity to stack and continue from
177 struct media_entity *entity = stack_top(graph);
178 struct media_link *link = &entity->links[link_top(graph)];
187 /* Get the entity in the other end of the link . */
188 next = media_entity_other(entity, link);
192 /* Has the entity already been visited? */
198 /* Push the new entity to stack and start over. */
213 * @entity: Starting entity
216 * Mark all entities connected to a given entity through enabled links, either
218 * every entity in the pipeline and stored in the media_entity pipe field.
225 __must_check int media_entity_pipeline_start(struct media_entity *entity,
228 struct media_device *mdev = entity->parent;
230 struct media_entity *entity_err = entity;
235 media_entity_graph_walk_start(&graph, entity);
237 while ((entity = media_entity_graph_walk_next(&graph))) {
238 DECLARE_BITMAP(active, entity->num_pads);
239 DECLARE_BITMAP(has_no_links, entity->num_pads);
242 entity->stream_count++;
243 WARN_ON(entity->pipe && entity->pipe != pipe);
244 entity->pipe = pipe;
247 if (entity->stream_count > 1)
250 if (!entity->ops || !entity->ops->link_validate)
253 bitmap_zero(active, entity->num_pads);
254 bitmap_fill(has_no_links, entity->num_pads);
256 for (i = 0; i < entity->num_links; i++) {
257 struct media_link *link = &entity->links[i];
258 struct media_pad *pad = link->sink->entity == entity
281 ret = entity->ops->link_validate(link);
287 bitmap_or(active, active, has_no_links, entity->num_pads);
289 if (!bitmap_full(active, entity->num_pads)) {
315 if (entity_err == entity)
327 * @entity: Starting entity
329 * Mark all entities connected to a given entity through enabled links, either
337 void media_entity_pipeline_stop(struct media_entity *entity)
339 struct media_device *mdev = entity->parent;
344 media_entity_graph_walk_start(&graph, entity);
346 while ((entity = media_entity_graph_walk_next(&graph))) {
347 entity->stream_count--;
348 if (entity->stream_count == 0)
349 entity->pipe = NULL;
362 * @entity: The entity
366 * The function will return immediately if @entity is NULL.
368 * Return a pointer to the entity on success or NULL on failure.
370 struct media_entity *media_entity_get(struct media_entity *entity)
372 if (entity == NULL)
375 if (entity->parent->dev &&
376 !try_module_get(entity->parent->dev->driver->owner))
379 return entity;
385 * @entity: The entity
389 * The function will return immediately if @entity is NULL.
391 void media_entity_put(struct media_entity *entity)
393 if (entity == NULL)
396 if (entity->parent->dev)
397 module_put(entity->parent->dev->driver->owner);
405 static struct media_link *media_entity_add_link(struct media_entity *entity)
407 if (entity->num_links >= entity->max_links) {
408 struct media_link *links = entity->links;
409 unsigned int max_links = entity->max_links + 2;
416 for (i = 0; i < entity->num_links; i++)
419 entity->max_links = max_links;
420 entity->links = links;
423 return &entity->links[entity->num_links++];
467 void __media_entity_remove_links(struct media_entity *entity)
471 for (i = 0; i < entity->num_links; i++) {
472 struct media_link *link = &entity->links[i];
476 if (link->source->entity == entity)
477 remote = link->sink->entity;
479 remote = link->source->entity;
489 if (link->source->entity == entity)
500 entity->num_links = 0;
501 entity->num_backlinks = 0;
505 void media_entity_remove_links(struct media_entity *entity)
507 /* Do nothing if the entity is not registered. */
508 if (entity->parent == NULL)
511 mutex_lock(&entity->parent->graph_mutex);
512 __media_entity_remove_links(entity);
513 mutex_unlock(&entity->parent->graph_mutex);
522 ret = media_entity_call(link->source->entity, link_setup,
527 ret = media_entity_call(link->sink->entity, link_setup,
530 media_entity_call(link->source->entity, link_setup,
575 source = link->source->entity;
576 sink = link->sink->entity;
603 mutex_lock(&link->source->entity->parent->graph_mutex);
605 mutex_unlock(&link->source->entity->parent->graph_mutex);
625 for (i = 0; i < source->entity->num_links; ++i) {
626 link = &source->entity->links[i];
628 if (link->source->entity == source->entity &&
630 link->sink->entity == sink->entity &&
653 for (i = 0; i < pad->entity->num_links; i++) {
654 struct media_link *link = &pad->entity->links[i];