1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2010 Nokia Corporation
7 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 * Sakari Ailus <sakari.ailus@iki.fi>
11 #include <linux/bitmap.h>
12 #include <linux/property.h>
13 #include <linux/slab.h>
14 #include <media/media-entity.h>
15 #include <media/media-device.h>
17 static inline const char *gobj_type(enum media_gobj_type type)
20 case MEDIA_GRAPH_ENTITY:
24 case MEDIA_GRAPH_LINK:
26 case MEDIA_GRAPH_INTF_DEVNODE:
27 return "intf-devnode";
33 static inline const char *intf_type(struct media_interface *intf)
36 case MEDIA_INTF_T_DVB_FE:
37 return "dvb-frontend";
38 case MEDIA_INTF_T_DVB_DEMUX:
40 case MEDIA_INTF_T_DVB_DVR:
42 case MEDIA_INTF_T_DVB_CA:
44 case MEDIA_INTF_T_DVB_NET:
46 case MEDIA_INTF_T_V4L_VIDEO:
48 case MEDIA_INTF_T_V4L_VBI:
50 case MEDIA_INTF_T_V4L_RADIO:
52 case MEDIA_INTF_T_V4L_SUBDEV:
54 case MEDIA_INTF_T_V4L_SWRADIO:
56 case MEDIA_INTF_T_V4L_TOUCH:
59 return "unknown-intf";
63 __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
66 idx_max = ALIGN(idx_max, BITS_PER_LONG);
67 ent_enum->bmap = kcalloc(idx_max / BITS_PER_LONG, sizeof(long),
72 bitmap_zero(ent_enum->bmap, idx_max);
73 ent_enum->idx_max = idx_max;
77 EXPORT_SYMBOL_GPL(__media_entity_enum_init);
79 void media_entity_enum_cleanup(struct media_entity_enum *ent_enum)
81 kfree(ent_enum->bmap);
83 EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
86 * dev_dbg_obj - Prints in debug mode a change on some object
88 * @event_name: Name of the event to report. Could be __func__
89 * @gobj: Pointer to the object
91 * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
92 * won't produce any code.
94 static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj)
96 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
97 switch (media_type(gobj)) {
98 case MEDIA_GRAPH_ENTITY:
99 dev_dbg(gobj->mdev->dev,
100 "%s id %u: entity '%s'\n",
101 event_name, media_id(gobj),
102 gobj_to_entity(gobj)->name);
104 case MEDIA_GRAPH_LINK:
106 struct media_link *link = gobj_to_link(gobj);
108 dev_dbg(gobj->mdev->dev,
109 "%s id %u: %s link id %u ==> id %u\n",
110 event_name, media_id(gobj),
111 media_type(link->gobj0) == MEDIA_GRAPH_PAD ?
112 "data" : "interface",
113 media_id(link->gobj0),
114 media_id(link->gobj1));
117 case MEDIA_GRAPH_PAD:
119 struct media_pad *pad = gobj_to_pad(gobj);
121 dev_dbg(gobj->mdev->dev,
122 "%s id %u: %s%spad '%s':%d\n",
123 event_name, media_id(gobj),
124 pad->flags & MEDIA_PAD_FL_SINK ? "sink " : "",
125 pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
126 pad->entity->name, pad->index);
129 case MEDIA_GRAPH_INTF_DEVNODE:
131 struct media_interface *intf = gobj_to_intf(gobj);
132 struct media_intf_devnode *devnode = intf_to_devnode(intf);
134 dev_dbg(gobj->mdev->dev,
135 "%s id %u: intf_devnode %s - major: %d, minor: %d\n",
136 event_name, media_id(gobj),
138 devnode->major, devnode->minor);
145 void media_gobj_create(struct media_device *mdev,
146 enum media_gobj_type type,
147 struct media_gobj *gobj)
153 /* Create a per-type unique object ID */
154 gobj->id = media_gobj_gen_id(type, ++mdev->id);
157 case MEDIA_GRAPH_ENTITY:
158 list_add_tail(&gobj->list, &mdev->entities);
160 case MEDIA_GRAPH_PAD:
161 list_add_tail(&gobj->list, &mdev->pads);
163 case MEDIA_GRAPH_LINK:
164 list_add_tail(&gobj->list, &mdev->links);
166 case MEDIA_GRAPH_INTF_DEVNODE:
167 list_add_tail(&gobj->list, &mdev->interfaces);
171 mdev->topology_version++;
173 dev_dbg_obj(__func__, gobj);
176 void media_gobj_destroy(struct media_gobj *gobj)
178 /* Do nothing if the object is not linked. */
179 if (gobj->mdev == NULL)
182 dev_dbg_obj(__func__, gobj);
184 gobj->mdev->topology_version++;
186 /* Remove the object from mdev list */
187 list_del(&gobj->list);
193 * TODO: Get rid of this.
195 #define MEDIA_ENTITY_MAX_PADS 512
197 int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
198 struct media_pad *pads)
200 struct media_device *mdev = entity->graph_obj.mdev;
203 if (num_pads >= MEDIA_ENTITY_MAX_PADS)
206 entity->num_pads = num_pads;
210 mutex_lock(&mdev->graph_mutex);
212 for (i = 0; i < num_pads; i++) {
213 pads[i].entity = entity;
216 media_gobj_create(mdev, MEDIA_GRAPH_PAD,
217 &entity->pads[i].graph_obj);
221 mutex_unlock(&mdev->graph_mutex);
225 EXPORT_SYMBOL_GPL(media_entity_pads_init);
227 /* -----------------------------------------------------------------------------
231 static struct media_entity *
232 media_entity_other(struct media_entity *entity, struct media_link *link)
234 if (link->source->entity == entity)
235 return link->sink->entity;
237 return link->source->entity;
240 /* push an entity to traversal stack */
241 static void stack_push(struct media_graph *graph,
242 struct media_entity *entity)
244 if (graph->top == MEDIA_ENTITY_ENUM_MAX_DEPTH - 1) {
249 graph->stack[graph->top].link = entity->links.next;
250 graph->stack[graph->top].entity = entity;
253 static struct media_entity *stack_pop(struct media_graph *graph)
255 struct media_entity *entity;
257 entity = graph->stack[graph->top].entity;
263 #define link_top(en) ((en)->stack[(en)->top].link)
264 #define stack_top(en) ((en)->stack[(en)->top].entity)
267 * media_graph_walk_init - Allocate resources for graph walk
268 * @graph: Media graph structure that will be used to walk the graph
269 * @mdev: Media device
271 * Reserve resources for graph walk in media device's current
272 * state. The memory must be released using
273 * media_graph_walk_free().
275 * Returns error on failure, zero on success.
277 __must_check int media_graph_walk_init(
278 struct media_graph *graph, struct media_device *mdev)
280 return media_entity_enum_init(&graph->ent_enum, mdev);
282 EXPORT_SYMBOL_GPL(media_graph_walk_init);
285 * media_graph_walk_cleanup - Release resources related to graph walking
286 * @graph: Media graph structure that was used to walk the graph
288 void media_graph_walk_cleanup(struct media_graph *graph)
290 media_entity_enum_cleanup(&graph->ent_enum);
292 EXPORT_SYMBOL_GPL(media_graph_walk_cleanup);
294 void media_graph_walk_start(struct media_graph *graph,
295 struct media_entity *entity)
297 media_entity_enum_zero(&graph->ent_enum);
298 media_entity_enum_set(&graph->ent_enum, entity);
301 graph->stack[graph->top].entity = NULL;
302 stack_push(graph, entity);
303 dev_dbg(entity->graph_obj.mdev->dev,
304 "begin graph walk at '%s'\n", entity->name);
306 EXPORT_SYMBOL_GPL(media_graph_walk_start);
308 static void media_graph_walk_iter(struct media_graph *graph)
310 struct media_entity *entity = stack_top(graph);
311 struct media_link *link;
312 struct media_entity *next;
314 link = list_entry(link_top(graph), typeof(*link), list);
316 /* The link is not enabled so we do not follow. */
317 if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
318 link_top(graph) = link_top(graph)->next;
319 dev_dbg(entity->graph_obj.mdev->dev,
320 "walk: skipping disabled link '%s':%u -> '%s':%u\n",
321 link->source->entity->name, link->source->index,
322 link->sink->entity->name, link->sink->index);
326 /* Get the entity in the other end of the link . */
327 next = media_entity_other(entity, link);
329 /* Has the entity already been visited? */
330 if (media_entity_enum_test_and_set(&graph->ent_enum, next)) {
331 link_top(graph) = link_top(graph)->next;
332 dev_dbg(entity->graph_obj.mdev->dev,
333 "walk: skipping entity '%s' (already seen)\n",
338 /* Push the new entity to stack and start over. */
339 link_top(graph) = link_top(graph)->next;
340 stack_push(graph, next);
341 dev_dbg(entity->graph_obj.mdev->dev, "walk: pushing '%s' on stack\n",
345 struct media_entity *media_graph_walk_next(struct media_graph *graph)
347 struct media_entity *entity;
349 if (stack_top(graph) == NULL)
353 * Depth first search. Push entity to stack and continue from
354 * top of the stack until no more entities on the level can be
357 while (link_top(graph) != &stack_top(graph)->links)
358 media_graph_walk_iter(graph);
360 entity = stack_pop(graph);
361 dev_dbg(entity->graph_obj.mdev->dev,
362 "walk: returning entity '%s'\n", entity->name);
366 EXPORT_SYMBOL_GPL(media_graph_walk_next);
368 int media_entity_get_fwnode_pad(struct media_entity *entity,
369 struct fwnode_handle *fwnode,
370 unsigned long direction_flags)
372 struct fwnode_endpoint endpoint;
376 if (!entity->ops || !entity->ops->get_fwnode_pad) {
377 for (i = 0; i < entity->num_pads; i++) {
378 if (entity->pads[i].flags & direction_flags)
385 ret = fwnode_graph_parse_endpoint(fwnode, &endpoint);
389 ret = entity->ops->get_fwnode_pad(entity, &endpoint);
393 if (ret >= entity->num_pads)
396 if (!(entity->pads[ret].flags & direction_flags))
401 EXPORT_SYMBOL_GPL(media_entity_get_fwnode_pad);
403 /* -----------------------------------------------------------------------------
404 * Pipeline management
407 __must_check int __media_pipeline_start(struct media_entity *entity,
408 struct media_pipeline *pipe)
410 struct media_device *mdev = entity->graph_obj.mdev;
411 struct media_graph *graph = &pipe->graph;
412 struct media_entity *entity_err = entity;
413 struct media_link *link;
416 if (!pipe->streaming_count++) {
417 ret = media_graph_walk_init(&pipe->graph, mdev);
419 goto error_graph_walk_start;
422 media_graph_walk_start(&pipe->graph, entity);
424 while ((entity = media_graph_walk_next(graph))) {
425 DECLARE_BITMAP(active, MEDIA_ENTITY_MAX_PADS);
426 DECLARE_BITMAP(has_no_links, MEDIA_ENTITY_MAX_PADS);
428 entity->stream_count++;
430 if (entity->pipe && entity->pipe != pipe) {
431 pr_err("Pipe active for %s. Can't start for %s\n",
440 /* Already streaming --- no need to check. */
441 if (entity->stream_count > 1)
444 if (!entity->ops || !entity->ops->link_validate)
447 bitmap_zero(active, entity->num_pads);
448 bitmap_fill(has_no_links, entity->num_pads);
450 list_for_each_entry(link, &entity->links, list) {
451 struct media_pad *pad = link->sink->entity == entity
452 ? link->sink : link->source;
454 /* Mark that a pad is connected by a link. */
455 bitmap_clear(has_no_links, pad->index, 1);
458 * Pads that either do not need to connect or
459 * are connected through an enabled link are
462 if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
463 link->flags & MEDIA_LNK_FL_ENABLED)
464 bitmap_set(active, pad->index, 1);
467 * Link validation will only take place for
468 * sink ends of the link that are enabled.
470 if (link->sink != pad ||
471 !(link->flags & MEDIA_LNK_FL_ENABLED))
474 ret = entity->ops->link_validate(link);
475 if (ret < 0 && ret != -ENOIOCTLCMD) {
476 dev_dbg(entity->graph_obj.mdev->dev,
477 "link validation failed for '%s':%u -> '%s':%u, error %d\n",
478 link->source->entity->name,
480 entity->name, link->sink->index, ret);
485 /* Either no links or validated links are fine. */
486 bitmap_or(active, active, has_no_links, entity->num_pads);
488 if (!bitmap_full(active, entity->num_pads)) {
490 dev_dbg(entity->graph_obj.mdev->dev,
491 "'%s':%u must be connected by an enabled link\n",
493 (unsigned)find_first_zero_bit(
494 active, entity->num_pads));
503 * Link validation on graph failed. We revert what we did and
506 media_graph_walk_start(graph, entity_err);
508 while ((entity_err = media_graph_walk_next(graph))) {
509 /* Sanity check for negative stream_count */
510 if (!WARN_ON_ONCE(entity_err->stream_count <= 0)) {
511 entity_err->stream_count--;
512 if (entity_err->stream_count == 0)
513 entity_err->pipe = NULL;
517 * We haven't increased stream_count further than this
520 if (entity_err == entity)
524 error_graph_walk_start:
525 if (!--pipe->streaming_count)
526 media_graph_walk_cleanup(graph);
530 EXPORT_SYMBOL_GPL(__media_pipeline_start);
532 __must_check int media_pipeline_start(struct media_entity *entity,
533 struct media_pipeline *pipe)
535 struct media_device *mdev = entity->graph_obj.mdev;
538 mutex_lock(&mdev->graph_mutex);
539 ret = __media_pipeline_start(entity, pipe);
540 mutex_unlock(&mdev->graph_mutex);
543 EXPORT_SYMBOL_GPL(media_pipeline_start);
545 void __media_pipeline_stop(struct media_entity *entity)
547 struct media_graph *graph = &entity->pipe->graph;
548 struct media_pipeline *pipe = entity->pipe;
551 * If the following check fails, the driver has performed an
552 * unbalanced call to media_pipeline_stop()
557 media_graph_walk_start(graph, entity);
559 while ((entity = media_graph_walk_next(graph))) {
560 /* Sanity check for negative stream_count */
561 if (!WARN_ON_ONCE(entity->stream_count <= 0)) {
562 entity->stream_count--;
563 if (entity->stream_count == 0)
568 if (!--pipe->streaming_count)
569 media_graph_walk_cleanup(graph);
572 EXPORT_SYMBOL_GPL(__media_pipeline_stop);
574 void media_pipeline_stop(struct media_entity *entity)
576 struct media_device *mdev = entity->graph_obj.mdev;
578 mutex_lock(&mdev->graph_mutex);
579 __media_pipeline_stop(entity);
580 mutex_unlock(&mdev->graph_mutex);
582 EXPORT_SYMBOL_GPL(media_pipeline_stop);
584 /* -----------------------------------------------------------------------------
588 static struct media_link *media_add_link(struct list_head *head)
590 struct media_link *link;
592 link = kzalloc(sizeof(*link), GFP_KERNEL);
596 list_add_tail(&link->list, head);
601 static void __media_entity_remove_link(struct media_entity *entity,
602 struct media_link *link)
604 struct media_link *rlink, *tmp;
605 struct media_entity *remote;
607 if (link->source->entity == entity)
608 remote = link->sink->entity;
610 remote = link->source->entity;
612 list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
613 if (rlink != link->reverse)
616 if (link->source->entity == entity)
617 remote->num_backlinks--;
619 /* Remove the remote link */
620 list_del(&rlink->list);
621 media_gobj_destroy(&rlink->graph_obj);
624 if (--remote->num_links == 0)
627 list_del(&link->list);
628 media_gobj_destroy(&link->graph_obj);
632 int media_get_pad_index(struct media_entity *entity, bool is_sink,
633 enum media_pad_signal_type sig_type)
641 for (i = 0; i < entity->num_pads; i++) {
642 if (entity->pads[i].flags & MEDIA_PAD_FL_SINK)
644 else if (entity->pads[i].flags & MEDIA_PAD_FL_SOURCE)
647 continue; /* This is an error! */
649 if (pad_is_sink != is_sink)
651 if (entity->pads[i].sig_type == sig_type)
656 EXPORT_SYMBOL_GPL(media_get_pad_index);
659 media_create_pad_link(struct media_entity *source, u16 source_pad,
660 struct media_entity *sink, u16 sink_pad, u32 flags)
662 struct media_link *link;
663 struct media_link *backlink;
665 if (WARN_ON(!source || !sink) ||
666 WARN_ON(source_pad >= source->num_pads) ||
667 WARN_ON(sink_pad >= sink->num_pads))
669 if (WARN_ON(!(source->pads[source_pad].flags & MEDIA_PAD_FL_SOURCE)))
671 if (WARN_ON(!(sink->pads[sink_pad].flags & MEDIA_PAD_FL_SINK)))
674 link = media_add_link(&source->links);
678 link->source = &source->pads[source_pad];
679 link->sink = &sink->pads[sink_pad];
680 link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK;
682 /* Initialize graph object embedded at the new link */
683 media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
686 /* Create the backlink. Backlinks are used to help graph traversal and
687 * are not reported to userspace.
689 backlink = media_add_link(&sink->links);
690 if (backlink == NULL) {
691 __media_entity_remove_link(source, link);
695 backlink->source = &source->pads[source_pad];
696 backlink->sink = &sink->pads[sink_pad];
697 backlink->flags = flags;
698 backlink->is_backlink = true;
700 /* Initialize graph object embedded at the new link */
701 media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
702 &backlink->graph_obj);
704 link->reverse = backlink;
705 backlink->reverse = link;
707 sink->num_backlinks++;
713 EXPORT_SYMBOL_GPL(media_create_pad_link);
715 int media_create_pad_links(const struct media_device *mdev,
716 const u32 source_function,
717 struct media_entity *source,
718 const u16 source_pad,
719 const u32 sink_function,
720 struct media_entity *sink,
723 const bool allow_both_undefined)
725 struct media_entity *entity;
729 /* Trivial case: 1:1 relation */
731 return media_create_pad_link(source, source_pad,
732 sink, sink_pad, flags);
734 /* Worse case scenario: n:n relation */
735 if (!source && !sink) {
736 if (!allow_both_undefined)
738 media_device_for_each_entity(source, mdev) {
739 if (source->function != source_function)
741 media_device_for_each_entity(sink, mdev) {
742 if (sink->function != sink_function)
744 ret = media_create_pad_link(source, source_pad,
749 flags &= ~(MEDIA_LNK_FL_ENABLED |
750 MEDIA_LNK_FL_IMMUTABLE);
756 /* Handle 1:n and n:1 cases */
758 function = sink_function;
760 function = source_function;
762 media_device_for_each_entity(entity, mdev) {
763 if (entity->function != function)
767 ret = media_create_pad_link(source, source_pad,
768 entity, sink_pad, flags);
770 ret = media_create_pad_link(entity, source_pad,
771 sink, sink_pad, flags);
774 flags &= ~(MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
778 EXPORT_SYMBOL_GPL(media_create_pad_links);
780 void __media_entity_remove_links(struct media_entity *entity)
782 struct media_link *link, *tmp;
784 list_for_each_entry_safe(link, tmp, &entity->links, list)
785 __media_entity_remove_link(entity, link);
787 entity->num_links = 0;
788 entity->num_backlinks = 0;
790 EXPORT_SYMBOL_GPL(__media_entity_remove_links);
792 void media_entity_remove_links(struct media_entity *entity)
794 struct media_device *mdev = entity->graph_obj.mdev;
796 /* Do nothing if the entity is not registered. */
800 mutex_lock(&mdev->graph_mutex);
801 __media_entity_remove_links(entity);
802 mutex_unlock(&mdev->graph_mutex);
804 EXPORT_SYMBOL_GPL(media_entity_remove_links);
806 static int __media_entity_setup_link_notify(struct media_link *link, u32 flags)
810 /* Notify both entities. */
811 ret = media_entity_call(link->source->entity, link_setup,
812 link->source, link->sink, flags);
813 if (ret < 0 && ret != -ENOIOCTLCMD)
816 ret = media_entity_call(link->sink->entity, link_setup,
817 link->sink, link->source, flags);
818 if (ret < 0 && ret != -ENOIOCTLCMD) {
819 media_entity_call(link->source->entity, link_setup,
820 link->source, link->sink, link->flags);
825 link->reverse->flags = link->flags;
830 int __media_entity_setup_link(struct media_link *link, u32 flags)
832 const u32 mask = MEDIA_LNK_FL_ENABLED;
833 struct media_device *mdev;
834 struct media_entity *source, *sink;
840 /* The non-modifiable link flags must not be modified. */
841 if ((link->flags & ~mask) != (flags & ~mask))
844 if (link->flags & MEDIA_LNK_FL_IMMUTABLE)
845 return link->flags == flags ? 0 : -EINVAL;
847 if (link->flags == flags)
850 source = link->source->entity;
851 sink = link->sink->entity;
853 if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) &&
854 (source->stream_count || sink->stream_count))
857 mdev = source->graph_obj.mdev;
859 if (mdev->ops && mdev->ops->link_notify) {
860 ret = mdev->ops->link_notify(link, flags,
861 MEDIA_DEV_NOTIFY_PRE_LINK_CH);
866 ret = __media_entity_setup_link_notify(link, flags);
868 if (mdev->ops && mdev->ops->link_notify)
869 mdev->ops->link_notify(link, flags,
870 MEDIA_DEV_NOTIFY_POST_LINK_CH);
874 EXPORT_SYMBOL_GPL(__media_entity_setup_link);
876 int media_entity_setup_link(struct media_link *link, u32 flags)
880 mutex_lock(&link->graph_obj.mdev->graph_mutex);
881 ret = __media_entity_setup_link(link, flags);
882 mutex_unlock(&link->graph_obj.mdev->graph_mutex);
886 EXPORT_SYMBOL_GPL(media_entity_setup_link);
889 media_entity_find_link(struct media_pad *source, struct media_pad *sink)
891 struct media_link *link;
893 list_for_each_entry(link, &source->entity->links, list) {
894 if (link->source->entity == source->entity &&
895 link->source->index == source->index &&
896 link->sink->entity == sink->entity &&
897 link->sink->index == sink->index)
903 EXPORT_SYMBOL_GPL(media_entity_find_link);
905 struct media_pad *media_entity_remote_pad(const struct media_pad *pad)
907 struct media_link *link;
909 list_for_each_entry(link, &pad->entity->links, list) {
910 if (!(link->flags & MEDIA_LNK_FL_ENABLED))
913 if (link->source == pad)
916 if (link->sink == pad)
923 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
925 static void media_interface_init(struct media_device *mdev,
926 struct media_interface *intf,
928 u32 intf_type, u32 flags)
930 intf->type = intf_type;
932 INIT_LIST_HEAD(&intf->links);
934 media_gobj_create(mdev, gobj_type, &intf->graph_obj);
937 /* Functions related to the media interface via device nodes */
939 struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
941 u32 major, u32 minor)
943 struct media_intf_devnode *devnode;
945 devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
949 devnode->major = major;
950 devnode->minor = minor;
952 media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
957 EXPORT_SYMBOL_GPL(media_devnode_create);
959 void media_devnode_remove(struct media_intf_devnode *devnode)
961 media_remove_intf_links(&devnode->intf);
962 media_gobj_destroy(&devnode->intf.graph_obj);
965 EXPORT_SYMBOL_GPL(media_devnode_remove);
967 struct media_link *media_create_intf_link(struct media_entity *entity,
968 struct media_interface *intf,
971 struct media_link *link;
973 link = media_add_link(&intf->links);
978 link->entity = entity;
979 link->flags = flags | MEDIA_LNK_FL_INTERFACE_LINK;
981 /* Initialize graph object embedded at the new link */
982 media_gobj_create(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
987 EXPORT_SYMBOL_GPL(media_create_intf_link);
989 void __media_remove_intf_link(struct media_link *link)
991 list_del(&link->list);
992 media_gobj_destroy(&link->graph_obj);
995 EXPORT_SYMBOL_GPL(__media_remove_intf_link);
997 void media_remove_intf_link(struct media_link *link)
999 struct media_device *mdev = link->graph_obj.mdev;
1001 /* Do nothing if the intf is not registered. */
1005 mutex_lock(&mdev->graph_mutex);
1006 __media_remove_intf_link(link);
1007 mutex_unlock(&mdev->graph_mutex);
1009 EXPORT_SYMBOL_GPL(media_remove_intf_link);
1011 void __media_remove_intf_links(struct media_interface *intf)
1013 struct media_link *link, *tmp;
1015 list_for_each_entry_safe(link, tmp, &intf->links, list)
1016 __media_remove_intf_link(link);
1019 EXPORT_SYMBOL_GPL(__media_remove_intf_links);
1021 void media_remove_intf_links(struct media_interface *intf)
1023 struct media_device *mdev = intf->graph_obj.mdev;
1025 /* Do nothing if the intf is not registered. */
1029 mutex_lock(&mdev->graph_mutex);
1030 __media_remove_intf_links(intf);
1031 mutex_unlock(&mdev->graph_mutex);
1033 EXPORT_SYMBOL_GPL(media_remove_intf_links);