4 * Copyright (C) 2010 Nokia Corporation
6 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/bitmap.h>
20 #include <linux/property.h>
21 #include <linux/slab.h>
22 #include <media/media-entity.h>
23 #include <media/media-device.h>
25 static inline const char *gobj_type(enum media_gobj_type type)
28 case MEDIA_GRAPH_ENTITY:
32 case MEDIA_GRAPH_LINK:
34 case MEDIA_GRAPH_INTF_DEVNODE:
35 return "intf-devnode";
41 static inline const char *intf_type(struct media_interface *intf)
44 case MEDIA_INTF_T_DVB_FE:
45 return "dvb-frontend";
46 case MEDIA_INTF_T_DVB_DEMUX:
48 case MEDIA_INTF_T_DVB_DVR:
50 case MEDIA_INTF_T_DVB_CA:
52 case MEDIA_INTF_T_DVB_NET:
54 case MEDIA_INTF_T_V4L_VIDEO:
56 case MEDIA_INTF_T_V4L_VBI:
58 case MEDIA_INTF_T_V4L_RADIO:
60 case MEDIA_INTF_T_V4L_SUBDEV:
62 case MEDIA_INTF_T_V4L_SWRADIO:
64 case MEDIA_INTF_T_V4L_TOUCH:
67 return "unknown-intf";
71 __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
74 idx_max = ALIGN(idx_max, BITS_PER_LONG);
75 ent_enum->bmap = kcalloc(idx_max / BITS_PER_LONG, sizeof(long),
80 bitmap_zero(ent_enum->bmap, idx_max);
81 ent_enum->idx_max = idx_max;
85 EXPORT_SYMBOL_GPL(__media_entity_enum_init);
87 void media_entity_enum_cleanup(struct media_entity_enum *ent_enum)
89 kfree(ent_enum->bmap);
91 EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
94 * dev_dbg_obj - Prints in debug mode a change on some object
96 * @event_name: Name of the event to report. Could be __func__
97 * @gobj: Pointer to the object
99 * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
100 * won't produce any code.
102 static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj)
104 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
105 switch (media_type(gobj)) {
106 case MEDIA_GRAPH_ENTITY:
107 dev_dbg(gobj->mdev->dev,
108 "%s id %u: entity '%s'\n",
109 event_name, media_id(gobj),
110 gobj_to_entity(gobj)->name);
112 case MEDIA_GRAPH_LINK:
114 struct media_link *link = gobj_to_link(gobj);
116 dev_dbg(gobj->mdev->dev,
117 "%s id %u: %s link id %u ==> id %u\n",
118 event_name, media_id(gobj),
119 media_type(link->gobj0) == MEDIA_GRAPH_PAD ?
120 "data" : "interface",
121 media_id(link->gobj0),
122 media_id(link->gobj1));
125 case MEDIA_GRAPH_PAD:
127 struct media_pad *pad = gobj_to_pad(gobj);
129 dev_dbg(gobj->mdev->dev,
130 "%s id %u: %s%spad '%s':%d\n",
131 event_name, media_id(gobj),
132 pad->flags & MEDIA_PAD_FL_SINK ? "sink " : "",
133 pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
134 pad->entity->name, pad->index);
137 case MEDIA_GRAPH_INTF_DEVNODE:
139 struct media_interface *intf = gobj_to_intf(gobj);
140 struct media_intf_devnode *devnode = intf_to_devnode(intf);
142 dev_dbg(gobj->mdev->dev,
143 "%s id %u: intf_devnode %s - major: %d, minor: %d\n",
144 event_name, media_id(gobj),
146 devnode->major, devnode->minor);
153 void media_gobj_create(struct media_device *mdev,
154 enum media_gobj_type type,
155 struct media_gobj *gobj)
161 /* Create a per-type unique object ID */
162 gobj->id = media_gobj_gen_id(type, ++mdev->id);
165 case MEDIA_GRAPH_ENTITY:
166 list_add_tail(&gobj->list, &mdev->entities);
168 case MEDIA_GRAPH_PAD:
169 list_add_tail(&gobj->list, &mdev->pads);
171 case MEDIA_GRAPH_LINK:
172 list_add_tail(&gobj->list, &mdev->links);
174 case MEDIA_GRAPH_INTF_DEVNODE:
175 list_add_tail(&gobj->list, &mdev->interfaces);
179 mdev->topology_version++;
181 dev_dbg_obj(__func__, gobj);
184 void media_gobj_destroy(struct media_gobj *gobj)
186 /* Do nothing if the object is not linked. */
187 if (gobj->mdev == NULL)
190 dev_dbg_obj(__func__, gobj);
192 gobj->mdev->topology_version++;
194 /* Remove the object from mdev list */
195 list_del(&gobj->list);
201 * TODO: Get rid of this.
203 #define MEDIA_ENTITY_MAX_PADS 512
205 int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
206 struct media_pad *pads)
208 struct media_device *mdev = entity->graph_obj.mdev;
211 if (num_pads >= MEDIA_ENTITY_MAX_PADS)
214 entity->num_pads = num_pads;
218 mutex_lock(&mdev->graph_mutex);
220 for (i = 0; i < num_pads; i++) {
221 pads[i].entity = entity;
224 media_gobj_create(mdev, MEDIA_GRAPH_PAD,
225 &entity->pads[i].graph_obj);
229 mutex_unlock(&mdev->graph_mutex);
233 EXPORT_SYMBOL_GPL(media_entity_pads_init);
235 /* -----------------------------------------------------------------------------
239 static struct media_entity *
240 media_entity_other(struct media_entity *entity, struct media_link *link)
242 if (link->source->entity == entity)
243 return link->sink->entity;
245 return link->source->entity;
248 /* push an entity to traversal stack */
249 static void stack_push(struct media_graph *graph,
250 struct media_entity *entity)
252 if (graph->top == MEDIA_ENTITY_ENUM_MAX_DEPTH - 1) {
257 graph->stack[graph->top].link = entity->links.next;
258 graph->stack[graph->top].entity = entity;
261 static struct media_entity *stack_pop(struct media_graph *graph)
263 struct media_entity *entity;
265 entity = graph->stack[graph->top].entity;
271 #define link_top(en) ((en)->stack[(en)->top].link)
272 #define stack_top(en) ((en)->stack[(en)->top].entity)
275 * media_graph_walk_init - Allocate resources for graph walk
276 * @graph: Media graph structure that will be used to walk the graph
277 * @mdev: Media device
279 * Reserve resources for graph walk in media device's current
280 * state. The memory must be released using
281 * media_graph_walk_free().
283 * Returns error on failure, zero on success.
285 __must_check int media_graph_walk_init(
286 struct media_graph *graph, struct media_device *mdev)
288 return media_entity_enum_init(&graph->ent_enum, mdev);
290 EXPORT_SYMBOL_GPL(media_graph_walk_init);
293 * media_graph_walk_cleanup - Release resources related to graph walking
294 * @graph: Media graph structure that was used to walk the graph
296 void media_graph_walk_cleanup(struct media_graph *graph)
298 media_entity_enum_cleanup(&graph->ent_enum);
300 EXPORT_SYMBOL_GPL(media_graph_walk_cleanup);
302 void media_graph_walk_start(struct media_graph *graph,
303 struct media_entity *entity)
305 media_entity_enum_zero(&graph->ent_enum);
306 media_entity_enum_set(&graph->ent_enum, entity);
309 graph->stack[graph->top].entity = NULL;
310 stack_push(graph, entity);
311 dev_dbg(entity->graph_obj.mdev->dev,
312 "begin graph walk at '%s'\n", entity->name);
314 EXPORT_SYMBOL_GPL(media_graph_walk_start);
316 static void media_graph_walk_iter(struct media_graph *graph)
318 struct media_entity *entity = stack_top(graph);
319 struct media_link *link;
320 struct media_entity *next;
322 link = list_entry(link_top(graph), typeof(*link), list);
324 /* The link is not enabled so we do not follow. */
325 if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
326 link_top(graph) = link_top(graph)->next;
327 dev_dbg(entity->graph_obj.mdev->dev,
328 "walk: skipping disabled link '%s':%u -> '%s':%u\n",
329 link->source->entity->name, link->source->index,
330 link->sink->entity->name, link->sink->index);
334 /* Get the entity in the other end of the link . */
335 next = media_entity_other(entity, link);
337 /* Has the entity already been visited? */
338 if (media_entity_enum_test_and_set(&graph->ent_enum, next)) {
339 link_top(graph) = link_top(graph)->next;
340 dev_dbg(entity->graph_obj.mdev->dev,
341 "walk: skipping entity '%s' (already seen)\n",
346 /* Push the new entity to stack and start over. */
347 link_top(graph) = link_top(graph)->next;
348 stack_push(graph, next);
349 dev_dbg(entity->graph_obj.mdev->dev, "walk: pushing '%s' on stack\n",
353 struct media_entity *media_graph_walk_next(struct media_graph *graph)
355 struct media_entity *entity;
357 if (stack_top(graph) == NULL)
361 * Depth first search. Push entity to stack and continue from
362 * top of the stack until no more entities on the level can be
365 while (link_top(graph) != &stack_top(graph)->links)
366 media_graph_walk_iter(graph);
368 entity = stack_pop(graph);
369 dev_dbg(entity->graph_obj.mdev->dev,
370 "walk: returning entity '%s'\n", entity->name);
374 EXPORT_SYMBOL_GPL(media_graph_walk_next);
376 int media_entity_get_fwnode_pad(struct media_entity *entity,
377 struct fwnode_handle *fwnode,
378 unsigned long direction_flags)
380 struct fwnode_endpoint endpoint;
384 if (!entity->ops || !entity->ops->get_fwnode_pad) {
385 for (i = 0; i < entity->num_pads; i++) {
386 if (entity->pads[i].flags & direction_flags)
393 ret = fwnode_graph_parse_endpoint(fwnode, &endpoint);
397 ret = entity->ops->get_fwnode_pad(&endpoint);
401 if (ret >= entity->num_pads)
404 if (!(entity->pads[ret].flags & direction_flags))
409 EXPORT_SYMBOL_GPL(media_entity_get_fwnode_pad);
411 /* -----------------------------------------------------------------------------
412 * Pipeline management
415 __must_check int __media_pipeline_start(struct media_entity *entity,
416 struct media_pipeline *pipe)
418 struct media_device *mdev = entity->graph_obj.mdev;
419 struct media_graph *graph = &pipe->graph;
420 struct media_entity *entity_err = entity;
421 struct media_link *link;
424 if (!pipe->streaming_count++) {
425 ret = media_graph_walk_init(&pipe->graph, mdev);
427 goto error_graph_walk_start;
430 media_graph_walk_start(&pipe->graph, entity);
432 while ((entity = media_graph_walk_next(graph))) {
433 DECLARE_BITMAP(active, MEDIA_ENTITY_MAX_PADS);
434 DECLARE_BITMAP(has_no_links, MEDIA_ENTITY_MAX_PADS);
436 entity->stream_count++;
438 if (entity->pipe && entity->pipe != pipe) {
439 pr_err("Pipe active for %s. Can't start for %s\n",
448 /* Already streaming --- no need to check. */
449 if (entity->stream_count > 1)
452 if (!entity->ops || !entity->ops->link_validate)
455 bitmap_zero(active, entity->num_pads);
456 bitmap_fill(has_no_links, entity->num_pads);
458 list_for_each_entry(link, &entity->links, list) {
459 struct media_pad *pad = link->sink->entity == entity
460 ? link->sink : link->source;
462 /* Mark that a pad is connected by a link. */
463 bitmap_clear(has_no_links, pad->index, 1);
466 * Pads that either do not need to connect or
467 * are connected through an enabled link are
470 if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
471 link->flags & MEDIA_LNK_FL_ENABLED)
472 bitmap_set(active, pad->index, 1);
475 * Link validation will only take place for
476 * sink ends of the link that are enabled.
478 if (link->sink != pad ||
479 !(link->flags & MEDIA_LNK_FL_ENABLED))
482 ret = entity->ops->link_validate(link);
483 if (ret < 0 && ret != -ENOIOCTLCMD) {
484 dev_dbg(entity->graph_obj.mdev->dev,
485 "link validation failed for '%s':%u -> '%s':%u, error %d\n",
486 link->source->entity->name,
488 entity->name, link->sink->index, ret);
493 /* Either no links or validated links are fine. */
494 bitmap_or(active, active, has_no_links, entity->num_pads);
496 if (!bitmap_full(active, entity->num_pads)) {
498 dev_dbg(entity->graph_obj.mdev->dev,
499 "'%s':%u must be connected by an enabled link\n",
501 (unsigned)find_first_zero_bit(
502 active, entity->num_pads));
511 * Link validation on graph failed. We revert what we did and
514 media_graph_walk_start(graph, entity_err);
516 while ((entity_err = media_graph_walk_next(graph))) {
517 /* Sanity check for negative stream_count */
518 if (!WARN_ON_ONCE(entity_err->stream_count <= 0)) {
519 entity_err->stream_count--;
520 if (entity_err->stream_count == 0)
521 entity_err->pipe = NULL;
525 * We haven't increased stream_count further than this
528 if (entity_err == entity)
532 error_graph_walk_start:
533 if (!--pipe->streaming_count)
534 media_graph_walk_cleanup(graph);
538 EXPORT_SYMBOL_GPL(__media_pipeline_start);
540 __must_check int media_pipeline_start(struct media_entity *entity,
541 struct media_pipeline *pipe)
543 struct media_device *mdev = entity->graph_obj.mdev;
546 mutex_lock(&mdev->graph_mutex);
547 ret = __media_pipeline_start(entity, pipe);
548 mutex_unlock(&mdev->graph_mutex);
551 EXPORT_SYMBOL_GPL(media_pipeline_start);
553 void __media_pipeline_stop(struct media_entity *entity)
555 struct media_graph *graph = &entity->pipe->graph;
556 struct media_pipeline *pipe = entity->pipe;
559 * If the following check fails, the driver has performed an
560 * unbalanced call to media_pipeline_stop()
565 media_graph_walk_start(graph, entity);
567 while ((entity = media_graph_walk_next(graph))) {
568 /* Sanity check for negative stream_count */
569 if (!WARN_ON_ONCE(entity->stream_count <= 0)) {
570 entity->stream_count--;
571 if (entity->stream_count == 0)
576 if (!--pipe->streaming_count)
577 media_graph_walk_cleanup(graph);
580 EXPORT_SYMBOL_GPL(__media_pipeline_stop);
582 void media_pipeline_stop(struct media_entity *entity)
584 struct media_device *mdev = entity->graph_obj.mdev;
586 mutex_lock(&mdev->graph_mutex);
587 __media_pipeline_stop(entity);
588 mutex_unlock(&mdev->graph_mutex);
590 EXPORT_SYMBOL_GPL(media_pipeline_stop);
592 /* -----------------------------------------------------------------------------
596 static struct media_link *media_add_link(struct list_head *head)
598 struct media_link *link;
600 link = kzalloc(sizeof(*link), GFP_KERNEL);
604 list_add_tail(&link->list, head);
609 static void __media_entity_remove_link(struct media_entity *entity,
610 struct media_link *link)
612 struct media_link *rlink, *tmp;
613 struct media_entity *remote;
615 if (link->source->entity == entity)
616 remote = link->sink->entity;
618 remote = link->source->entity;
620 list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
621 if (rlink != link->reverse)
624 if (link->source->entity == entity)
625 remote->num_backlinks--;
627 /* Remove the remote link */
628 list_del(&rlink->list);
629 media_gobj_destroy(&rlink->graph_obj);
632 if (--remote->num_links == 0)
635 list_del(&link->list);
636 media_gobj_destroy(&link->graph_obj);
640 int media_get_pad_index(struct media_entity *entity, bool is_sink,
641 enum media_pad_signal_type sig_type)
649 for (i = 0; i < entity->num_pads; i++) {
650 if (entity->pads[i].flags == MEDIA_PAD_FL_SINK)
652 else if (entity->pads[i].flags == MEDIA_PAD_FL_SOURCE)
655 continue; /* This is an error! */
657 if (pad_is_sink != is_sink)
659 if (entity->pads[i].sig_type == sig_type)
664 EXPORT_SYMBOL_GPL(media_get_pad_index);
667 media_create_pad_link(struct media_entity *source, u16 source_pad,
668 struct media_entity *sink, u16 sink_pad, u32 flags)
670 struct media_link *link;
671 struct media_link *backlink;
673 BUG_ON(source == NULL || sink == NULL);
674 BUG_ON(source_pad >= source->num_pads);
675 BUG_ON(sink_pad >= sink->num_pads);
677 link = media_add_link(&source->links);
681 link->source = &source->pads[source_pad];
682 link->sink = &sink->pads[sink_pad];
683 link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK;
685 /* Initialize graph object embedded at the new link */
686 media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
689 /* Create the backlink. Backlinks are used to help graph traversal and
690 * are not reported to userspace.
692 backlink = media_add_link(&sink->links);
693 if (backlink == NULL) {
694 __media_entity_remove_link(source, link);
698 backlink->source = &source->pads[source_pad];
699 backlink->sink = &sink->pads[sink_pad];
700 backlink->flags = flags;
701 backlink->is_backlink = true;
703 /* Initialize graph object embedded at the new link */
704 media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
705 &backlink->graph_obj);
707 link->reverse = backlink;
708 backlink->reverse = link;
710 sink->num_backlinks++;
716 EXPORT_SYMBOL_GPL(media_create_pad_link);
718 int media_create_pad_links(const struct media_device *mdev,
719 const u32 source_function,
720 struct media_entity *source,
721 const u16 source_pad,
722 const u32 sink_function,
723 struct media_entity *sink,
726 const bool allow_both_undefined)
728 struct media_entity *entity;
732 /* Trivial case: 1:1 relation */
734 return media_create_pad_link(source, source_pad,
735 sink, sink_pad, flags);
737 /* Worse case scenario: n:n relation */
738 if (!source && !sink) {
739 if (!allow_both_undefined)
741 media_device_for_each_entity(source, mdev) {
742 if (source->function != source_function)
744 media_device_for_each_entity(sink, mdev) {
745 if (sink->function != sink_function)
747 ret = media_create_pad_link(source, source_pad,
752 flags &= ~(MEDIA_LNK_FL_ENABLED |
753 MEDIA_LNK_FL_IMMUTABLE);
759 /* Handle 1:n and n:1 cases */
761 function = sink_function;
763 function = source_function;
765 media_device_for_each_entity(entity, mdev) {
766 if (entity->function != function)
770 ret = media_create_pad_link(source, source_pad,
771 entity, sink_pad, flags);
773 ret = media_create_pad_link(entity, source_pad,
774 sink, sink_pad, flags);
777 flags &= ~(MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
781 EXPORT_SYMBOL_GPL(media_create_pad_links);
783 void __media_entity_remove_links(struct media_entity *entity)
785 struct media_link *link, *tmp;
787 list_for_each_entry_safe(link, tmp, &entity->links, list)
788 __media_entity_remove_link(entity, link);
790 entity->num_links = 0;
791 entity->num_backlinks = 0;
793 EXPORT_SYMBOL_GPL(__media_entity_remove_links);
795 void media_entity_remove_links(struct media_entity *entity)
797 struct media_device *mdev = entity->graph_obj.mdev;
799 /* Do nothing if the entity is not registered. */
803 mutex_lock(&mdev->graph_mutex);
804 __media_entity_remove_links(entity);
805 mutex_unlock(&mdev->graph_mutex);
807 EXPORT_SYMBOL_GPL(media_entity_remove_links);
809 static int __media_entity_setup_link_notify(struct media_link *link, u32 flags)
813 /* Notify both entities. */
814 ret = media_entity_call(link->source->entity, link_setup,
815 link->source, link->sink, flags);
816 if (ret < 0 && ret != -ENOIOCTLCMD)
819 ret = media_entity_call(link->sink->entity, link_setup,
820 link->sink, link->source, flags);
821 if (ret < 0 && ret != -ENOIOCTLCMD) {
822 media_entity_call(link->source->entity, link_setup,
823 link->source, link->sink, link->flags);
828 link->reverse->flags = link->flags;
833 int __media_entity_setup_link(struct media_link *link, u32 flags)
835 const u32 mask = MEDIA_LNK_FL_ENABLED;
836 struct media_device *mdev;
837 struct media_entity *source, *sink;
843 /* The non-modifiable link flags must not be modified. */
844 if ((link->flags & ~mask) != (flags & ~mask))
847 if (link->flags & MEDIA_LNK_FL_IMMUTABLE)
848 return link->flags == flags ? 0 : -EINVAL;
850 if (link->flags == flags)
853 source = link->source->entity;
854 sink = link->sink->entity;
856 if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) &&
857 (source->stream_count || sink->stream_count))
860 mdev = source->graph_obj.mdev;
862 if (mdev->ops && mdev->ops->link_notify) {
863 ret = mdev->ops->link_notify(link, flags,
864 MEDIA_DEV_NOTIFY_PRE_LINK_CH);
869 ret = __media_entity_setup_link_notify(link, flags);
871 if (mdev->ops && mdev->ops->link_notify)
872 mdev->ops->link_notify(link, flags,
873 MEDIA_DEV_NOTIFY_POST_LINK_CH);
877 EXPORT_SYMBOL_GPL(__media_entity_setup_link);
879 int media_entity_setup_link(struct media_link *link, u32 flags)
883 mutex_lock(&link->graph_obj.mdev->graph_mutex);
884 ret = __media_entity_setup_link(link, flags);
885 mutex_unlock(&link->graph_obj.mdev->graph_mutex);
889 EXPORT_SYMBOL_GPL(media_entity_setup_link);
892 media_entity_find_link(struct media_pad *source, struct media_pad *sink)
894 struct media_link *link;
896 list_for_each_entry(link, &source->entity->links, list) {
897 if (link->source->entity == source->entity &&
898 link->source->index == source->index &&
899 link->sink->entity == sink->entity &&
900 link->sink->index == sink->index)
906 EXPORT_SYMBOL_GPL(media_entity_find_link);
908 struct media_pad *media_entity_remote_pad(const struct media_pad *pad)
910 struct media_link *link;
912 list_for_each_entry(link, &pad->entity->links, list) {
913 if (!(link->flags & MEDIA_LNK_FL_ENABLED))
916 if (link->source == pad)
919 if (link->sink == pad)
926 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
928 static void media_interface_init(struct media_device *mdev,
929 struct media_interface *intf,
931 u32 intf_type, u32 flags)
933 intf->type = intf_type;
935 INIT_LIST_HEAD(&intf->links);
937 media_gobj_create(mdev, gobj_type, &intf->graph_obj);
940 /* Functions related to the media interface via device nodes */
942 struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
944 u32 major, u32 minor)
946 struct media_intf_devnode *devnode;
948 devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
952 devnode->major = major;
953 devnode->minor = minor;
955 media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
960 EXPORT_SYMBOL_GPL(media_devnode_create);
962 void media_devnode_remove(struct media_intf_devnode *devnode)
964 media_remove_intf_links(&devnode->intf);
965 media_gobj_destroy(&devnode->intf.graph_obj);
968 EXPORT_SYMBOL_GPL(media_devnode_remove);
970 struct media_link *media_create_intf_link(struct media_entity *entity,
971 struct media_interface *intf,
974 struct media_link *link;
976 link = media_add_link(&intf->links);
981 link->entity = entity;
982 link->flags = flags | MEDIA_LNK_FL_INTERFACE_LINK;
984 /* Initialize graph object embedded at the new link */
985 media_gobj_create(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
990 EXPORT_SYMBOL_GPL(media_create_intf_link);
992 void __media_remove_intf_link(struct media_link *link)
994 list_del(&link->list);
995 media_gobj_destroy(&link->graph_obj);
998 EXPORT_SYMBOL_GPL(__media_remove_intf_link);
1000 void media_remove_intf_link(struct media_link *link)
1002 struct media_device *mdev = link->graph_obj.mdev;
1004 /* Do nothing if the intf is not registered. */
1008 mutex_lock(&mdev->graph_mutex);
1009 __media_remove_intf_link(link);
1010 mutex_unlock(&mdev->graph_mutex);
1012 EXPORT_SYMBOL_GPL(media_remove_intf_link);
1014 void __media_remove_intf_links(struct media_interface *intf)
1016 struct media_link *link, *tmp;
1018 list_for_each_entry_safe(link, tmp, &intf->links, list)
1019 __media_remove_intf_link(link);
1022 EXPORT_SYMBOL_GPL(__media_remove_intf_links);
1024 void media_remove_intf_links(struct media_interface *intf)
1026 struct media_device *mdev = intf->graph_obj.mdev;
1028 /* Do nothing if the intf is not registered. */
1032 mutex_lock(&mdev->graph_mutex);
1033 __media_remove_intf_links(intf);
1034 mutex_unlock(&mdev->graph_mutex);
1036 EXPORT_SYMBOL_GPL(media_remove_intf_links);