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 static inline const char *link_type_name(struct media_link *link)
65 switch (link->flags & MEDIA_LNK_FL_LINK_TYPE) {
66 case MEDIA_LNK_FL_DATA_LINK:
68 case MEDIA_LNK_FL_INTERFACE_LINK:
70 case MEDIA_LNK_FL_ANCILLARY_LINK:
77 __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
80 idx_max = ALIGN(idx_max, BITS_PER_LONG);
81 ent_enum->bmap = kcalloc(idx_max / BITS_PER_LONG, sizeof(long),
86 bitmap_zero(ent_enum->bmap, idx_max);
87 ent_enum->idx_max = idx_max;
91 EXPORT_SYMBOL_GPL(__media_entity_enum_init);
93 void media_entity_enum_cleanup(struct media_entity_enum *ent_enum)
95 kfree(ent_enum->bmap);
97 EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
100 * dev_dbg_obj - Prints in debug mode a change on some object
102 * @event_name: Name of the event to report. Could be __func__
103 * @gobj: Pointer to the object
105 * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
106 * won't produce any code.
108 static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj)
110 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
111 switch (media_type(gobj)) {
112 case MEDIA_GRAPH_ENTITY:
113 dev_dbg(gobj->mdev->dev,
114 "%s id %u: entity '%s'\n",
115 event_name, media_id(gobj),
116 gobj_to_entity(gobj)->name);
118 case MEDIA_GRAPH_LINK:
120 struct media_link *link = gobj_to_link(gobj);
122 dev_dbg(gobj->mdev->dev,
123 "%s id %u: %s link id %u ==> id %u\n",
124 event_name, media_id(gobj), link_type_name(link),
125 media_id(link->gobj0),
126 media_id(link->gobj1));
129 case MEDIA_GRAPH_PAD:
131 struct media_pad *pad = gobj_to_pad(gobj);
133 dev_dbg(gobj->mdev->dev,
134 "%s id %u: %s%spad '%s':%d\n",
135 event_name, media_id(gobj),
136 pad->flags & MEDIA_PAD_FL_SINK ? "sink " : "",
137 pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
138 pad->entity->name, pad->index);
141 case MEDIA_GRAPH_INTF_DEVNODE:
143 struct media_interface *intf = gobj_to_intf(gobj);
144 struct media_intf_devnode *devnode = intf_to_devnode(intf);
146 dev_dbg(gobj->mdev->dev,
147 "%s id %u: intf_devnode %s - major: %d, minor: %d\n",
148 event_name, media_id(gobj),
150 devnode->major, devnode->minor);
157 void media_gobj_create(struct media_device *mdev,
158 enum media_gobj_type type,
159 struct media_gobj *gobj)
165 /* Create a per-type unique object ID */
166 gobj->id = media_gobj_gen_id(type, ++mdev->id);
169 case MEDIA_GRAPH_ENTITY:
170 list_add_tail(&gobj->list, &mdev->entities);
172 case MEDIA_GRAPH_PAD:
173 list_add_tail(&gobj->list, &mdev->pads);
175 case MEDIA_GRAPH_LINK:
176 list_add_tail(&gobj->list, &mdev->links);
178 case MEDIA_GRAPH_INTF_DEVNODE:
179 list_add_tail(&gobj->list, &mdev->interfaces);
183 mdev->topology_version++;
185 dev_dbg_obj(__func__, gobj);
188 void media_gobj_destroy(struct media_gobj *gobj)
190 /* Do nothing if the object is not linked. */
191 if (gobj->mdev == NULL)
194 dev_dbg_obj(__func__, gobj);
196 gobj->mdev->topology_version++;
198 /* Remove the object from mdev list */
199 list_del(&gobj->list);
205 * TODO: Get rid of this.
207 #define MEDIA_ENTITY_MAX_PADS 512
209 int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
210 struct media_pad *pads)
212 struct media_device *mdev = entity->graph_obj.mdev;
215 if (num_pads >= MEDIA_ENTITY_MAX_PADS)
218 entity->num_pads = num_pads;
222 mutex_lock(&mdev->graph_mutex);
224 for (i = 0; i < num_pads; i++) {
225 pads[i].entity = entity;
228 media_gobj_create(mdev, MEDIA_GRAPH_PAD,
229 &entity->pads[i].graph_obj);
233 mutex_unlock(&mdev->graph_mutex);
237 EXPORT_SYMBOL_GPL(media_entity_pads_init);
239 /* -----------------------------------------------------------------------------
243 static struct media_entity *
244 media_entity_other(struct media_entity *entity, struct media_link *link)
246 if (link->source->entity == entity)
247 return link->sink->entity;
249 return link->source->entity;
252 /* push an entity to traversal stack */
253 static void stack_push(struct media_graph *graph,
254 struct media_entity *entity)
256 if (graph->top == MEDIA_ENTITY_ENUM_MAX_DEPTH - 1) {
261 graph->stack[graph->top].link = entity->links.next;
262 graph->stack[graph->top].entity = entity;
265 static struct media_entity *stack_pop(struct media_graph *graph)
267 struct media_entity *entity;
269 entity = graph->stack[graph->top].entity;
275 #define link_top(en) ((en)->stack[(en)->top].link)
276 #define stack_top(en) ((en)->stack[(en)->top].entity)
279 * media_graph_walk_init - Allocate resources for graph walk
280 * @graph: Media graph structure that will be used to walk the graph
281 * @mdev: Media device
283 * Reserve resources for graph walk in media device's current
284 * state. The memory must be released using
285 * media_graph_walk_free().
287 * Returns error on failure, zero on success.
289 __must_check int media_graph_walk_init(
290 struct media_graph *graph, struct media_device *mdev)
292 return media_entity_enum_init(&graph->ent_enum, mdev);
294 EXPORT_SYMBOL_GPL(media_graph_walk_init);
297 * media_graph_walk_cleanup - Release resources related to graph walking
298 * @graph: Media graph structure that was used to walk the graph
300 void media_graph_walk_cleanup(struct media_graph *graph)
302 media_entity_enum_cleanup(&graph->ent_enum);
304 EXPORT_SYMBOL_GPL(media_graph_walk_cleanup);
306 void media_graph_walk_start(struct media_graph *graph,
307 struct media_entity *entity)
309 media_entity_enum_zero(&graph->ent_enum);
310 media_entity_enum_set(&graph->ent_enum, entity);
313 graph->stack[graph->top].entity = NULL;
314 stack_push(graph, entity);
315 dev_dbg(entity->graph_obj.mdev->dev,
316 "begin graph walk at '%s'\n", entity->name);
318 EXPORT_SYMBOL_GPL(media_graph_walk_start);
320 static void media_graph_walk_iter(struct media_graph *graph)
322 struct media_entity *entity = stack_top(graph);
323 struct media_link *link;
324 struct media_entity *next;
326 link = list_entry(link_top(graph), typeof(*link), list);
328 /* If the link is not a data link, don't follow it */
329 if ((link->flags & MEDIA_LNK_FL_LINK_TYPE) != MEDIA_LNK_FL_DATA_LINK) {
330 link_top(graph) = link_top(graph)->next;
334 /* The link is not enabled so we do not follow. */
335 if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
336 link_top(graph) = link_top(graph)->next;
337 dev_dbg(entity->graph_obj.mdev->dev,
338 "walk: skipping disabled link '%s':%u -> '%s':%u\n",
339 link->source->entity->name, link->source->index,
340 link->sink->entity->name, link->sink->index);
344 /* Get the entity at the other end of the link. */
345 next = media_entity_other(entity, link);
347 /* Has the entity already been visited? */
348 if (media_entity_enum_test_and_set(&graph->ent_enum, next)) {
349 link_top(graph) = link_top(graph)->next;
350 dev_dbg(entity->graph_obj.mdev->dev,
351 "walk: skipping entity '%s' (already seen)\n",
356 /* Push the new entity to stack and start over. */
357 link_top(graph) = link_top(graph)->next;
358 stack_push(graph, next);
359 dev_dbg(entity->graph_obj.mdev->dev, "walk: pushing '%s' on stack\n",
361 lockdep_assert_held(&entity->graph_obj.mdev->graph_mutex);
364 struct media_entity *media_graph_walk_next(struct media_graph *graph)
366 struct media_entity *entity;
368 if (stack_top(graph) == NULL)
372 * Depth first search. Push entity to stack and continue from
373 * top of the stack until no more entities on the level can be
376 while (link_top(graph) != &stack_top(graph)->links)
377 media_graph_walk_iter(graph);
379 entity = stack_pop(graph);
380 dev_dbg(entity->graph_obj.mdev->dev,
381 "walk: returning entity '%s'\n", entity->name);
385 EXPORT_SYMBOL_GPL(media_graph_walk_next);
387 int media_entity_get_fwnode_pad(struct media_entity *entity,
388 struct fwnode_handle *fwnode,
389 unsigned long direction_flags)
391 struct fwnode_endpoint endpoint;
395 if (!entity->ops || !entity->ops->get_fwnode_pad) {
396 for (i = 0; i < entity->num_pads; i++) {
397 if (entity->pads[i].flags & direction_flags)
404 ret = fwnode_graph_parse_endpoint(fwnode, &endpoint);
408 ret = entity->ops->get_fwnode_pad(entity, &endpoint);
412 if (ret >= entity->num_pads)
415 if (!(entity->pads[ret].flags & direction_flags))
420 EXPORT_SYMBOL_GPL(media_entity_get_fwnode_pad);
422 /* -----------------------------------------------------------------------------
423 * Pipeline management
426 __must_check int __media_pipeline_start(struct media_entity *entity,
427 struct media_pipeline *pipe)
429 struct media_device *mdev = entity->graph_obj.mdev;
430 struct media_graph *graph = &pipe->graph;
431 struct media_entity *entity_err = entity;
432 struct media_link *link;
435 if (!pipe->streaming_count++) {
436 ret = media_graph_walk_init(&pipe->graph, mdev);
438 goto error_graph_walk_start;
441 media_graph_walk_start(&pipe->graph, entity);
443 while ((entity = media_graph_walk_next(graph))) {
444 DECLARE_BITMAP(active, MEDIA_ENTITY_MAX_PADS);
445 DECLARE_BITMAP(has_no_links, MEDIA_ENTITY_MAX_PADS);
447 entity->stream_count++;
449 if (entity->pipe && entity->pipe != pipe) {
450 pr_err("Pipe active for %s. Can't start for %s\n",
459 /* Already streaming --- no need to check. */
460 if (entity->stream_count > 1)
463 if (!entity->ops || !entity->ops->link_validate)
466 bitmap_zero(active, entity->num_pads);
467 bitmap_fill(has_no_links, entity->num_pads);
469 list_for_each_entry(link, &entity->links, list) {
470 struct media_pad *pad = link->sink->entity == entity
471 ? link->sink : link->source;
473 /* Mark that a pad is connected by a link. */
474 bitmap_clear(has_no_links, pad->index, 1);
477 * Pads that either do not need to connect or
478 * are connected through an enabled link are
481 if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
482 link->flags & MEDIA_LNK_FL_ENABLED)
483 bitmap_set(active, pad->index, 1);
486 * Link validation will only take place for
487 * sink ends of the link that are enabled.
489 if (link->sink != pad ||
490 !(link->flags & MEDIA_LNK_FL_ENABLED))
493 ret = entity->ops->link_validate(link);
494 if (ret < 0 && ret != -ENOIOCTLCMD) {
495 dev_dbg(entity->graph_obj.mdev->dev,
496 "link validation failed for '%s':%u -> '%s':%u, error %d\n",
497 link->source->entity->name,
499 entity->name, link->sink->index, ret);
504 /* Either no links or validated links are fine. */
505 bitmap_or(active, active, has_no_links, entity->num_pads);
507 if (!bitmap_full(active, entity->num_pads)) {
509 dev_dbg(entity->graph_obj.mdev->dev,
510 "'%s':%u must be connected by an enabled link\n",
512 (unsigned)find_first_zero_bit(
513 active, entity->num_pads));
522 * Link validation on graph failed. We revert what we did and
525 media_graph_walk_start(graph, entity_err);
527 while ((entity_err = media_graph_walk_next(graph))) {
528 /* Sanity check for negative stream_count */
529 if (!WARN_ON_ONCE(entity_err->stream_count <= 0)) {
530 entity_err->stream_count--;
531 if (entity_err->stream_count == 0)
532 entity_err->pipe = NULL;
536 * We haven't increased stream_count further than this
539 if (entity_err == entity)
543 error_graph_walk_start:
544 if (!--pipe->streaming_count)
545 media_graph_walk_cleanup(graph);
549 EXPORT_SYMBOL_GPL(__media_pipeline_start);
551 __must_check int media_pipeline_start(struct media_entity *entity,
552 struct media_pipeline *pipe)
554 struct media_device *mdev = entity->graph_obj.mdev;
557 mutex_lock(&mdev->graph_mutex);
558 ret = __media_pipeline_start(entity, pipe);
559 mutex_unlock(&mdev->graph_mutex);
562 EXPORT_SYMBOL_GPL(media_pipeline_start);
564 void __media_pipeline_stop(struct media_entity *entity)
566 struct media_graph *graph = &entity->pipe->graph;
567 struct media_pipeline *pipe = entity->pipe;
570 * If the following check fails, the driver has performed an
571 * unbalanced call to media_pipeline_stop()
576 media_graph_walk_start(graph, entity);
578 while ((entity = media_graph_walk_next(graph))) {
579 /* Sanity check for negative stream_count */
580 if (!WARN_ON_ONCE(entity->stream_count <= 0)) {
581 entity->stream_count--;
582 if (entity->stream_count == 0)
587 if (!--pipe->streaming_count)
588 media_graph_walk_cleanup(graph);
591 EXPORT_SYMBOL_GPL(__media_pipeline_stop);
593 void media_pipeline_stop(struct media_entity *entity)
595 struct media_device *mdev = entity->graph_obj.mdev;
597 mutex_lock(&mdev->graph_mutex);
598 __media_pipeline_stop(entity);
599 mutex_unlock(&mdev->graph_mutex);
601 EXPORT_SYMBOL_GPL(media_pipeline_stop);
603 /* -----------------------------------------------------------------------------
607 static struct media_link *media_add_link(struct list_head *head)
609 struct media_link *link;
611 link = kzalloc(sizeof(*link), GFP_KERNEL);
615 list_add_tail(&link->list, head);
620 static void __media_entity_remove_link(struct media_entity *entity,
621 struct media_link *link)
623 struct media_link *rlink, *tmp;
624 struct media_entity *remote;
626 if (link->source->entity == entity)
627 remote = link->sink->entity;
629 remote = link->source->entity;
631 list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
632 if (rlink != link->reverse)
635 if (link->source->entity == entity)
636 remote->num_backlinks--;
638 /* Remove the remote link */
639 list_del(&rlink->list);
640 media_gobj_destroy(&rlink->graph_obj);
643 if (--remote->num_links == 0)
646 list_del(&link->list);
647 media_gobj_destroy(&link->graph_obj);
651 int media_get_pad_index(struct media_entity *entity, bool is_sink,
652 enum media_pad_signal_type sig_type)
660 for (i = 0; i < entity->num_pads; i++) {
661 if (entity->pads[i].flags & MEDIA_PAD_FL_SINK)
663 else if (entity->pads[i].flags & MEDIA_PAD_FL_SOURCE)
666 continue; /* This is an error! */
668 if (pad_is_sink != is_sink)
670 if (entity->pads[i].sig_type == sig_type)
675 EXPORT_SYMBOL_GPL(media_get_pad_index);
678 media_create_pad_link(struct media_entity *source, u16 source_pad,
679 struct media_entity *sink, u16 sink_pad, u32 flags)
681 struct media_link *link;
682 struct media_link *backlink;
684 if (WARN_ON(!source || !sink) ||
685 WARN_ON(source_pad >= source->num_pads) ||
686 WARN_ON(sink_pad >= sink->num_pads))
688 if (WARN_ON(!(source->pads[source_pad].flags & MEDIA_PAD_FL_SOURCE)))
690 if (WARN_ON(!(sink->pads[sink_pad].flags & MEDIA_PAD_FL_SINK)))
693 link = media_add_link(&source->links);
697 link->source = &source->pads[source_pad];
698 link->sink = &sink->pads[sink_pad];
699 link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK;
701 /* Initialize graph object embedded at the new link */
702 media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
705 /* Create the backlink. Backlinks are used to help graph traversal and
706 * are not reported to userspace.
708 backlink = media_add_link(&sink->links);
709 if (backlink == NULL) {
710 __media_entity_remove_link(source, link);
714 backlink->source = &source->pads[source_pad];
715 backlink->sink = &sink->pads[sink_pad];
716 backlink->flags = flags;
717 backlink->is_backlink = true;
719 /* Initialize graph object embedded at the new link */
720 media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
721 &backlink->graph_obj);
723 link->reverse = backlink;
724 backlink->reverse = link;
726 sink->num_backlinks++;
732 EXPORT_SYMBOL_GPL(media_create_pad_link);
734 int media_create_pad_links(const struct media_device *mdev,
735 const u32 source_function,
736 struct media_entity *source,
737 const u16 source_pad,
738 const u32 sink_function,
739 struct media_entity *sink,
742 const bool allow_both_undefined)
744 struct media_entity *entity;
748 /* Trivial case: 1:1 relation */
750 return media_create_pad_link(source, source_pad,
751 sink, sink_pad, flags);
753 /* Worse case scenario: n:n relation */
754 if (!source && !sink) {
755 if (!allow_both_undefined)
757 media_device_for_each_entity(source, mdev) {
758 if (source->function != source_function)
760 media_device_for_each_entity(sink, mdev) {
761 if (sink->function != sink_function)
763 ret = media_create_pad_link(source, source_pad,
768 flags &= ~(MEDIA_LNK_FL_ENABLED |
769 MEDIA_LNK_FL_IMMUTABLE);
775 /* Handle 1:n and n:1 cases */
777 function = sink_function;
779 function = source_function;
781 media_device_for_each_entity(entity, mdev) {
782 if (entity->function != function)
786 ret = media_create_pad_link(source, source_pad,
787 entity, sink_pad, flags);
789 ret = media_create_pad_link(entity, source_pad,
790 sink, sink_pad, flags);
793 flags &= ~(MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
797 EXPORT_SYMBOL_GPL(media_create_pad_links);
799 void __media_entity_remove_links(struct media_entity *entity)
801 struct media_link *link, *tmp;
803 list_for_each_entry_safe(link, tmp, &entity->links, list)
804 __media_entity_remove_link(entity, link);
806 entity->num_links = 0;
807 entity->num_backlinks = 0;
809 EXPORT_SYMBOL_GPL(__media_entity_remove_links);
811 void media_entity_remove_links(struct media_entity *entity)
813 struct media_device *mdev = entity->graph_obj.mdev;
815 /* Do nothing if the entity is not registered. */
819 mutex_lock(&mdev->graph_mutex);
820 __media_entity_remove_links(entity);
821 mutex_unlock(&mdev->graph_mutex);
823 EXPORT_SYMBOL_GPL(media_entity_remove_links);
825 static int __media_entity_setup_link_notify(struct media_link *link, u32 flags)
829 /* Notify both entities. */
830 ret = media_entity_call(link->source->entity, link_setup,
831 link->source, link->sink, flags);
832 if (ret < 0 && ret != -ENOIOCTLCMD)
835 ret = media_entity_call(link->sink->entity, link_setup,
836 link->sink, link->source, flags);
837 if (ret < 0 && ret != -ENOIOCTLCMD) {
838 media_entity_call(link->source->entity, link_setup,
839 link->source, link->sink, link->flags);
844 link->reverse->flags = link->flags;
849 int __media_entity_setup_link(struct media_link *link, u32 flags)
851 const u32 mask = MEDIA_LNK_FL_ENABLED;
852 struct media_device *mdev;
853 struct media_entity *source, *sink;
859 /* The non-modifiable link flags must not be modified. */
860 if ((link->flags & ~mask) != (flags & ~mask))
863 if (link->flags & MEDIA_LNK_FL_IMMUTABLE)
864 return link->flags == flags ? 0 : -EINVAL;
866 if (link->flags == flags)
869 source = link->source->entity;
870 sink = link->sink->entity;
872 if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) &&
873 (source->stream_count || sink->stream_count))
876 mdev = source->graph_obj.mdev;
878 if (mdev->ops && mdev->ops->link_notify) {
879 ret = mdev->ops->link_notify(link, flags,
880 MEDIA_DEV_NOTIFY_PRE_LINK_CH);
885 ret = __media_entity_setup_link_notify(link, flags);
887 if (mdev->ops && mdev->ops->link_notify)
888 mdev->ops->link_notify(link, flags,
889 MEDIA_DEV_NOTIFY_POST_LINK_CH);
893 EXPORT_SYMBOL_GPL(__media_entity_setup_link);
895 int media_entity_setup_link(struct media_link *link, u32 flags)
899 mutex_lock(&link->graph_obj.mdev->graph_mutex);
900 ret = __media_entity_setup_link(link, flags);
901 mutex_unlock(&link->graph_obj.mdev->graph_mutex);
905 EXPORT_SYMBOL_GPL(media_entity_setup_link);
908 media_entity_find_link(struct media_pad *source, struct media_pad *sink)
910 struct media_link *link;
912 list_for_each_entry(link, &source->entity->links, list) {
913 if (link->source->entity == source->entity &&
914 link->source->index == source->index &&
915 link->sink->entity == sink->entity &&
916 link->sink->index == sink->index)
922 EXPORT_SYMBOL_GPL(media_entity_find_link);
924 struct media_pad *media_entity_remote_pad(const struct media_pad *pad)
926 struct media_link *link;
928 list_for_each_entry(link, &pad->entity->links, list) {
929 if (!(link->flags & MEDIA_LNK_FL_ENABLED))
932 if (link->source == pad)
935 if (link->sink == pad)
942 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
944 static void media_interface_init(struct media_device *mdev,
945 struct media_interface *intf,
947 u32 intf_type, u32 flags)
949 intf->type = intf_type;
951 INIT_LIST_HEAD(&intf->links);
953 media_gobj_create(mdev, gobj_type, &intf->graph_obj);
956 /* Functions related to the media interface via device nodes */
958 struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
960 u32 major, u32 minor)
962 struct media_intf_devnode *devnode;
964 devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
968 devnode->major = major;
969 devnode->minor = minor;
971 media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
976 EXPORT_SYMBOL_GPL(media_devnode_create);
978 void media_devnode_remove(struct media_intf_devnode *devnode)
980 media_remove_intf_links(&devnode->intf);
981 media_gobj_destroy(&devnode->intf.graph_obj);
984 EXPORT_SYMBOL_GPL(media_devnode_remove);
986 struct media_link *media_create_intf_link(struct media_entity *entity,
987 struct media_interface *intf,
990 struct media_link *link;
992 link = media_add_link(&intf->links);
997 link->entity = entity;
998 link->flags = flags | MEDIA_LNK_FL_INTERFACE_LINK;
1000 /* Initialize graph object embedded at the new link */
1001 media_gobj_create(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
1006 EXPORT_SYMBOL_GPL(media_create_intf_link);
1008 void __media_remove_intf_link(struct media_link *link)
1010 list_del(&link->list);
1011 media_gobj_destroy(&link->graph_obj);
1014 EXPORT_SYMBOL_GPL(__media_remove_intf_link);
1016 void media_remove_intf_link(struct media_link *link)
1018 struct media_device *mdev = link->graph_obj.mdev;
1020 /* Do nothing if the intf is not registered. */
1024 mutex_lock(&mdev->graph_mutex);
1025 __media_remove_intf_link(link);
1026 mutex_unlock(&mdev->graph_mutex);
1028 EXPORT_SYMBOL_GPL(media_remove_intf_link);
1030 void __media_remove_intf_links(struct media_interface *intf)
1032 struct media_link *link, *tmp;
1034 list_for_each_entry_safe(link, tmp, &intf->links, list)
1035 __media_remove_intf_link(link);
1038 EXPORT_SYMBOL_GPL(__media_remove_intf_links);
1040 void media_remove_intf_links(struct media_interface *intf)
1042 struct media_device *mdev = intf->graph_obj.mdev;
1044 /* Do nothing if the intf is not registered. */
1048 mutex_lock(&mdev->graph_mutex);
1049 __media_remove_intf_links(intf);
1050 mutex_unlock(&mdev->graph_mutex);
1052 EXPORT_SYMBOL_GPL(media_remove_intf_links);
1054 struct media_link *media_create_ancillary_link(struct media_entity *primary,
1055 struct media_entity *ancillary)
1057 struct media_link *link;
1059 link = media_add_link(&primary->links);
1061 return ERR_PTR(-ENOMEM);
1063 link->gobj0 = &primary->graph_obj;
1064 link->gobj1 = &ancillary->graph_obj;
1065 link->flags = MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED |
1066 MEDIA_LNK_FL_ANCILLARY_LINK;
1068 /* Initialize graph object embedded in the new link */
1069 media_gobj_create(primary->graph_obj.mdev, MEDIA_GRAPH_LINK,
1074 EXPORT_SYMBOL_GPL(media_create_ancillary_link);