]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/media/media-entity.c
13c8ca11f169ef0a96346bb61a7b83f8fe4359ef
[karo-tx-linux.git] / drivers / media / media-entity.c
1 /*
2  * Media entity
3  *
4  * Copyright (C) 2010 Nokia Corporation
5  *
6  * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7  *           Sakari Ailus <sakari.ailus@iki.fi>
8  *
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.
12  *
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.
17  *
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
21  */
22
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>
28
29 static inline const char *gobj_type(enum media_gobj_type type)
30 {
31         switch (type) {
32         case MEDIA_GRAPH_ENTITY:
33                 return "entity";
34         case MEDIA_GRAPH_PAD:
35                 return "pad";
36         case MEDIA_GRAPH_LINK:
37                 return "link";
38         case MEDIA_GRAPH_INTF_DEVNODE:
39                 return "intf-devnode";
40         default:
41                 return "unknown";
42         }
43 }
44
45 static inline const char *intf_type(struct media_interface *intf)
46 {
47         switch (intf->type) {
48         case MEDIA_INTF_T_DVB_FE:
49                 return "frontend";
50         case MEDIA_INTF_T_DVB_DEMUX:
51                 return "demux";
52         case MEDIA_INTF_T_DVB_DVR:
53                 return "DVR";
54         case MEDIA_INTF_T_DVB_CA:
55                 return  "CA";
56         case MEDIA_INTF_T_DVB_NET:
57                 return "dvbnet";
58         case MEDIA_INTF_T_V4L_VIDEO:
59                 return "video";
60         case MEDIA_INTF_T_V4L_VBI:
61                 return "vbi";
62         case MEDIA_INTF_T_V4L_RADIO:
63                 return "radio";
64         case MEDIA_INTF_T_V4L_SUBDEV:
65                 return "v4l2-subdev";
66         case MEDIA_INTF_T_V4L_SWRADIO:
67                 return "swradio";
68         default:
69                 return "unknown-intf";
70         }
71 };
72
73 /**
74  *  dev_dbg_obj - Prints in debug mode a change on some object
75  *
76  * @event_name: Name of the event to report. Could be __func__
77  * @gobj:       Pointer to the object
78  *
79  * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
80  * won't produce any code.
81  */
82 static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
83 {
84 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
85         switch (media_type(gobj)) {
86         case MEDIA_GRAPH_ENTITY:
87                 dev_dbg(gobj->mdev->dev,
88                         "%s: id 0x%08x entity#%d: '%s'\n",
89                         event_name, gobj->id, media_localid(gobj),
90                         gobj_to_entity(gobj)->name);
91                 break;
92         case MEDIA_GRAPH_LINK:
93         {
94                 struct media_link *link = gobj_to_link(gobj);
95
96                 dev_dbg(gobj->mdev->dev,
97                         "%s: id 0x%08x link#%d: %s#%d ==> %s#%d\n",
98                         event_name, gobj->id, media_localid(gobj),
99
100                         gobj_type(media_type(link->gobj0)),
101                         media_localid(link->gobj0),
102
103                         gobj_type(media_type(link->gobj1)),
104                         media_localid(link->gobj1));
105                 break;
106         }
107         case MEDIA_GRAPH_PAD:
108         {
109                 struct media_pad *pad = gobj_to_pad(gobj);
110
111                 dev_dbg(gobj->mdev->dev,
112                         "%s: id 0x%08x %s%spad#%d: '%s':%d\n",
113                         event_name, gobj->id,
114                         pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
115                         pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
116                         media_localid(gobj),
117                         pad->entity->name, pad->index);
118                 break;
119         }
120         case MEDIA_GRAPH_INTF_DEVNODE:
121         {
122                 struct media_interface *intf = gobj_to_intf(gobj);
123                 struct media_intf_devnode *devnode = intf_to_devnode(intf);
124
125                 dev_dbg(gobj->mdev->dev,
126                         "%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
127                         event_name, gobj->id, media_localid(gobj),
128                         intf_type(intf),
129                         devnode->major, devnode->minor);
130                 break;
131         }
132         }
133 #endif
134 }
135
136 void media_gobj_create(struct media_device *mdev,
137                            enum media_gobj_type type,
138                            struct media_gobj *gobj)
139 {
140         BUG_ON(!mdev);
141
142         gobj->mdev = mdev;
143
144         /* Create a per-type unique object ID */
145         switch (type) {
146         case MEDIA_GRAPH_ENTITY:
147                 gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
148                 list_add_tail(&gobj->list, &mdev->entities);
149                 break;
150         case MEDIA_GRAPH_PAD:
151                 gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
152                 list_add_tail(&gobj->list, &mdev->pads);
153                 break;
154         case MEDIA_GRAPH_LINK:
155                 gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
156                 list_add_tail(&gobj->list, &mdev->links);
157                 break;
158         case MEDIA_GRAPH_INTF_DEVNODE:
159                 gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
160                 list_add_tail(&gobj->list, &mdev->interfaces);
161                 break;
162         }
163
164         mdev->topology_version++;
165
166         dev_dbg_obj(__func__, gobj);
167 }
168
169 void media_gobj_destroy(struct media_gobj *gobj)
170 {
171         dev_dbg_obj(__func__, gobj);
172
173         gobj->mdev->topology_version++;
174
175         /* Remove the object from mdev list */
176         list_del(&gobj->list);
177 }
178
179 int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
180                            struct media_pad *pads)
181 {
182         struct media_device *mdev = entity->graph_obj.mdev;
183         unsigned int i;
184
185         entity->num_pads = num_pads;
186         entity->pads = pads;
187
188         if (mdev)
189                 spin_lock(&mdev->lock);
190
191         for (i = 0; i < num_pads; i++) {
192                 pads[i].entity = entity;
193                 pads[i].index = i;
194                 if (mdev)
195                         media_gobj_create(mdev, MEDIA_GRAPH_PAD,
196                                         &entity->pads[i].graph_obj);
197         }
198
199         if (mdev)
200                 spin_unlock(&mdev->lock);
201
202         return 0;
203 }
204 EXPORT_SYMBOL_GPL(media_entity_pads_init);
205
206 /* -----------------------------------------------------------------------------
207  * Graph traversal
208  */
209
210 static struct media_entity *
211 media_entity_other(struct media_entity *entity, struct media_link *link)
212 {
213         if (link->source->entity == entity)
214                 return link->sink->entity;
215         else
216                 return link->source->entity;
217 }
218
219 /* push an entity to traversal stack */
220 static void stack_push(struct media_entity_graph *graph,
221                        struct media_entity *entity)
222 {
223         if (graph->top == MEDIA_ENTITY_ENUM_MAX_DEPTH - 1) {
224                 WARN_ON(1);
225                 return;
226         }
227         graph->top++;
228         graph->stack[graph->top].link = entity->links.next;
229         graph->stack[graph->top].entity = entity;
230 }
231
232 static struct media_entity *stack_pop(struct media_entity_graph *graph)
233 {
234         struct media_entity *entity;
235
236         entity = graph->stack[graph->top].entity;
237         graph->top--;
238
239         return entity;
240 }
241
242 #define link_top(en)    ((en)->stack[(en)->top].link)
243 #define stack_top(en)   ((en)->stack[(en)->top].entity)
244
245 void media_entity_graph_walk_start(struct media_entity_graph *graph,
246                                    struct media_entity *entity)
247 {
248         graph->top = 0;
249         graph->stack[graph->top].entity = NULL;
250         bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
251
252         if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
253                 return;
254
255         __set_bit(media_entity_id(entity), graph->entities);
256         stack_push(graph, entity);
257 }
258 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
259
260 struct media_entity *
261 media_entity_graph_walk_next(struct media_entity_graph *graph)
262 {
263         if (stack_top(graph) == NULL)
264                 return NULL;
265
266         /*
267          * Depth first search. Push entity to stack and continue from
268          * top of the stack until no more entities on the level can be
269          * found.
270          */
271         while (link_top(graph) != &stack_top(graph)->links) {
272                 struct media_entity *entity = stack_top(graph);
273                 struct media_link *link;
274                 struct media_entity *next;
275
276                 link = list_entry(link_top(graph), typeof(*link), list);
277
278                 /* The link is not enabled so we do not follow. */
279                 if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
280                         link_top(graph) = link_top(graph)->next;
281                         continue;
282                 }
283
284                 /* Get the entity in the other end of the link . */
285                 next = media_entity_other(entity, link);
286                 if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
287                         return NULL;
288
289                 /* Has the entity already been visited? */
290                 if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
291                         link_top(graph) = link_top(graph)->next;
292                         continue;
293                 }
294
295                 /* Push the new entity to stack and start over. */
296                 link_top(graph) = link_top(graph)->next;
297                 stack_push(graph, next);
298         }
299
300         return stack_pop(graph);
301 }
302 EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
303
304 /* -----------------------------------------------------------------------------
305  * Pipeline management
306  */
307
308 __must_check int media_entity_pipeline_start(struct media_entity *entity,
309                                              struct media_pipeline *pipe)
310 {
311         struct media_device *mdev = entity->graph_obj.mdev;
312         struct media_entity_graph graph;
313         struct media_entity *entity_err = entity;
314         struct media_link *link;
315         int ret;
316
317         mutex_lock(&mdev->graph_mutex);
318
319         media_entity_graph_walk_start(&graph, entity);
320
321         while ((entity = media_entity_graph_walk_next(&graph))) {
322                 DECLARE_BITMAP(active, MEDIA_ENTITY_MAX_PADS);
323                 DECLARE_BITMAP(has_no_links, MEDIA_ENTITY_MAX_PADS);
324
325                 entity->stream_count++;
326
327                 if (WARN_ON(entity->pipe && entity->pipe != pipe)) {
328                         ret = -EBUSY;
329                         goto error;
330                 }
331
332                 entity->pipe = pipe;
333
334                 /* Already streaming --- no need to check. */
335                 if (entity->stream_count > 1)
336                         continue;
337
338                 if (!entity->ops || !entity->ops->link_validate)
339                         continue;
340
341                 bitmap_zero(active, entity->num_pads);
342                 bitmap_fill(has_no_links, entity->num_pads);
343
344                 list_for_each_entry(link, &entity->links, list) {
345                         struct media_pad *pad = link->sink->entity == entity
346                                                 ? link->sink : link->source;
347
348                         /* Mark that a pad is connected by a link. */
349                         bitmap_clear(has_no_links, pad->index, 1);
350
351                         /*
352                          * Pads that either do not need to connect or
353                          * are connected through an enabled link are
354                          * fine.
355                          */
356                         if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
357                             link->flags & MEDIA_LNK_FL_ENABLED)
358                                 bitmap_set(active, pad->index, 1);
359
360                         /*
361                          * Link validation will only take place for
362                          * sink ends of the link that are enabled.
363                          */
364                         if (link->sink != pad ||
365                             !(link->flags & MEDIA_LNK_FL_ENABLED))
366                                 continue;
367
368                         ret = entity->ops->link_validate(link);
369                         if (ret < 0 && ret != -ENOIOCTLCMD) {
370                                 dev_dbg(entity->graph_obj.mdev->dev,
371                                         "link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
372                                         link->source->entity->name,
373                                         link->source->index,
374                                         entity->name, link->sink->index, ret);
375                                 goto error;
376                         }
377                 }
378
379                 /* Either no links or validated links are fine. */
380                 bitmap_or(active, active, has_no_links, entity->num_pads);
381
382                 if (!bitmap_full(active, entity->num_pads)) {
383                         ret = -EPIPE;
384                         dev_dbg(entity->graph_obj.mdev->dev,
385                                 "\"%s\":%u must be connected by an enabled link\n",
386                                 entity->name,
387                                 (unsigned)find_first_zero_bit(
388                                         active, entity->num_pads));
389                         goto error;
390                 }
391         }
392
393         mutex_unlock(&mdev->graph_mutex);
394
395         return 0;
396
397 error:
398         /*
399          * Link validation on graph failed. We revert what we did and
400          * return the error.
401          */
402         media_entity_graph_walk_start(&graph, entity_err);
403
404         while ((entity_err = media_entity_graph_walk_next(&graph))) {
405                 entity_err->stream_count--;
406                 if (entity_err->stream_count == 0)
407                         entity_err->pipe = NULL;
408
409                 /*
410                  * We haven't increased stream_count further than this
411                  * so we quit here.
412                  */
413                 if (entity_err == entity)
414                         break;
415         }
416
417         mutex_unlock(&mdev->graph_mutex);
418
419         return ret;
420 }
421 EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
422
423 void media_entity_pipeline_stop(struct media_entity *entity)
424 {
425         struct media_device *mdev = entity->graph_obj.mdev;
426         struct media_entity_graph graph;
427
428         mutex_lock(&mdev->graph_mutex);
429
430         media_entity_graph_walk_start(&graph, entity);
431
432         while ((entity = media_entity_graph_walk_next(&graph))) {
433                 entity->stream_count--;
434                 if (entity->stream_count == 0)
435                         entity->pipe = NULL;
436         }
437
438         mutex_unlock(&mdev->graph_mutex);
439 }
440 EXPORT_SYMBOL_GPL(media_entity_pipeline_stop);
441
442 /* -----------------------------------------------------------------------------
443  * Module use count
444  */
445
446 struct media_entity *media_entity_get(struct media_entity *entity)
447 {
448         if (entity == NULL)
449                 return NULL;
450
451         if (entity->graph_obj.mdev->dev &&
452             !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
453                 return NULL;
454
455         return entity;
456 }
457 EXPORT_SYMBOL_GPL(media_entity_get);
458
459 void media_entity_put(struct media_entity *entity)
460 {
461         if (entity == NULL)
462                 return;
463
464         if (entity->graph_obj.mdev->dev)
465                 module_put(entity->graph_obj.mdev->dev->driver->owner);
466 }
467 EXPORT_SYMBOL_GPL(media_entity_put);
468
469 /* -----------------------------------------------------------------------------
470  * Links management
471  */
472
473 static struct media_link *media_add_link(struct list_head *head)
474 {
475         struct media_link *link;
476
477         link = kzalloc(sizeof(*link), GFP_KERNEL);
478         if (link == NULL)
479                 return NULL;
480
481         list_add_tail(&link->list, head);
482
483         return link;
484 }
485
486 static void __media_entity_remove_link(struct media_entity *entity,
487                                        struct media_link *link)
488 {
489         struct media_link *rlink, *tmp;
490         struct media_entity *remote;
491
492         if (link->source->entity == entity)
493                 remote = link->sink->entity;
494         else
495                 remote = link->source->entity;
496
497         list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
498                 if (rlink != link->reverse)
499                         continue;
500
501                 if (link->source->entity == entity)
502                         remote->num_backlinks--;
503
504                 /* Remove the remote link */
505                 list_del(&rlink->list);
506                 media_gobj_destroy(&rlink->graph_obj);
507                 kfree(rlink);
508
509                 if (--remote->num_links == 0)
510                         break;
511         }
512         list_del(&link->list);
513         media_gobj_destroy(&link->graph_obj);
514         kfree(link);
515 }
516
517 int
518 media_create_pad_link(struct media_entity *source, u16 source_pad,
519                          struct media_entity *sink, u16 sink_pad, u32 flags)
520 {
521         struct media_link *link;
522         struct media_link *backlink;
523
524         BUG_ON(source == NULL || sink == NULL);
525         BUG_ON(source_pad >= source->num_pads);
526         BUG_ON(sink_pad >= sink->num_pads);
527
528         link = media_add_link(&source->links);
529         if (link == NULL)
530                 return -ENOMEM;
531
532         link->source = &source->pads[source_pad];
533         link->sink = &sink->pads[sink_pad];
534         link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK;
535
536         /* Initialize graph object embedded at the new link */
537         media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
538                         &link->graph_obj);
539
540         /* Create the backlink. Backlinks are used to help graph traversal and
541          * are not reported to userspace.
542          */
543         backlink = media_add_link(&sink->links);
544         if (backlink == NULL) {
545                 __media_entity_remove_link(source, link);
546                 return -ENOMEM;
547         }
548
549         backlink->source = &source->pads[source_pad];
550         backlink->sink = &sink->pads[sink_pad];
551         backlink->flags = flags;
552         backlink->is_backlink = true;
553
554         /* Initialize graph object embedded at the new link */
555         media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
556                         &backlink->graph_obj);
557
558         link->reverse = backlink;
559         backlink->reverse = link;
560
561         sink->num_backlinks++;
562         sink->num_links++;
563         source->num_links++;
564
565         return 0;
566 }
567 EXPORT_SYMBOL_GPL(media_create_pad_link);
568
569 void __media_entity_remove_links(struct media_entity *entity)
570 {
571         struct media_link *link, *tmp;
572
573         list_for_each_entry_safe(link, tmp, &entity->links, list)
574                 __media_entity_remove_link(entity, link);
575
576         entity->num_links = 0;
577         entity->num_backlinks = 0;
578 }
579 EXPORT_SYMBOL_GPL(__media_entity_remove_links);
580
581 void media_entity_remove_links(struct media_entity *entity)
582 {
583         struct media_device *mdev = entity->graph_obj.mdev;
584
585         /* Do nothing if the entity is not registered. */
586         if (mdev == NULL)
587                 return;
588
589         spin_lock(&mdev->lock);
590         __media_entity_remove_links(entity);
591         spin_unlock(&mdev->lock);
592 }
593 EXPORT_SYMBOL_GPL(media_entity_remove_links);
594
595 static int __media_entity_setup_link_notify(struct media_link *link, u32 flags)
596 {
597         int ret;
598
599         /* Notify both entities. */
600         ret = media_entity_call(link->source->entity, link_setup,
601                                 link->source, link->sink, flags);
602         if (ret < 0 && ret != -ENOIOCTLCMD)
603                 return ret;
604
605         ret = media_entity_call(link->sink->entity, link_setup,
606                                 link->sink, link->source, flags);
607         if (ret < 0 && ret != -ENOIOCTLCMD) {
608                 media_entity_call(link->source->entity, link_setup,
609                                   link->source, link->sink, link->flags);
610                 return ret;
611         }
612
613         link->flags = flags;
614         link->reverse->flags = link->flags;
615
616         return 0;
617 }
618
619 int __media_entity_setup_link(struct media_link *link, u32 flags)
620 {
621         const u32 mask = MEDIA_LNK_FL_ENABLED;
622         struct media_device *mdev;
623         struct media_entity *source, *sink;
624         int ret = -EBUSY;
625
626         if (link == NULL)
627                 return -EINVAL;
628
629         /* The non-modifiable link flags must not be modified. */
630         if ((link->flags & ~mask) != (flags & ~mask))
631                 return -EINVAL;
632
633         if (link->flags & MEDIA_LNK_FL_IMMUTABLE)
634                 return link->flags == flags ? 0 : -EINVAL;
635
636         if (link->flags == flags)
637                 return 0;
638
639         source = link->source->entity;
640         sink = link->sink->entity;
641
642         if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) &&
643             (source->stream_count || sink->stream_count))
644                 return -EBUSY;
645
646         mdev = source->graph_obj.mdev;
647
648         if (mdev->link_notify) {
649                 ret = mdev->link_notify(link, flags,
650                                         MEDIA_DEV_NOTIFY_PRE_LINK_CH);
651                 if (ret < 0)
652                         return ret;
653         }
654
655         ret = __media_entity_setup_link_notify(link, flags);
656
657         if (mdev->link_notify)
658                 mdev->link_notify(link, flags, MEDIA_DEV_NOTIFY_POST_LINK_CH);
659
660         return ret;
661 }
662
663 int media_entity_setup_link(struct media_link *link, u32 flags)
664 {
665         int ret;
666
667         mutex_lock(&link->graph_obj.mdev->graph_mutex);
668         ret = __media_entity_setup_link(link, flags);
669         mutex_unlock(&link->graph_obj.mdev->graph_mutex);
670
671         return ret;
672 }
673 EXPORT_SYMBOL_GPL(media_entity_setup_link);
674
675 struct media_link *
676 media_entity_find_link(struct media_pad *source, struct media_pad *sink)
677 {
678         struct media_link *link;
679
680         list_for_each_entry(link, &source->entity->links, list) {
681                 if (link->source->entity == source->entity &&
682                     link->source->index == source->index &&
683                     link->sink->entity == sink->entity &&
684                     link->sink->index == sink->index)
685                         return link;
686         }
687
688         return NULL;
689 }
690 EXPORT_SYMBOL_GPL(media_entity_find_link);
691
692 struct media_pad *media_entity_remote_pad(struct media_pad *pad)
693 {
694         struct media_link *link;
695
696         list_for_each_entry(link, &pad->entity->links, list) {
697                 if (!(link->flags & MEDIA_LNK_FL_ENABLED))
698                         continue;
699
700                 if (link->source == pad)
701                         return link->sink;
702
703                 if (link->sink == pad)
704                         return link->source;
705         }
706
707         return NULL;
708
709 }
710 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
711
712 static void media_interface_init(struct media_device *mdev,
713                                  struct media_interface *intf,
714                                  u32 gobj_type,
715                                  u32 intf_type, u32 flags)
716 {
717         intf->type = intf_type;
718         intf->flags = flags;
719         INIT_LIST_HEAD(&intf->links);
720
721         media_gobj_create(mdev, gobj_type, &intf->graph_obj);
722 }
723
724 /* Functions related to the media interface via device nodes */
725
726 struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
727                                                 u32 type, u32 flags,
728                                                 u32 major, u32 minor)
729 {
730         struct media_intf_devnode *devnode;
731
732         devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
733         if (!devnode)
734                 return NULL;
735
736         devnode->major = major;
737         devnode->minor = minor;
738
739         media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
740                              type, flags);
741
742         return devnode;
743 }
744 EXPORT_SYMBOL_GPL(media_devnode_create);
745
746 void media_devnode_remove(struct media_intf_devnode *devnode)
747 {
748         media_remove_intf_links(&devnode->intf);
749         media_gobj_destroy(&devnode->intf.graph_obj);
750         kfree(devnode);
751 }
752 EXPORT_SYMBOL_GPL(media_devnode_remove);
753
754 struct media_link *media_create_intf_link(struct media_entity *entity,
755                                             struct media_interface *intf,
756                                             u32 flags)
757 {
758         struct media_link *link;
759
760         link = media_add_link(&intf->links);
761         if (link == NULL)
762                 return NULL;
763
764         link->intf = intf;
765         link->entity = entity;
766         link->flags = flags | MEDIA_LNK_FL_INTERFACE_LINK;
767
768         /* Initialize graph object embedded at the new link */
769         media_gobj_create(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
770                         &link->graph_obj);
771
772         return link;
773 }
774 EXPORT_SYMBOL_GPL(media_create_intf_link);
775
776 void __media_remove_intf_link(struct media_link *link)
777 {
778         list_del(&link->list);
779         media_gobj_destroy(&link->graph_obj);
780         kfree(link);
781 }
782 EXPORT_SYMBOL_GPL(__media_remove_intf_link);
783
784 void media_remove_intf_link(struct media_link *link)
785 {
786         struct media_device *mdev = link->graph_obj.mdev;
787
788         /* Do nothing if the intf is not registered. */
789         if (mdev == NULL)
790                 return;
791
792         spin_lock(&mdev->lock);
793         __media_remove_intf_link(link);
794         spin_unlock(&mdev->lock);
795 }
796 EXPORT_SYMBOL_GPL(media_remove_intf_link);
797
798 void __media_remove_intf_links(struct media_interface *intf)
799 {
800         struct media_link *link, *tmp;
801
802         list_for_each_entry_safe(link, tmp, &intf->links, list)
803                 __media_remove_intf_link(link);
804
805 }
806 EXPORT_SYMBOL_GPL(__media_remove_intf_links);
807
808 void media_remove_intf_links(struct media_interface *intf)
809 {
810         struct media_device *mdev = intf->graph_obj.mdev;
811
812         /* Do nothing if the intf is not registered. */
813         if (mdev == NULL)
814                 return;
815
816         spin_lock(&mdev->lock);
817         __media_remove_intf_links(intf);
818         spin_unlock(&mdev->lock);
819 }
820 EXPORT_SYMBOL_GPL(media_remove_intf_links);