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/module.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
:
66 case MEDIA_INTF_T_ALSA_PCM_CAPTURE
:
67 return "alsa-pcm-capture";
68 case MEDIA_INTF_T_ALSA_PCM_PLAYBACK
:
69 return "alsa-pcm-playback";
70 case MEDIA_INTF_T_ALSA_CONTROL
:
71 return "alsa-control";
72 case MEDIA_INTF_T_ALSA_COMPRESS
:
73 return "alsa-compress";
74 case MEDIA_INTF_T_ALSA_RAWMIDI
:
75 return "alsa-rawmidi";
76 case MEDIA_INTF_T_ALSA_HWDEP
:
78 case MEDIA_INTF_T_ALSA_SEQUENCER
:
79 return "alsa-sequencer";
80 case MEDIA_INTF_T_ALSA_TIMER
:
83 return "unknown-intf";
87 __must_check
int __media_entity_enum_init(struct media_entity_enum
*ent_enum
,
90 idx_max
= ALIGN(idx_max
, BITS_PER_LONG
);
91 ent_enum
->bmap
= kcalloc(idx_max
/ BITS_PER_LONG
, sizeof(long),
96 bitmap_zero(ent_enum
->bmap
, idx_max
);
97 ent_enum
->idx_max
= idx_max
;
101 EXPORT_SYMBOL_GPL(__media_entity_enum_init
);
103 void media_entity_enum_cleanup(struct media_entity_enum
*ent_enum
)
105 kfree(ent_enum
->bmap
);
107 EXPORT_SYMBOL_GPL(media_entity_enum_cleanup
);
110 * dev_dbg_obj - Prints in debug mode a change on some object
112 * @event_name: Name of the event to report. Could be __func__
113 * @gobj: Pointer to the object
115 * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
116 * won't produce any code.
118 static void dev_dbg_obj(const char *event_name
, struct media_gobj
*gobj
)
120 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
121 switch (media_type(gobj
)) {
122 case MEDIA_GRAPH_ENTITY
:
123 dev_dbg(gobj
->mdev
->dev
,
124 "%s id %u: entity '%s'\n",
125 event_name
, media_id(gobj
),
126 gobj_to_entity(gobj
)->name
);
128 case MEDIA_GRAPH_LINK
:
130 struct media_link
*link
= gobj_to_link(gobj
);
132 dev_dbg(gobj
->mdev
->dev
,
133 "%s id %u: %s link id %u ==> id %u\n",
134 event_name
, media_id(gobj
),
135 media_type(link
->gobj0
) == MEDIA_GRAPH_PAD
?
136 "data" : "interface",
137 media_id(link
->gobj0
),
138 media_id(link
->gobj1
));
141 case MEDIA_GRAPH_PAD
:
143 struct media_pad
*pad
= gobj_to_pad(gobj
);
145 dev_dbg(gobj
->mdev
->dev
,
146 "%s id %u: %s%spad '%s':%d\n",
147 event_name
, media_id(gobj
),
148 pad
->flags
& MEDIA_PAD_FL_SINK
? "sink " : "",
149 pad
->flags
& MEDIA_PAD_FL_SOURCE
? "source " : "",
150 pad
->entity
->name
, pad
->index
);
153 case MEDIA_GRAPH_INTF_DEVNODE
:
155 struct media_interface
*intf
= gobj_to_intf(gobj
);
156 struct media_intf_devnode
*devnode
= intf_to_devnode(intf
);
158 dev_dbg(gobj
->mdev
->dev
,
159 "%s id %u: intf_devnode %s - major: %d, minor: %d\n",
160 event_name
, media_id(gobj
),
162 devnode
->major
, devnode
->minor
);
169 void media_gobj_create(struct media_device
*mdev
,
170 enum media_gobj_type type
,
171 struct media_gobj
*gobj
)
177 /* Create a per-type unique object ID */
178 gobj
->id
= media_gobj_gen_id(type
, ++mdev
->id
);
181 case MEDIA_GRAPH_ENTITY
:
182 list_add_tail(&gobj
->list
, &mdev
->entities
);
184 case MEDIA_GRAPH_PAD
:
185 list_add_tail(&gobj
->list
, &mdev
->pads
);
187 case MEDIA_GRAPH_LINK
:
188 list_add_tail(&gobj
->list
, &mdev
->links
);
190 case MEDIA_GRAPH_INTF_DEVNODE
:
191 list_add_tail(&gobj
->list
, &mdev
->interfaces
);
195 mdev
->topology_version
++;
197 dev_dbg_obj(__func__
, gobj
);
200 void media_gobj_destroy(struct media_gobj
*gobj
)
202 dev_dbg_obj(__func__
, gobj
);
204 /* Do nothing if the object is not linked. */
205 if (gobj
->mdev
== NULL
)
208 gobj
->mdev
->topology_version
++;
210 /* Remove the object from mdev list */
211 list_del(&gobj
->list
);
216 int media_entity_pads_init(struct media_entity
*entity
, u16 num_pads
,
217 struct media_pad
*pads
)
219 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
222 entity
->num_pads
= num_pads
;
226 mutex_lock(&mdev
->graph_mutex
);
228 for (i
= 0; i
< num_pads
; i
++) {
229 pads
[i
].entity
= entity
;
232 media_gobj_create(mdev
, MEDIA_GRAPH_PAD
,
233 &entity
->pads
[i
].graph_obj
);
237 mutex_unlock(&mdev
->graph_mutex
);
241 EXPORT_SYMBOL_GPL(media_entity_pads_init
);
243 /* -----------------------------------------------------------------------------
247 static struct media_entity
*
248 media_entity_other(struct media_entity
*entity
, struct media_link
*link
)
250 if (link
->source
->entity
== entity
)
251 return link
->sink
->entity
;
253 return link
->source
->entity
;
256 /* push an entity to traversal stack */
257 static void stack_push(struct media_graph
*graph
,
258 struct media_entity
*entity
)
260 if (graph
->top
== MEDIA_ENTITY_ENUM_MAX_DEPTH
- 1) {
265 graph
->stack
[graph
->top
].link
= entity
->links
.next
;
266 graph
->stack
[graph
->top
].entity
= entity
;
269 static struct media_entity
*stack_pop(struct media_graph
*graph
)
271 struct media_entity
*entity
;
273 entity
= graph
->stack
[graph
->top
].entity
;
279 #define link_top(en) ((en)->stack[(en)->top].link)
280 #define stack_top(en) ((en)->stack[(en)->top].entity)
283 * TODO: Get rid of this.
285 #define MEDIA_ENTITY_MAX_PADS 512
288 * media_graph_walk_init - Allocate resources for graph walk
289 * @graph: Media graph structure that will be used to walk the graph
290 * @mdev: Media device
292 * Reserve resources for graph walk in media device's current
293 * state. The memory must be released using
294 * media_graph_walk_free().
296 * Returns error on failure, zero on success.
298 __must_check
int media_graph_walk_init(
299 struct media_graph
*graph
, struct media_device
*mdev
)
301 return media_entity_enum_init(&graph
->ent_enum
, mdev
);
303 EXPORT_SYMBOL_GPL(media_graph_walk_init
);
306 * media_graph_walk_cleanup - Release resources related to graph walking
307 * @graph: Media graph structure that was used to walk the graph
309 void media_graph_walk_cleanup(struct media_graph
*graph
)
311 media_entity_enum_cleanup(&graph
->ent_enum
);
313 EXPORT_SYMBOL_GPL(media_graph_walk_cleanup
);
315 void media_graph_walk_start(struct media_graph
*graph
,
316 struct media_entity
*entity
)
318 media_entity_enum_zero(&graph
->ent_enum
);
319 media_entity_enum_set(&graph
->ent_enum
, entity
);
322 graph
->stack
[graph
->top
].entity
= NULL
;
323 stack_push(graph
, entity
);
325 EXPORT_SYMBOL_GPL(media_graph_walk_start
);
327 static void media_graph_walk_iter(struct media_graph
*graph
)
329 struct media_entity
*entity
= stack_top(graph
);
330 struct media_link
*link
;
331 struct media_entity
*next
;
333 link
= list_entry(link_top(graph
), typeof(*link
), list
);
335 /* The link is not enabled so we do not follow. */
336 if (!(link
->flags
& MEDIA_LNK_FL_ENABLED
)) {
337 link_top(graph
) = link_top(graph
)->next
;
341 /* Get the entity in the other end of the link . */
342 next
= media_entity_other(entity
, link
);
344 /* Has the entity already been visited? */
345 if (media_entity_enum_test_and_set(&graph
->ent_enum
, next
)) {
346 link_top(graph
) = link_top(graph
)->next
;
350 /* Push the new entity to stack and start over. */
351 link_top(graph
) = link_top(graph
)->next
;
352 stack_push(graph
, next
);
355 struct media_entity
*media_graph_walk_next(struct media_graph
*graph
)
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 return stack_pop(graph
);
370 EXPORT_SYMBOL_GPL(media_graph_walk_next
);
372 /* -----------------------------------------------------------------------------
373 * Pipeline management
376 __must_check
int __media_pipeline_start(struct media_entity
*entity
,
377 struct media_pipeline
*pipe
)
379 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
380 struct media_graph
*graph
= &pipe
->graph
;
381 struct media_entity
*entity_err
= entity
;
382 struct media_link
*link
;
385 if (!pipe
->streaming_count
++) {
386 ret
= media_graph_walk_init(&pipe
->graph
, mdev
);
388 goto error_graph_walk_start
;
391 media_graph_walk_start(&pipe
->graph
, entity
);
393 while ((entity
= media_graph_walk_next(graph
))) {
394 DECLARE_BITMAP(active
, MEDIA_ENTITY_MAX_PADS
);
395 DECLARE_BITMAP(has_no_links
, MEDIA_ENTITY_MAX_PADS
);
397 entity
->stream_count
++;
399 if (WARN_ON(entity
->pipe
&& entity
->pipe
!= pipe
)) {
406 /* Already streaming --- no need to check. */
407 if (entity
->stream_count
> 1)
410 if (!entity
->ops
|| !entity
->ops
->link_validate
)
413 bitmap_zero(active
, entity
->num_pads
);
414 bitmap_fill(has_no_links
, entity
->num_pads
);
416 list_for_each_entry(link
, &entity
->links
, list
) {
417 struct media_pad
*pad
= link
->sink
->entity
== entity
418 ? link
->sink
: link
->source
;
420 /* Mark that a pad is connected by a link. */
421 bitmap_clear(has_no_links
, pad
->index
, 1);
424 * Pads that either do not need to connect or
425 * are connected through an enabled link are
428 if (!(pad
->flags
& MEDIA_PAD_FL_MUST_CONNECT
) ||
429 link
->flags
& MEDIA_LNK_FL_ENABLED
)
430 bitmap_set(active
, pad
->index
, 1);
433 * Link validation will only take place for
434 * sink ends of the link that are enabled.
436 if (link
->sink
!= pad
||
437 !(link
->flags
& MEDIA_LNK_FL_ENABLED
))
440 ret
= entity
->ops
->link_validate(link
);
441 if (ret
< 0 && ret
!= -ENOIOCTLCMD
) {
442 dev_dbg(entity
->graph_obj
.mdev
->dev
,
443 "link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
444 link
->source
->entity
->name
,
446 entity
->name
, link
->sink
->index
, ret
);
451 /* Either no links or validated links are fine. */
452 bitmap_or(active
, active
, has_no_links
, entity
->num_pads
);
454 if (!bitmap_full(active
, entity
->num_pads
)) {
456 dev_dbg(entity
->graph_obj
.mdev
->dev
,
457 "\"%s\":%u must be connected by an enabled link\n",
459 (unsigned)find_first_zero_bit(
460 active
, entity
->num_pads
));
469 * Link validation on graph failed. We revert what we did and
472 media_graph_walk_start(graph
, entity_err
);
474 while ((entity_err
= media_graph_walk_next(graph
))) {
475 /* Sanity check for negative stream_count */
476 if (!WARN_ON_ONCE(entity_err
->stream_count
<= 0)) {
477 entity_err
->stream_count
--;
478 if (entity_err
->stream_count
== 0)
479 entity_err
->pipe
= NULL
;
483 * We haven't increased stream_count further than this
486 if (entity_err
== entity
)
490 error_graph_walk_start
:
491 if (!--pipe
->streaming_count
)
492 media_graph_walk_cleanup(graph
);
496 EXPORT_SYMBOL_GPL(__media_pipeline_start
);
498 __must_check
int media_pipeline_start(struct media_entity
*entity
,
499 struct media_pipeline
*pipe
)
501 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
504 mutex_lock(&mdev
->graph_mutex
);
505 ret
= __media_pipeline_start(entity
, pipe
);
506 mutex_unlock(&mdev
->graph_mutex
);
509 EXPORT_SYMBOL_GPL(media_pipeline_start
);
511 void __media_pipeline_stop(struct media_entity
*entity
)
513 struct media_graph
*graph
= &entity
->pipe
->graph
;
514 struct media_pipeline
*pipe
= entity
->pipe
;
517 WARN_ON(!pipe
->streaming_count
);
518 media_graph_walk_start(graph
, entity
);
520 while ((entity
= media_graph_walk_next(graph
))) {
521 /* Sanity check for negative stream_count */
522 if (!WARN_ON_ONCE(entity
->stream_count
<= 0)) {
523 entity
->stream_count
--;
524 if (entity
->stream_count
== 0)
529 if (!--pipe
->streaming_count
)
530 media_graph_walk_cleanup(graph
);
533 EXPORT_SYMBOL_GPL(__media_pipeline_stop
);
535 void media_pipeline_stop(struct media_entity
*entity
)
537 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
539 mutex_lock(&mdev
->graph_mutex
);
540 __media_pipeline_stop(entity
);
541 mutex_unlock(&mdev
->graph_mutex
);
543 EXPORT_SYMBOL_GPL(media_pipeline_stop
);
545 /* -----------------------------------------------------------------------------
549 struct media_entity
*media_entity_get(struct media_entity
*entity
)
554 if (entity
->graph_obj
.mdev
->dev
&&
555 !try_module_get(entity
->graph_obj
.mdev
->dev
->driver
->owner
))
560 EXPORT_SYMBOL_GPL(media_entity_get
);
562 void media_entity_put(struct media_entity
*entity
)
567 if (entity
->graph_obj
.mdev
->dev
)
568 module_put(entity
->graph_obj
.mdev
->dev
->driver
->owner
);
570 EXPORT_SYMBOL_GPL(media_entity_put
);
572 /* -----------------------------------------------------------------------------
576 static struct media_link
*media_add_link(struct list_head
*head
)
578 struct media_link
*link
;
580 link
= kzalloc(sizeof(*link
), GFP_KERNEL
);
584 list_add_tail(&link
->list
, head
);
589 static void __media_entity_remove_link(struct media_entity
*entity
,
590 struct media_link
*link
)
592 struct media_link
*rlink
, *tmp
;
593 struct media_entity
*remote
;
595 if (link
->source
->entity
== entity
)
596 remote
= link
->sink
->entity
;
598 remote
= link
->source
->entity
;
600 list_for_each_entry_safe(rlink
, tmp
, &remote
->links
, list
) {
601 if (rlink
!= link
->reverse
)
604 if (link
->source
->entity
== entity
)
605 remote
->num_backlinks
--;
607 /* Remove the remote link */
608 list_del(&rlink
->list
);
609 media_gobj_destroy(&rlink
->graph_obj
);
612 if (--remote
->num_links
== 0)
615 list_del(&link
->list
);
616 media_gobj_destroy(&link
->graph_obj
);
621 media_create_pad_link(struct media_entity
*source
, u16 source_pad
,
622 struct media_entity
*sink
, u16 sink_pad
, u32 flags
)
624 struct media_link
*link
;
625 struct media_link
*backlink
;
627 BUG_ON(source
== NULL
|| sink
== NULL
);
628 BUG_ON(source_pad
>= source
->num_pads
);
629 BUG_ON(sink_pad
>= sink
->num_pads
);
631 link
= media_add_link(&source
->links
);
635 link
->source
= &source
->pads
[source_pad
];
636 link
->sink
= &sink
->pads
[sink_pad
];
637 link
->flags
= flags
& ~MEDIA_LNK_FL_INTERFACE_LINK
;
639 /* Initialize graph object embedded at the new link */
640 media_gobj_create(source
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
643 /* Create the backlink. Backlinks are used to help graph traversal and
644 * are not reported to userspace.
646 backlink
= media_add_link(&sink
->links
);
647 if (backlink
== NULL
) {
648 __media_entity_remove_link(source
, link
);
652 backlink
->source
= &source
->pads
[source_pad
];
653 backlink
->sink
= &sink
->pads
[sink_pad
];
654 backlink
->flags
= flags
;
655 backlink
->is_backlink
= true;
657 /* Initialize graph object embedded at the new link */
658 media_gobj_create(sink
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
659 &backlink
->graph_obj
);
661 link
->reverse
= backlink
;
662 backlink
->reverse
= link
;
664 sink
->num_backlinks
++;
670 EXPORT_SYMBOL_GPL(media_create_pad_link
);
672 int media_create_pad_links(const struct media_device
*mdev
,
673 const u32 source_function
,
674 struct media_entity
*source
,
675 const u16 source_pad
,
676 const u32 sink_function
,
677 struct media_entity
*sink
,
680 const bool allow_both_undefined
)
682 struct media_entity
*entity
;
686 /* Trivial case: 1:1 relation */
688 return media_create_pad_link(source
, source_pad
,
689 sink
, sink_pad
, flags
);
691 /* Worse case scenario: n:n relation */
692 if (!source
&& !sink
) {
693 if (!allow_both_undefined
)
695 media_device_for_each_entity(source
, mdev
) {
696 if (source
->function
!= source_function
)
698 media_device_for_each_entity(sink
, mdev
) {
699 if (sink
->function
!= sink_function
)
701 ret
= media_create_pad_link(source
, source_pad
,
706 flags
&= ~(MEDIA_LNK_FL_ENABLED
|
707 MEDIA_LNK_FL_IMMUTABLE
);
713 /* Handle 1:n and n:1 cases */
715 function
= sink_function
;
717 function
= source_function
;
719 media_device_for_each_entity(entity
, mdev
) {
720 if (entity
->function
!= function
)
724 ret
= media_create_pad_link(source
, source_pad
,
725 entity
, sink_pad
, flags
);
727 ret
= media_create_pad_link(entity
, source_pad
,
728 sink
, sink_pad
, flags
);
731 flags
&= ~(MEDIA_LNK_FL_ENABLED
| MEDIA_LNK_FL_IMMUTABLE
);
735 EXPORT_SYMBOL_GPL(media_create_pad_links
);
737 void __media_entity_remove_links(struct media_entity
*entity
)
739 struct media_link
*link
, *tmp
;
741 list_for_each_entry_safe(link
, tmp
, &entity
->links
, list
)
742 __media_entity_remove_link(entity
, link
);
744 entity
->num_links
= 0;
745 entity
->num_backlinks
= 0;
747 EXPORT_SYMBOL_GPL(__media_entity_remove_links
);
749 void media_entity_remove_links(struct media_entity
*entity
)
751 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
753 /* Do nothing if the entity is not registered. */
757 mutex_lock(&mdev
->graph_mutex
);
758 __media_entity_remove_links(entity
);
759 mutex_unlock(&mdev
->graph_mutex
);
761 EXPORT_SYMBOL_GPL(media_entity_remove_links
);
763 static int __media_entity_setup_link_notify(struct media_link
*link
, u32 flags
)
767 /* Notify both entities. */
768 ret
= media_entity_call(link
->source
->entity
, link_setup
,
769 link
->source
, link
->sink
, flags
);
770 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
773 ret
= media_entity_call(link
->sink
->entity
, link_setup
,
774 link
->sink
, link
->source
, flags
);
775 if (ret
< 0 && ret
!= -ENOIOCTLCMD
) {
776 media_entity_call(link
->source
->entity
, link_setup
,
777 link
->source
, link
->sink
, link
->flags
);
782 link
->reverse
->flags
= link
->flags
;
787 int __media_entity_setup_link(struct media_link
*link
, u32 flags
)
789 const u32 mask
= MEDIA_LNK_FL_ENABLED
;
790 struct media_device
*mdev
;
791 struct media_entity
*source
, *sink
;
797 /* The non-modifiable link flags must not be modified. */
798 if ((link
->flags
& ~mask
) != (flags
& ~mask
))
801 if (link
->flags
& MEDIA_LNK_FL_IMMUTABLE
)
802 return link
->flags
== flags
? 0 : -EINVAL
;
804 if (link
->flags
== flags
)
807 source
= link
->source
->entity
;
808 sink
= link
->sink
->entity
;
810 if (!(link
->flags
& MEDIA_LNK_FL_DYNAMIC
) &&
811 (source
->stream_count
|| sink
->stream_count
))
814 mdev
= source
->graph_obj
.mdev
;
816 if (mdev
->ops
&& mdev
->ops
->link_notify
) {
817 ret
= mdev
->ops
->link_notify(link
, flags
,
818 MEDIA_DEV_NOTIFY_PRE_LINK_CH
);
823 ret
= __media_entity_setup_link_notify(link
, flags
);
825 if (mdev
->ops
&& mdev
->ops
->link_notify
)
826 mdev
->ops
->link_notify(link
, flags
,
827 MEDIA_DEV_NOTIFY_POST_LINK_CH
);
831 EXPORT_SYMBOL_GPL(__media_entity_setup_link
);
833 int media_entity_setup_link(struct media_link
*link
, u32 flags
)
837 mutex_lock(&link
->graph_obj
.mdev
->graph_mutex
);
838 ret
= __media_entity_setup_link(link
, flags
);
839 mutex_unlock(&link
->graph_obj
.mdev
->graph_mutex
);
843 EXPORT_SYMBOL_GPL(media_entity_setup_link
);
846 media_entity_find_link(struct media_pad
*source
, struct media_pad
*sink
)
848 struct media_link
*link
;
850 list_for_each_entry(link
, &source
->entity
->links
, list
) {
851 if (link
->source
->entity
== source
->entity
&&
852 link
->source
->index
== source
->index
&&
853 link
->sink
->entity
== sink
->entity
&&
854 link
->sink
->index
== sink
->index
)
860 EXPORT_SYMBOL_GPL(media_entity_find_link
);
862 struct media_pad
*media_entity_remote_pad(struct media_pad
*pad
)
864 struct media_link
*link
;
866 list_for_each_entry(link
, &pad
->entity
->links
, list
) {
867 if (!(link
->flags
& MEDIA_LNK_FL_ENABLED
))
870 if (link
->source
== pad
)
873 if (link
->sink
== pad
)
880 EXPORT_SYMBOL_GPL(media_entity_remote_pad
);
882 static void media_interface_init(struct media_device
*mdev
,
883 struct media_interface
*intf
,
885 u32 intf_type
, u32 flags
)
887 intf
->type
= intf_type
;
889 INIT_LIST_HEAD(&intf
->links
);
891 media_gobj_create(mdev
, gobj_type
, &intf
->graph_obj
);
894 /* Functions related to the media interface via device nodes */
896 struct media_intf_devnode
*media_devnode_create(struct media_device
*mdev
,
898 u32 major
, u32 minor
)
900 struct media_intf_devnode
*devnode
;
902 devnode
= kzalloc(sizeof(*devnode
), GFP_KERNEL
);
906 devnode
->major
= major
;
907 devnode
->minor
= minor
;
909 media_interface_init(mdev
, &devnode
->intf
, MEDIA_GRAPH_INTF_DEVNODE
,
914 EXPORT_SYMBOL_GPL(media_devnode_create
);
916 void media_devnode_remove(struct media_intf_devnode
*devnode
)
918 media_remove_intf_links(&devnode
->intf
);
919 media_gobj_destroy(&devnode
->intf
.graph_obj
);
922 EXPORT_SYMBOL_GPL(media_devnode_remove
);
924 struct media_link
*media_create_intf_link(struct media_entity
*entity
,
925 struct media_interface
*intf
,
928 struct media_link
*link
;
930 link
= media_add_link(&intf
->links
);
935 link
->entity
= entity
;
936 link
->flags
= flags
| MEDIA_LNK_FL_INTERFACE_LINK
;
938 /* Initialize graph object embedded at the new link */
939 media_gobj_create(intf
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
944 EXPORT_SYMBOL_GPL(media_create_intf_link
);
946 void __media_remove_intf_link(struct media_link
*link
)
948 list_del(&link
->list
);
949 media_gobj_destroy(&link
->graph_obj
);
952 EXPORT_SYMBOL_GPL(__media_remove_intf_link
);
954 void media_remove_intf_link(struct media_link
*link
)
956 struct media_device
*mdev
= link
->graph_obj
.mdev
;
958 /* Do nothing if the intf is not registered. */
962 mutex_lock(&mdev
->graph_mutex
);
963 __media_remove_intf_link(link
);
964 mutex_unlock(&mdev
->graph_mutex
);
966 EXPORT_SYMBOL_GPL(media_remove_intf_link
);
968 void __media_remove_intf_links(struct media_interface
*intf
)
970 struct media_link
*link
, *tmp
;
972 list_for_each_entry_safe(link
, tmp
, &intf
->links
, list
)
973 __media_remove_intf_link(link
);
976 EXPORT_SYMBOL_GPL(__media_remove_intf_links
);
978 void media_remove_intf_links(struct media_interface
*intf
)
980 struct media_device
*mdev
= intf
->graph_obj
.mdev
;
982 /* Do nothing if the intf is not registered. */
986 mutex_lock(&mdev
->graph_mutex
);
987 __media_remove_intf_links(intf
);
988 mutex_unlock(&mdev
->graph_mutex
);
990 EXPORT_SYMBOL_GPL(media_remove_intf_links
);