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 /* Do nothing if the object is not linked. */
203 if (gobj
->mdev
== NULL
)
206 dev_dbg_obj(__func__
, gobj
);
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
);
324 dev_dbg(entity
->graph_obj
.mdev
->dev
,
325 "begin graph walk at '%s'\n", entity
->name
);
327 EXPORT_SYMBOL_GPL(media_graph_walk_start
);
329 static void media_graph_walk_iter(struct media_graph
*graph
)
331 struct media_entity
*entity
= stack_top(graph
);
332 struct media_link
*link
;
333 struct media_entity
*next
;
335 link
= list_entry(link_top(graph
), typeof(*link
), list
);
337 /* The link is not enabled so we do not follow. */
338 if (!(link
->flags
& MEDIA_LNK_FL_ENABLED
)) {
339 link_top(graph
) = link_top(graph
)->next
;
340 dev_dbg(entity
->graph_obj
.mdev
->dev
,
341 "walk: skipping disabled link '%s':%u -> '%s':%u\n",
342 link
->source
->entity
->name
, link
->source
->index
,
343 link
->sink
->entity
->name
, link
->sink
->index
);
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
;
353 dev_dbg(entity
->graph_obj
.mdev
->dev
,
354 "walk: skipping entity '%s' (already seen)\n",
359 /* Push the new entity to stack and start over. */
360 link_top(graph
) = link_top(graph
)->next
;
361 stack_push(graph
, next
);
362 dev_dbg(entity
->graph_obj
.mdev
->dev
, "walk: pushing '%s' on stack\n",
366 struct media_entity
*media_graph_walk_next(struct media_graph
*graph
)
368 struct media_entity
*entity
;
370 if (stack_top(graph
) == NULL
)
374 * Depth first search. Push entity to stack and continue from
375 * top of the stack until no more entities on the level can be
378 while (link_top(graph
) != &stack_top(graph
)->links
)
379 media_graph_walk_iter(graph
);
381 entity
= stack_pop(graph
);
382 dev_dbg(entity
->graph_obj
.mdev
->dev
,
383 "walk: returning entity '%s'\n", entity
->name
);
387 EXPORT_SYMBOL_GPL(media_graph_walk_next
);
389 /* -----------------------------------------------------------------------------
390 * Pipeline management
393 __must_check
int __media_pipeline_start(struct media_entity
*entity
,
394 struct media_pipeline
*pipe
)
396 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
397 struct media_graph
*graph
= &pipe
->graph
;
398 struct media_entity
*entity_err
= entity
;
399 struct media_link
*link
;
402 if (!pipe
->streaming_count
++) {
403 ret
= media_graph_walk_init(&pipe
->graph
, mdev
);
405 goto error_graph_walk_start
;
408 media_graph_walk_start(&pipe
->graph
, entity
);
410 while ((entity
= media_graph_walk_next(graph
))) {
411 DECLARE_BITMAP(active
, MEDIA_ENTITY_MAX_PADS
);
412 DECLARE_BITMAP(has_no_links
, MEDIA_ENTITY_MAX_PADS
);
414 entity
->stream_count
++;
416 if (WARN_ON(entity
->pipe
&& entity
->pipe
!= pipe
)) {
423 /* Already streaming --- no need to check. */
424 if (entity
->stream_count
> 1)
427 if (!entity
->ops
|| !entity
->ops
->link_validate
)
430 bitmap_zero(active
, entity
->num_pads
);
431 bitmap_fill(has_no_links
, entity
->num_pads
);
433 list_for_each_entry(link
, &entity
->links
, list
) {
434 struct media_pad
*pad
= link
->sink
->entity
== entity
435 ? link
->sink
: link
->source
;
437 /* Mark that a pad is connected by a link. */
438 bitmap_clear(has_no_links
, pad
->index
, 1);
441 * Pads that either do not need to connect or
442 * are connected through an enabled link are
445 if (!(pad
->flags
& MEDIA_PAD_FL_MUST_CONNECT
) ||
446 link
->flags
& MEDIA_LNK_FL_ENABLED
)
447 bitmap_set(active
, pad
->index
, 1);
450 * Link validation will only take place for
451 * sink ends of the link that are enabled.
453 if (link
->sink
!= pad
||
454 !(link
->flags
& MEDIA_LNK_FL_ENABLED
))
457 ret
= entity
->ops
->link_validate(link
);
458 if (ret
< 0 && ret
!= -ENOIOCTLCMD
) {
459 dev_dbg(entity
->graph_obj
.mdev
->dev
,
460 "link validation failed for '%s':%u -> '%s':%u, error %d\n",
461 link
->source
->entity
->name
,
463 entity
->name
, link
->sink
->index
, ret
);
468 /* Either no links or validated links are fine. */
469 bitmap_or(active
, active
, has_no_links
, entity
->num_pads
);
471 if (!bitmap_full(active
, entity
->num_pads
)) {
473 dev_dbg(entity
->graph_obj
.mdev
->dev
,
474 "'%s':%u must be connected by an enabled link\n",
476 (unsigned)find_first_zero_bit(
477 active
, entity
->num_pads
));
486 * Link validation on graph failed. We revert what we did and
489 media_graph_walk_start(graph
, entity_err
);
491 while ((entity_err
= media_graph_walk_next(graph
))) {
492 /* Sanity check for negative stream_count */
493 if (!WARN_ON_ONCE(entity_err
->stream_count
<= 0)) {
494 entity_err
->stream_count
--;
495 if (entity_err
->stream_count
== 0)
496 entity_err
->pipe
= NULL
;
500 * We haven't increased stream_count further than this
503 if (entity_err
== entity
)
507 error_graph_walk_start
:
508 if (!--pipe
->streaming_count
)
509 media_graph_walk_cleanup(graph
);
513 EXPORT_SYMBOL_GPL(__media_pipeline_start
);
515 __must_check
int media_pipeline_start(struct media_entity
*entity
,
516 struct media_pipeline
*pipe
)
518 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
521 mutex_lock(&mdev
->graph_mutex
);
522 ret
= __media_pipeline_start(entity
, pipe
);
523 mutex_unlock(&mdev
->graph_mutex
);
526 EXPORT_SYMBOL_GPL(media_pipeline_start
);
528 void __media_pipeline_stop(struct media_entity
*entity
)
530 struct media_graph
*graph
= &entity
->pipe
->graph
;
531 struct media_pipeline
*pipe
= entity
->pipe
;
534 WARN_ON(!pipe
->streaming_count
);
535 media_graph_walk_start(graph
, entity
);
537 while ((entity
= media_graph_walk_next(graph
))) {
538 /* Sanity check for negative stream_count */
539 if (!WARN_ON_ONCE(entity
->stream_count
<= 0)) {
540 entity
->stream_count
--;
541 if (entity
->stream_count
== 0)
546 if (!--pipe
->streaming_count
)
547 media_graph_walk_cleanup(graph
);
550 EXPORT_SYMBOL_GPL(__media_pipeline_stop
);
552 void media_pipeline_stop(struct media_entity
*entity
)
554 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
556 mutex_lock(&mdev
->graph_mutex
);
557 __media_pipeline_stop(entity
);
558 mutex_unlock(&mdev
->graph_mutex
);
560 EXPORT_SYMBOL_GPL(media_pipeline_stop
);
562 /* -----------------------------------------------------------------------------
566 struct media_entity
*media_entity_get(struct media_entity
*entity
)
571 if (entity
->graph_obj
.mdev
->dev
&&
572 !try_module_get(entity
->graph_obj
.mdev
->dev
->driver
->owner
))
577 EXPORT_SYMBOL_GPL(media_entity_get
);
579 void media_entity_put(struct media_entity
*entity
)
584 if (entity
->graph_obj
.mdev
->dev
)
585 module_put(entity
->graph_obj
.mdev
->dev
->driver
->owner
);
587 EXPORT_SYMBOL_GPL(media_entity_put
);
589 /* -----------------------------------------------------------------------------
593 static struct media_link
*media_add_link(struct list_head
*head
)
595 struct media_link
*link
;
597 link
= kzalloc(sizeof(*link
), GFP_KERNEL
);
601 list_add_tail(&link
->list
, head
);
606 static void __media_entity_remove_link(struct media_entity
*entity
,
607 struct media_link
*link
)
609 struct media_link
*rlink
, *tmp
;
610 struct media_entity
*remote
;
612 if (link
->source
->entity
== entity
)
613 remote
= link
->sink
->entity
;
615 remote
= link
->source
->entity
;
617 list_for_each_entry_safe(rlink
, tmp
, &remote
->links
, list
) {
618 if (rlink
!= link
->reverse
)
621 if (link
->source
->entity
== entity
)
622 remote
->num_backlinks
--;
624 /* Remove the remote link */
625 list_del(&rlink
->list
);
626 media_gobj_destroy(&rlink
->graph_obj
);
629 if (--remote
->num_links
== 0)
632 list_del(&link
->list
);
633 media_gobj_destroy(&link
->graph_obj
);
638 media_create_pad_link(struct media_entity
*source
, u16 source_pad
,
639 struct media_entity
*sink
, u16 sink_pad
, u32 flags
)
641 struct media_link
*link
;
642 struct media_link
*backlink
;
644 BUG_ON(source
== NULL
|| sink
== NULL
);
645 BUG_ON(source_pad
>= source
->num_pads
);
646 BUG_ON(sink_pad
>= sink
->num_pads
);
648 link
= media_add_link(&source
->links
);
652 link
->source
= &source
->pads
[source_pad
];
653 link
->sink
= &sink
->pads
[sink_pad
];
654 link
->flags
= flags
& ~MEDIA_LNK_FL_INTERFACE_LINK
;
656 /* Initialize graph object embedded at the new link */
657 media_gobj_create(source
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
660 /* Create the backlink. Backlinks are used to help graph traversal and
661 * are not reported to userspace.
663 backlink
= media_add_link(&sink
->links
);
664 if (backlink
== NULL
) {
665 __media_entity_remove_link(source
, link
);
669 backlink
->source
= &source
->pads
[source_pad
];
670 backlink
->sink
= &sink
->pads
[sink_pad
];
671 backlink
->flags
= flags
;
672 backlink
->is_backlink
= true;
674 /* Initialize graph object embedded at the new link */
675 media_gobj_create(sink
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
676 &backlink
->graph_obj
);
678 link
->reverse
= backlink
;
679 backlink
->reverse
= link
;
681 sink
->num_backlinks
++;
687 EXPORT_SYMBOL_GPL(media_create_pad_link
);
689 int media_create_pad_links(const struct media_device
*mdev
,
690 const u32 source_function
,
691 struct media_entity
*source
,
692 const u16 source_pad
,
693 const u32 sink_function
,
694 struct media_entity
*sink
,
697 const bool allow_both_undefined
)
699 struct media_entity
*entity
;
703 /* Trivial case: 1:1 relation */
705 return media_create_pad_link(source
, source_pad
,
706 sink
, sink_pad
, flags
);
708 /* Worse case scenario: n:n relation */
709 if (!source
&& !sink
) {
710 if (!allow_both_undefined
)
712 media_device_for_each_entity(source
, mdev
) {
713 if (source
->function
!= source_function
)
715 media_device_for_each_entity(sink
, mdev
) {
716 if (sink
->function
!= sink_function
)
718 ret
= media_create_pad_link(source
, source_pad
,
723 flags
&= ~(MEDIA_LNK_FL_ENABLED
|
724 MEDIA_LNK_FL_IMMUTABLE
);
730 /* Handle 1:n and n:1 cases */
732 function
= sink_function
;
734 function
= source_function
;
736 media_device_for_each_entity(entity
, mdev
) {
737 if (entity
->function
!= function
)
741 ret
= media_create_pad_link(source
, source_pad
,
742 entity
, sink_pad
, flags
);
744 ret
= media_create_pad_link(entity
, source_pad
,
745 sink
, sink_pad
, flags
);
748 flags
&= ~(MEDIA_LNK_FL_ENABLED
| MEDIA_LNK_FL_IMMUTABLE
);
752 EXPORT_SYMBOL_GPL(media_create_pad_links
);
754 void __media_entity_remove_links(struct media_entity
*entity
)
756 struct media_link
*link
, *tmp
;
758 list_for_each_entry_safe(link
, tmp
, &entity
->links
, list
)
759 __media_entity_remove_link(entity
, link
);
761 entity
->num_links
= 0;
762 entity
->num_backlinks
= 0;
764 EXPORT_SYMBOL_GPL(__media_entity_remove_links
);
766 void media_entity_remove_links(struct media_entity
*entity
)
768 struct media_device
*mdev
= entity
->graph_obj
.mdev
;
770 /* Do nothing if the entity is not registered. */
774 mutex_lock(&mdev
->graph_mutex
);
775 __media_entity_remove_links(entity
);
776 mutex_unlock(&mdev
->graph_mutex
);
778 EXPORT_SYMBOL_GPL(media_entity_remove_links
);
780 static int __media_entity_setup_link_notify(struct media_link
*link
, u32 flags
)
784 /* Notify both entities. */
785 ret
= media_entity_call(link
->source
->entity
, link_setup
,
786 link
->source
, link
->sink
, flags
);
787 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
790 ret
= media_entity_call(link
->sink
->entity
, link_setup
,
791 link
->sink
, link
->source
, flags
);
792 if (ret
< 0 && ret
!= -ENOIOCTLCMD
) {
793 media_entity_call(link
->source
->entity
, link_setup
,
794 link
->source
, link
->sink
, link
->flags
);
799 link
->reverse
->flags
= link
->flags
;
804 int __media_entity_setup_link(struct media_link
*link
, u32 flags
)
806 const u32 mask
= MEDIA_LNK_FL_ENABLED
;
807 struct media_device
*mdev
;
808 struct media_entity
*source
, *sink
;
814 /* The non-modifiable link flags must not be modified. */
815 if ((link
->flags
& ~mask
) != (flags
& ~mask
))
818 if (link
->flags
& MEDIA_LNK_FL_IMMUTABLE
)
819 return link
->flags
== flags
? 0 : -EINVAL
;
821 if (link
->flags
== flags
)
824 source
= link
->source
->entity
;
825 sink
= link
->sink
->entity
;
827 if (!(link
->flags
& MEDIA_LNK_FL_DYNAMIC
) &&
828 (source
->stream_count
|| sink
->stream_count
))
831 mdev
= source
->graph_obj
.mdev
;
833 if (mdev
->ops
&& mdev
->ops
->link_notify
) {
834 ret
= mdev
->ops
->link_notify(link
, flags
,
835 MEDIA_DEV_NOTIFY_PRE_LINK_CH
);
840 ret
= __media_entity_setup_link_notify(link
, flags
);
842 if (mdev
->ops
&& mdev
->ops
->link_notify
)
843 mdev
->ops
->link_notify(link
, flags
,
844 MEDIA_DEV_NOTIFY_POST_LINK_CH
);
848 EXPORT_SYMBOL_GPL(__media_entity_setup_link
);
850 int media_entity_setup_link(struct media_link
*link
, u32 flags
)
854 mutex_lock(&link
->graph_obj
.mdev
->graph_mutex
);
855 ret
= __media_entity_setup_link(link
, flags
);
856 mutex_unlock(&link
->graph_obj
.mdev
->graph_mutex
);
860 EXPORT_SYMBOL_GPL(media_entity_setup_link
);
863 media_entity_find_link(struct media_pad
*source
, struct media_pad
*sink
)
865 struct media_link
*link
;
867 list_for_each_entry(link
, &source
->entity
->links
, list
) {
868 if (link
->source
->entity
== source
->entity
&&
869 link
->source
->index
== source
->index
&&
870 link
->sink
->entity
== sink
->entity
&&
871 link
->sink
->index
== sink
->index
)
877 EXPORT_SYMBOL_GPL(media_entity_find_link
);
879 struct media_pad
*media_entity_remote_pad(struct media_pad
*pad
)
881 struct media_link
*link
;
883 list_for_each_entry(link
, &pad
->entity
->links
, list
) {
884 if (!(link
->flags
& MEDIA_LNK_FL_ENABLED
))
887 if (link
->source
== pad
)
890 if (link
->sink
== pad
)
897 EXPORT_SYMBOL_GPL(media_entity_remote_pad
);
899 static void media_interface_init(struct media_device
*mdev
,
900 struct media_interface
*intf
,
902 u32 intf_type
, u32 flags
)
904 intf
->type
= intf_type
;
906 INIT_LIST_HEAD(&intf
->links
);
908 media_gobj_create(mdev
, gobj_type
, &intf
->graph_obj
);
911 /* Functions related to the media interface via device nodes */
913 struct media_intf_devnode
*media_devnode_create(struct media_device
*mdev
,
915 u32 major
, u32 minor
)
917 struct media_intf_devnode
*devnode
;
919 devnode
= kzalloc(sizeof(*devnode
), GFP_KERNEL
);
923 devnode
->major
= major
;
924 devnode
->minor
= minor
;
926 media_interface_init(mdev
, &devnode
->intf
, MEDIA_GRAPH_INTF_DEVNODE
,
931 EXPORT_SYMBOL_GPL(media_devnode_create
);
933 void media_devnode_remove(struct media_intf_devnode
*devnode
)
935 media_remove_intf_links(&devnode
->intf
);
936 media_gobj_destroy(&devnode
->intf
.graph_obj
);
939 EXPORT_SYMBOL_GPL(media_devnode_remove
);
941 struct media_link
*media_create_intf_link(struct media_entity
*entity
,
942 struct media_interface
*intf
,
945 struct media_link
*link
;
947 link
= media_add_link(&intf
->links
);
952 link
->entity
= entity
;
953 link
->flags
= flags
| MEDIA_LNK_FL_INTERFACE_LINK
;
955 /* Initialize graph object embedded at the new link */
956 media_gobj_create(intf
->graph_obj
.mdev
, MEDIA_GRAPH_LINK
,
961 EXPORT_SYMBOL_GPL(media_create_intf_link
);
963 void __media_remove_intf_link(struct media_link
*link
)
965 list_del(&link
->list
);
966 media_gobj_destroy(&link
->graph_obj
);
969 EXPORT_SYMBOL_GPL(__media_remove_intf_link
);
971 void media_remove_intf_link(struct media_link
*link
)
973 struct media_device
*mdev
= link
->graph_obj
.mdev
;
975 /* Do nothing if the intf is not registered. */
979 mutex_lock(&mdev
->graph_mutex
);
980 __media_remove_intf_link(link
);
981 mutex_unlock(&mdev
->graph_mutex
);
983 EXPORT_SYMBOL_GPL(media_remove_intf_link
);
985 void __media_remove_intf_links(struct media_interface
*intf
)
987 struct media_link
*link
, *tmp
;
989 list_for_each_entry_safe(link
, tmp
, &intf
->links
, list
)
990 __media_remove_intf_link(link
);
993 EXPORT_SYMBOL_GPL(__media_remove_intf_links
);
995 void media_remove_intf_links(struct media_interface
*intf
)
997 struct media_device
*mdev
= intf
->graph_obj
.mdev
;
999 /* Do nothing if the intf is not registered. */
1003 mutex_lock(&mdev
->graph_mutex
);
1004 __media_remove_intf_links(intf
);
1005 mutex_unlock(&mdev
->graph_mutex
);
1007 EXPORT_SYMBOL_GPL(media_remove_intf_links
);