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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/bitmap.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <media/media-entity.h>
27 #include <media/media-device.h>
29 static inline const char *gobj_type(enum media_gobj_type type
)
32 case MEDIA_GRAPH_ENTITY
:
36 case MEDIA_GRAPH_LINK
:
38 case MEDIA_GRAPH_INTF_DEVNODE
:
39 return "intf-devnode";
45 static inline const char *intf_type(struct media_interface
*intf
)
48 case MEDIA_INTF_T_DVB_FE
:
49 return "dvb-frontend";
50 case MEDIA_INTF_T_DVB_DEMUX
:
52 case MEDIA_INTF_T_DVB_DVR
:
54 case MEDIA_INTF_T_DVB_CA
:
56 case MEDIA_INTF_T_DVB_NET
:
58 case MEDIA_INTF_T_V4L_VIDEO
:
60 case MEDIA_INTF_T_V4L_VBI
:
62 case MEDIA_INTF_T_V4L_RADIO
:
64 case MEDIA_INTF_T_V4L_SUBDEV
:
66 case MEDIA_INTF_T_V4L_SWRADIO
:
68 case MEDIA_INTF_T_ALSA_PCM_CAPTURE
:
69 return "alsa-pcm-capture";
70 case MEDIA_INTF_T_ALSA_PCM_PLAYBACK
:
71 return "alsa-pcm-playback";
72 case MEDIA_INTF_T_ALSA_CONTROL
:
73 return "alsa-control";
74 case MEDIA_INTF_T_ALSA_COMPRESS
:
75 return "alsa-compress";
76 case MEDIA_INTF_T_ALSA_RAWMIDI
:
77 return "alsa-rawmidi";
78 case MEDIA_INTF_T_ALSA_HWDEP
:
80 case MEDIA_INTF_T_ALSA_SEQUENCER
:
81 return "alsa-sequencer";
82 case MEDIA_INTF_T_ALSA_TIMER
:
85 return "unknown-intf";
89 __must_check
int __media_entity_enum_init(struct media_entity_enum
*ent_enum
,
92 idx_max
= ALIGN(idx_max
, BITS_PER_LONG
);
93 ent_enum
->bmap
= kcalloc(idx_max
/ BITS_PER_LONG
, sizeof(long),
98 bitmap_zero(ent_enum
->bmap
, idx_max
);
99 ent_enum
->idx_max
= idx_max
;
103 EXPORT_SYMBOL_GPL(__media_entity_enum_init
);
105 void media_entity_enum_cleanup(struct media_entity_enum
*ent_enum
)
107 kfree(ent_enum
->bmap
);
109 EXPORT_SYMBOL_GPL(media_entity_enum_cleanup
);
112 * dev_dbg_obj - Prints in debug mode a change on some object
114 * @event_name: Name of the event to report. Could be __func__
115 * @gobj: Pointer to the object
117 * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
118 * won't produce any code.
120 static void dev_dbg_obj(const char *event_name
, struct media_gobj
*gobj
)
122 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
123 switch (media_type(gobj
)) {
124 case MEDIA_GRAPH_ENTITY
:
125 dev_dbg(gobj
->mdev
->dev
,
126 "%s id %u: entity '%s'\n",
127 event_name
, media_id(gobj
),
128 gobj_to_entity(gobj
)->name
);
130 case MEDIA_GRAPH_LINK
:
132 struct media_link
*link
= gobj_to_link(gobj
);
134 dev_dbg(gobj
->mdev
->dev
,
135 "%s id %u: %s link id %u ==> id %u\n",
136 event_name
, media_id(gobj
),
137 media_type(link
->gobj0
) == MEDIA_GRAPH_PAD
?
138 "data" : "interface",
139 media_id(link
->gobj0
),
140 media_id(link
->gobj1
));
143 case MEDIA_GRAPH_PAD
:
145 struct media_pad
*pad
= gobj_to_pad(gobj
);
147 dev_dbg(gobj
->mdev
->dev
,
148 "%s id %u: %s%spad '%s':%d\n",
149 event_name
, media_id(gobj
),
150 pad
->flags
& MEDIA_PAD_FL_SINK
? "sink " : "",
151 pad
->flags
& MEDIA_PAD_FL_SOURCE
? "source " : "",
152 pad
->entity
->name
, pad
->index
);
155 case MEDIA_GRAPH_INTF_DEVNODE
:
157 struct media_interface
*intf
= gobj_to_intf(gobj
);
158 struct media_intf_devnode
*devnode
= intf_to_devnode(intf
);
160 dev_dbg(gobj
->mdev
->dev
,
161 "%s id %u: intf_devnode %s - major: %d, minor: %d\n",
162 event_name
, media_id(gobj
),
164 devnode
->major
, devnode
->minor
);
171 void media_gobj_create(struct media_device
*mdev
,
172 enum media_gobj_type type
,
173 struct media_gobj
*gobj
)
179 /* Create a per-type unique object ID */
180 gobj
->id
= media_gobj_gen_id(type
, ++mdev
->id
);
183 case MEDIA_GRAPH_ENTITY
:
184 list_add_tail(&gobj
->list
, &mdev
->entities
);
186 case MEDIA_GRAPH_PAD
:
187 list_add_tail(&gobj
->list
, &mdev
->pads
);
189 case MEDIA_GRAPH_LINK
:
190 list_add_tail(&gobj
->list
, &mdev
->links
);
192 case MEDIA_GRAPH_INTF_DEVNODE
:
193 list_add_tail(&gobj
->list
, &mdev
->interfaces
);
197 mdev
->topology_version
++;
199 dev_dbg_obj(__func__
, gobj
);
202 void media_gobj_destroy(struct media_gobj
*gobj
)
204 dev_dbg_obj(__func__
, gobj
);
206 gobj
->mdev
->topology_version
++;
208 /* Remove the object from mdev list */
209 list_del(&gobj
->list
);
212 int media_entity_pads_init(struct media_entity
*entity
, u16 num_pads
,
213 struct media_pad
*pads
)
215 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
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_entity_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_entity_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 * TODO: Get rid of this.
281 #define MEDIA_ENTITY_MAX_PADS 512
284 * media_entity_graph_walk_init - Allocate resources for graph walk
285 * @graph: Media graph structure that will be used to walk the graph
286 * @mdev: Media device
288 * Reserve resources for graph walk in media device's current
289 * state. The memory must be released using
290 * media_entity_graph_walk_free().
292 * Returns error on failure, zero on success.
294 __must_check
int media_entity_graph_walk_init(
295 struct media_entity_graph
*graph
, struct media_device
*mdev
)
297 return media_entity_enum_init(&graph
->ent_enum
, mdev
);
299 EXPORT_SYMBOL_GPL(media_entity_graph_walk_init
);
302 * media_entity_graph_walk_cleanup - Release resources related to graph walking
303 * @graph: Media graph structure that was used to walk the graph
305 void media_entity_graph_walk_cleanup(struct media_entity_graph
*graph
)
307 media_entity_enum_cleanup(&graph
->ent_enum
);
309 EXPORT_SYMBOL_GPL(media_entity_graph_walk_cleanup
);
311 void media_entity_graph_walk_start(struct media_entity_graph
*graph
,
312 struct media_entity
*entity
)
314 media_entity_enum_zero(&graph
->ent_enum
);
315 media_entity_enum_set(&graph
->ent_enum
, entity
);
318 graph
->stack
[graph
->top
].entity
= NULL
;
319 stack_push(graph
, entity
);
321 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start
);
323 struct media_entity
*
324 media_entity_graph_walk_next(struct media_entity_graph
*graph
)
326 if (stack_top(graph
) == NULL
)
330 * Depth first search. Push entity to stack and continue from
331 * top of the stack until no more entities on the level can be
334 while (link_top(graph
) != &stack_top(graph
)->links
) {
335 struct media_entity
*entity
= stack_top(graph
);
336 struct media_link
*link
;
337 struct media_entity
*next
;
339 link
= list_entry(link_top(graph
), typeof(*link
), list
);
341 /* The link is not enabled so we do not follow. */
342 if (!(link
->flags
& MEDIA_LNK_FL_ENABLED
)) {
343 link_top(graph
) = link_top(graph
)->next
;
347 /* Get the entity in the other end of the link . */
348 next
= media_entity_other(entity
, link
);
350 /* Has the entity already been visited? */
351 if (media_entity_enum_test_and_set(&graph
->ent_enum
, next
)) {
352 link_top(graph
) = link_top(graph
)->next
;
356 /* Push the new entity to stack and start over. */
357 link_top(graph
) = link_top(graph
)->next
;
358 stack_push(graph
, next
);
361 return stack_pop(graph
);
363 EXPORT_SYMBOL_GPL(media_entity_graph_walk_next
);
365 /* -----------------------------------------------------------------------------
366 * Pipeline management
369 __must_check
int __media_entity_pipeline_start(struct media_entity
*entity
,
370 struct media_pipeline
*pipe
)
372 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
373 struct media_entity_graph
*graph
= &pipe
->graph
;
374 struct media_entity
*entity_err
= entity
;
375 struct media_link
*link
;
378 if (!pipe
->streaming_count
++) {
379 ret
= media_entity_graph_walk_init(&pipe
->graph
, mdev
);
381 goto error_graph_walk_start
;
384 media_entity_graph_walk_start(&pipe
->graph
, entity
);
386 while ((entity
= media_entity_graph_walk_next(graph
))) {
387 DECLARE_BITMAP(active
, MEDIA_ENTITY_MAX_PADS
);
388 DECLARE_BITMAP(has_no_links
, MEDIA_ENTITY_MAX_PADS
);
390 entity
->stream_count
++;
392 if (WARN_ON(entity
->pipe
&& entity
->pipe
!= pipe
)) {
399 /* Already streaming --- no need to check. */
400 if (entity
->stream_count
> 1)
403 if (!entity
->ops
|| !entity
->ops
->link_validate
)
406 bitmap_zero(active
, entity
->num_pads
);
407 bitmap_fill(has_no_links
, entity
->num_pads
);
409 list_for_each_entry(link
, &entity
->links
, list
) {
410 struct media_pad
*pad
= link
->sink
->entity
== entity
411 ? link
->sink
: link
->source
;
413 /* Mark that a pad is connected by a link. */
414 bitmap_clear(has_no_links
, pad
->index
, 1);
417 * Pads that either do not need to connect or
418 * are connected through an enabled link are
421 if (!(pad
->flags
& MEDIA_PAD_FL_MUST_CONNECT
) ||
422 link
->flags
& MEDIA_LNK_FL_ENABLED
)
423 bitmap_set(active
, pad
->index
, 1);
426 * Link validation will only take place for
427 * sink ends of the link that are enabled.
429 if (link
->sink
!= pad
||
430 !(link
->flags
& MEDIA_LNK_FL_ENABLED
))
433 ret
= entity
->ops
->link_validate(link
);
434 if (ret
< 0 && ret
!= -ENOIOCTLCMD
) {
435 dev_dbg(entity
->graph_obj
.mdev
->dev
,
436 "link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
437 link
->source
->entity
->name
,
439 entity
->name
, link
->sink
->index
, ret
);
444 /* Either no links or validated links are fine. */
445 bitmap_or(active
, active
, has_no_links
, entity
->num_pads
);
447 if (!bitmap_full(active
, entity
->num_pads
)) {
449 dev_dbg(entity
->graph_obj
.mdev
->dev
,
450 "\"%s\":%u must be connected by an enabled link\n",
452 (unsigned)find_first_zero_bit(
453 active
, entity
->num_pads
));
462 * Link validation on graph failed. We revert what we did and
465 media_entity_graph_walk_start(graph
, entity_err
);
467 while ((entity_err
= media_entity_graph_walk_next(graph
))) {
468 /* don't let the stream_count go negative */
469 if (entity
->stream_count
> 0) {
470 entity_err
->stream_count
--;
471 if (entity_err
->stream_count
== 0)
472 entity_err
->pipe
= NULL
;
476 * We haven't increased stream_count further than this
479 if (entity_err
== entity
)
483 error_graph_walk_start
:
484 if (!--pipe
->streaming_count
)
485 media_entity_graph_walk_cleanup(graph
);
489 EXPORT_SYMBOL_GPL(__media_entity_pipeline_start
);
491 __must_check
int media_entity_pipeline_start(struct media_entity
*entity
,
492 struct media_pipeline
*pipe
)
494 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
497 mutex_lock(&mdev
->graph_mutex
);
498 ret
= __media_entity_pipeline_start(entity
, pipe
);
499 mutex_unlock(&mdev
->graph_mutex
);
502 EXPORT_SYMBOL_GPL(media_entity_pipeline_start
);
504 void __media_entity_pipeline_stop(struct media_entity
*entity
)
506 struct media_entity_graph
*graph
= &entity
->pipe
->graph
;
507 struct media_pipeline
*pipe
= entity
->pipe
;
510 WARN_ON(!pipe
->streaming_count
);
511 media_entity_graph_walk_start(graph
, entity
);
513 while ((entity
= media_entity_graph_walk_next(graph
))) {
514 /* don't let the stream_count go negative */
515 if (entity
->stream_count
> 0) {
516 entity
->stream_count
--;
517 if (entity
->stream_count
== 0)
522 if (!--pipe
->streaming_count
)
523 media_entity_graph_walk_cleanup(graph
);
526 EXPORT_SYMBOL_GPL(__media_entity_pipeline_stop
);
528 void media_entity_pipeline_stop(struct media_entity
*entity
)
530 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
532 mutex_lock(&mdev
->graph_mutex
);
533 __media_entity_pipeline_stop(entity
);
534 mutex_unlock(&mdev
->graph_mutex
);
536 EXPORT_SYMBOL_GPL(media_entity_pipeline_stop
);
538 /* -----------------------------------------------------------------------------
542 struct media_entity
*media_entity_get(struct media_entity
*entity
)
547 if (entity
->graph_obj
.mdev
->dev
&&
548 !try_module_get(entity
->graph_obj
.mdev
->dev
->driver
->owner
))
553 EXPORT_SYMBOL_GPL(media_entity_get
);
555 void media_entity_put(struct media_entity
*entity
)
560 if (entity
->graph_obj
.mdev
->dev
)
561 module_put(entity
->graph_obj
.mdev
->dev
->driver
->owner
);
563 EXPORT_SYMBOL_GPL(media_entity_put
);
565 /* -----------------------------------------------------------------------------
569 static struct media_link
*media_add_link(struct list_head
*head
)
571 struct media_link
*link
;
573 link
= kzalloc(sizeof(*link
), GFP_KERNEL
);
577 list_add_tail(&link
->list
, head
);
582 static void __media_entity_remove_link(struct media_entity
*entity
,
583 struct media_link
*link
)
585 struct media_link
*rlink
, *tmp
;
586 struct media_entity
*remote
;
588 if (link
->source
->entity
== entity
)
589 remote
= link
->sink
->entity
;
591 remote
= link
->source
->entity
;
593 list_for_each_entry_safe(rlink
, tmp
, &remote
->links
, list
) {
594 if (rlink
!= link
->reverse
)
597 if (link
->source
->entity
== entity
)
598 remote
->num_backlinks
--;
600 /* Remove the remote link */
601 list_del(&rlink
->list
);
602 media_gobj_destroy(&rlink
->graph_obj
);
605 if (--remote
->num_links
== 0)
608 list_del(&link
->list
);
609 media_gobj_destroy(&link
->graph_obj
);
614 media_create_pad_link(struct media_entity
*source
, u16 source_pad
,
615 struct media_entity
*sink
, u16 sink_pad
, u32 flags
)
617 struct media_link
*link
;
618 struct media_link
*backlink
;
620 BUG_ON(source
== NULL
|| sink
== NULL
);
621 BUG_ON(source_pad
>= source
->num_pads
);
622 BUG_ON(sink_pad
>= sink
->num_pads
);
624 link
= media_add_link(&source
->links
);
628 link
->source
= &source
->pads
[source_pad
];
629 link
->sink
= &sink
->pads
[sink_pad
];
630 link
->flags
= flags
& ~MEDIA_LNK_FL_INTERFACE_LINK
;
632 /* Initialize graph object embedded at the new link */
633 media_gobj_create(source
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
636 /* Create the backlink. Backlinks are used to help graph traversal and
637 * are not reported to userspace.
639 backlink
= media_add_link(&sink
->links
);
640 if (backlink
== NULL
) {
641 __media_entity_remove_link(source
, link
);
645 backlink
->source
= &source
->pads
[source_pad
];
646 backlink
->sink
= &sink
->pads
[sink_pad
];
647 backlink
->flags
= flags
;
648 backlink
->is_backlink
= true;
650 /* Initialize graph object embedded at the new link */
651 media_gobj_create(sink
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
652 &backlink
->graph_obj
);
654 link
->reverse
= backlink
;
655 backlink
->reverse
= link
;
657 sink
->num_backlinks
++;
663 EXPORT_SYMBOL_GPL(media_create_pad_link
);
665 int media_create_pad_links(const struct media_device
*mdev
,
666 const u32 source_function
,
667 struct media_entity
*source
,
668 const u16 source_pad
,
669 const u32 sink_function
,
670 struct media_entity
*sink
,
673 const bool allow_both_undefined
)
675 struct media_entity
*entity
;
679 /* Trivial case: 1:1 relation */
681 return media_create_pad_link(source
, source_pad
,
682 sink
, sink_pad
, flags
);
684 /* Worse case scenario: n:n relation */
685 if (!source
&& !sink
) {
686 if (!allow_both_undefined
)
688 media_device_for_each_entity(source
, mdev
) {
689 if (source
->function
!= source_function
)
691 media_device_for_each_entity(sink
, mdev
) {
692 if (sink
->function
!= sink_function
)
694 ret
= media_create_pad_link(source
, source_pad
,
699 flags
&= ~(MEDIA_LNK_FL_ENABLED
|
700 MEDIA_LNK_FL_IMMUTABLE
);
706 /* Handle 1:n and n:1 cases */
708 function
= sink_function
;
710 function
= source_function
;
712 media_device_for_each_entity(entity
, mdev
) {
713 if (entity
->function
!= function
)
717 ret
= media_create_pad_link(source
, source_pad
,
718 entity
, sink_pad
, flags
);
720 ret
= media_create_pad_link(entity
, source_pad
,
721 sink
, sink_pad
, flags
);
724 flags
&= ~(MEDIA_LNK_FL_ENABLED
| MEDIA_LNK_FL_IMMUTABLE
);
728 EXPORT_SYMBOL_GPL(media_create_pad_links
);
730 void __media_entity_remove_links(struct media_entity
*entity
)
732 struct media_link
*link
, *tmp
;
734 list_for_each_entry_safe(link
, tmp
, &entity
->links
, list
)
735 __media_entity_remove_link(entity
, link
);
737 entity
->num_links
= 0;
738 entity
->num_backlinks
= 0;
740 EXPORT_SYMBOL_GPL(__media_entity_remove_links
);
742 void media_entity_remove_links(struct media_entity
*entity
)
744 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
746 /* Do nothing if the entity is not registered. */
750 mutex_lock(&mdev
->graph_mutex
);
751 __media_entity_remove_links(entity
);
752 mutex_unlock(&mdev
->graph_mutex
);
754 EXPORT_SYMBOL_GPL(media_entity_remove_links
);
756 static int __media_entity_setup_link_notify(struct media_link
*link
, u32 flags
)
760 /* Notify both entities. */
761 ret
= media_entity_call(link
->source
->entity
, link_setup
,
762 link
->source
, link
->sink
, flags
);
763 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
766 ret
= media_entity_call(link
->sink
->entity
, link_setup
,
767 link
->sink
, link
->source
, flags
);
768 if (ret
< 0 && ret
!= -ENOIOCTLCMD
) {
769 media_entity_call(link
->source
->entity
, link_setup
,
770 link
->source
, link
->sink
, link
->flags
);
775 link
->reverse
->flags
= link
->flags
;
780 int __media_entity_setup_link(struct media_link
*link
, u32 flags
)
782 const u32 mask
= MEDIA_LNK_FL_ENABLED
;
783 struct media_device
*mdev
;
784 struct media_entity
*source
, *sink
;
790 /* The non-modifiable link flags must not be modified. */
791 if ((link
->flags
& ~mask
) != (flags
& ~mask
))
794 if (link
->flags
& MEDIA_LNK_FL_IMMUTABLE
)
795 return link
->flags
== flags
? 0 : -EINVAL
;
797 if (link
->flags
== flags
)
800 source
= link
->source
->entity
;
801 sink
= link
->sink
->entity
;
803 if (!(link
->flags
& MEDIA_LNK_FL_DYNAMIC
) &&
804 (source
->stream_count
|| sink
->stream_count
))
807 mdev
= source
->graph_obj
.mdev
;
809 if (mdev
->link_notify
) {
810 ret
= mdev
->link_notify(link
, flags
,
811 MEDIA_DEV_NOTIFY_PRE_LINK_CH
);
816 ret
= __media_entity_setup_link_notify(link
, flags
);
818 if (mdev
->link_notify
)
819 mdev
->link_notify(link
, flags
, MEDIA_DEV_NOTIFY_POST_LINK_CH
);
823 EXPORT_SYMBOL_GPL(__media_entity_setup_link
);
825 int media_entity_setup_link(struct media_link
*link
, u32 flags
)
829 mutex_lock(&link
->graph_obj
.mdev
->graph_mutex
);
830 ret
= __media_entity_setup_link(link
, flags
);
831 mutex_unlock(&link
->graph_obj
.mdev
->graph_mutex
);
835 EXPORT_SYMBOL_GPL(media_entity_setup_link
);
838 media_entity_find_link(struct media_pad
*source
, struct media_pad
*sink
)
840 struct media_link
*link
;
842 list_for_each_entry(link
, &source
->entity
->links
, list
) {
843 if (link
->source
->entity
== source
->entity
&&
844 link
->source
->index
== source
->index
&&
845 link
->sink
->entity
== sink
->entity
&&
846 link
->sink
->index
== sink
->index
)
852 EXPORT_SYMBOL_GPL(media_entity_find_link
);
854 struct media_pad
*media_entity_remote_pad(struct media_pad
*pad
)
856 struct media_link
*link
;
858 list_for_each_entry(link
, &pad
->entity
->links
, list
) {
859 if (!(link
->flags
& MEDIA_LNK_FL_ENABLED
))
862 if (link
->source
== pad
)
865 if (link
->sink
== pad
)
872 EXPORT_SYMBOL_GPL(media_entity_remote_pad
);
874 static void media_interface_init(struct media_device
*mdev
,
875 struct media_interface
*intf
,
877 u32 intf_type
, u32 flags
)
879 intf
->type
= intf_type
;
881 INIT_LIST_HEAD(&intf
->links
);
883 media_gobj_create(mdev
, gobj_type
, &intf
->graph_obj
);
886 /* Functions related to the media interface via device nodes */
888 struct media_intf_devnode
*media_devnode_create(struct media_device
*mdev
,
890 u32 major
, u32 minor
)
892 struct media_intf_devnode
*devnode
;
894 devnode
= kzalloc(sizeof(*devnode
), GFP_KERNEL
);
898 devnode
->major
= major
;
899 devnode
->minor
= minor
;
901 media_interface_init(mdev
, &devnode
->intf
, MEDIA_GRAPH_INTF_DEVNODE
,
906 EXPORT_SYMBOL_GPL(media_devnode_create
);
908 void media_devnode_remove(struct media_intf_devnode
*devnode
)
910 media_remove_intf_links(&devnode
->intf
);
911 media_gobj_destroy(&devnode
->intf
.graph_obj
);
914 EXPORT_SYMBOL_GPL(media_devnode_remove
);
916 struct media_link
*media_create_intf_link(struct media_entity
*entity
,
917 struct media_interface
*intf
,
920 struct media_link
*link
;
922 link
= media_add_link(&intf
->links
);
927 link
->entity
= entity
;
928 link
->flags
= flags
| MEDIA_LNK_FL_INTERFACE_LINK
;
930 /* Initialize graph object embedded at the new link */
931 media_gobj_create(intf
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
936 EXPORT_SYMBOL_GPL(media_create_intf_link
);
938 void __media_remove_intf_link(struct media_link
*link
)
940 list_del(&link
->list
);
941 media_gobj_destroy(&link
->graph_obj
);
944 EXPORT_SYMBOL_GPL(__media_remove_intf_link
);
946 void media_remove_intf_link(struct media_link
*link
)
948 struct media_device
*mdev
= link
->graph_obj
.mdev
;
950 /* Do nothing if the intf is not registered. */
954 mutex_lock(&mdev
->graph_mutex
);
955 __media_remove_intf_link(link
);
956 mutex_unlock(&mdev
->graph_mutex
);
958 EXPORT_SYMBOL_GPL(media_remove_intf_link
);
960 void __media_remove_intf_links(struct media_interface
*intf
)
962 struct media_link
*link
, *tmp
;
964 list_for_each_entry_safe(link
, tmp
, &intf
->links
, list
)
965 __media_remove_intf_link(link
);
968 EXPORT_SYMBOL_GPL(__media_remove_intf_links
);
970 void media_remove_intf_links(struct media_interface
*intf
)
972 struct media_device
*mdev
= intf
->graph_obj
.mdev
;
974 /* Do nothing if the intf is not registered. */
978 mutex_lock(&mdev
->graph_mutex
);
979 __media_remove_intf_links(intf
);
980 mutex_unlock(&mdev
->graph_mutex
);
982 EXPORT_SYMBOL_GPL(media_remove_intf_links
);