blob: 3cad525c2ac1feefe5191e4c32794afb27effd3a [file] [log] [blame]
Laurent Pinchart53e269c2009-12-09 08:40:00 -03001/*
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
Laurent Pinchart5c7b25b2013-06-07 12:45:11 -030023#include <linux/bitmap.h>
Laurent Pinchart53e269c2009-12-09 08:40:00 -030024#include <linux/module.h>
25#include <linux/slab.h>
26#include <media/media-entity.h>
Laurent Pinchart503c3d822010-03-07 15:04:59 -030027#include <media/media-device.h>
Laurent Pinchart53e269c2009-12-09 08:40:00 -030028
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -030029static 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";
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -030038 case MEDIA_GRAPH_INTF_DEVNODE:
39 return "intf-devnode";
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -030040 default:
41 return "unknown";
42 }
43}
44
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -030045static 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
Mauro Carvalho Chehab1fc25d32015-12-11 12:14:58 -020073/**
Sakari Ailusc8d54cd2015-12-16 11:44:32 -020074 * __media_entity_enum_init - Initialise an entity enumeration
75 *
76 * @ent_enum: Entity enumeration to be initialised
77 * @idx_max: Maximum number of entities in the enumeration
78 *
79 * Returns zero on success or a negative error code.
80 */
81__must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
82 int idx_max)
83{
84 if (idx_max > MEDIA_ENTITY_ENUM_MAX_ID) {
85 ent_enum->bmap = kcalloc(DIV_ROUND_UP(idx_max, BITS_PER_LONG),
86 sizeof(long), GFP_KERNEL);
87 if (!ent_enum->bmap)
88 return -ENOMEM;
89 } else {
90 ent_enum->bmap = ent_enum->prealloc_bmap;
91 }
92
93 bitmap_zero(ent_enum->bmap, idx_max);
94 ent_enum->idx_max = idx_max;
95
96 return 0;
97}
98EXPORT_SYMBOL_GPL(__media_entity_enum_init);
99
100/**
101 * media_entity_enum_cleanup - Release resources of an entity enumeration
102 *
103 * @e: Entity enumeration to be released
104 */
105void media_entity_enum_cleanup(struct media_entity_enum *ent_enum)
106{
107 if (ent_enum->bmap != ent_enum->prealloc_bmap)
108 kfree(ent_enum->bmap);
109 ent_enum->bmap = NULL;
110}
111EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
112
113/**
Mauro Carvalho Chehab1fc25d32015-12-11 12:14:58 -0200114 * dev_dbg_obj - Prints in debug mode a change on some object
115 *
116 * @event_name: Name of the event to report. Could be __func__
117 * @gobj: Pointer to the object
118 *
119 * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
120 * won't produce any code.
121 */
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300122static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj)
123{
124#if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
125 switch (media_type(gobj)) {
126 case MEDIA_GRAPH_ENTITY:
127 dev_dbg(gobj->mdev->dev,
128 "%s: id 0x%08x entity#%d: '%s'\n",
129 event_name, gobj->id, media_localid(gobj),
130 gobj_to_entity(gobj)->name);
131 break;
132 case MEDIA_GRAPH_LINK:
133 {
134 struct media_link *link = gobj_to_link(gobj);
135
136 dev_dbg(gobj->mdev->dev,
Mauro Carvalho Chehab3c0e2662015-08-21 08:45:34 -0300137 "%s: id 0x%08x link#%d: %s#%d ==> %s#%d\n",
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300138 event_name, gobj->id, media_localid(gobj),
139
Mauro Carvalho Chehab3c0e2662015-08-21 08:45:34 -0300140 gobj_type(media_type(link->gobj0)),
141 media_localid(link->gobj0),
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300142
Mauro Carvalho Chehab3c0e2662015-08-21 08:45:34 -0300143 gobj_type(media_type(link->gobj1)),
144 media_localid(link->gobj1));
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300145 break;
146 }
147 case MEDIA_GRAPH_PAD:
148 {
149 struct media_pad *pad = gobj_to_pad(gobj);
150
151 dev_dbg(gobj->mdev->dev,
Mauro Carvalho Chehab6c24d462015-08-21 18:26:42 -0300152 "%s: id 0x%08x %s%spad#%d: '%s':%d\n",
153 event_name, gobj->id,
154 pad->flags & MEDIA_PAD_FL_SINK ? " sink " : "",
155 pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
156 media_localid(gobj),
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300157 pad->entity->name, pad->index);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300158 break;
159 }
160 case MEDIA_GRAPH_INTF_DEVNODE:
161 {
162 struct media_interface *intf = gobj_to_intf(gobj);
163 struct media_intf_devnode *devnode = intf_to_devnode(intf);
164
165 dev_dbg(gobj->mdev->dev,
166 "%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
167 event_name, gobj->id, media_localid(gobj),
168 intf_type(intf),
169 devnode->major, devnode->minor);
170 break;
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300171 }
172 }
173#endif
174}
175
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200176void media_gobj_create(struct media_device *mdev,
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300177 enum media_gobj_type type,
178 struct media_gobj *gobj)
179{
Mauro Carvalho Chehab8f6d3682015-08-19 20:18:35 -0300180 BUG_ON(!mdev);
181
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300182 gobj->mdev = mdev;
183
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300184 /* Create a per-type unique object ID */
185 switch (type) {
186 case MEDIA_GRAPH_ENTITY:
187 gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
Mauro Carvalho Chehab05bfa9f2015-08-23 07:51:33 -0300188 list_add_tail(&gobj->list, &mdev->entities);
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300189 break;
Mauro Carvalho Chehab18710dc2015-08-14 12:50:08 -0300190 case MEDIA_GRAPH_PAD:
191 gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300192 list_add_tail(&gobj->list, &mdev->pads);
Mauro Carvalho Chehab18710dc2015-08-14 12:50:08 -0300193 break;
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300194 case MEDIA_GRAPH_LINK:
195 gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300196 list_add_tail(&gobj->list, &mdev->links);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300197 break;
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300198 case MEDIA_GRAPH_INTF_DEVNODE:
199 gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300200 list_add_tail(&gobj->list, &mdev->interfaces);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300201 break;
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300202 }
Mauro Carvalho Chehab2521fda2015-08-23 09:40:26 -0300203
204 mdev->topology_version++;
205
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300206 dev_dbg_obj(__func__, gobj);
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300207}
208
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200209void media_gobj_destroy(struct media_gobj *gobj)
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300210{
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300211 dev_dbg_obj(__func__, gobj);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300212
Mauro Carvalho Chehab2521fda2015-08-23 09:40:26 -0300213 gobj->mdev->topology_version++;
214
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300215 /* Remove the object from mdev list */
216 list_del(&gobj->list);
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300217}
218
Mauro Carvalho Chehab1fc25d32015-12-11 12:14:58 -0200219int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
220 struct media_pad *pads)
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300221{
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300222 struct media_device *mdev = entity->graph_obj.mdev;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300223 unsigned int i;
224
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300225 entity->num_pads = num_pads;
226 entity->pads = pads;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300227
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300228 if (mdev)
229 spin_lock(&mdev->lock);
230
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300231 for (i = 0; i < num_pads; i++) {
232 pads[i].entity = entity;
233 pads[i].index = i;
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300234 if (mdev)
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200235 media_gobj_create(mdev, MEDIA_GRAPH_PAD,
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300236 &entity->pads[i].graph_obj);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300237 }
238
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300239 if (mdev)
240 spin_unlock(&mdev->lock);
241
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300242 return 0;
243}
Mauro Carvalho Chehabab22e772015-12-11 07:44:40 -0200244EXPORT_SYMBOL_GPL(media_entity_pads_init);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300245
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300246/* -----------------------------------------------------------------------------
247 * Graph traversal
248 */
249
250static struct media_entity *
251media_entity_other(struct media_entity *entity, struct media_link *link)
252{
253 if (link->source->entity == entity)
254 return link->sink->entity;
255 else
256 return link->source->entity;
257}
258
259/* push an entity to traversal stack */
260static void stack_push(struct media_entity_graph *graph,
261 struct media_entity *entity)
262{
263 if (graph->top == MEDIA_ENTITY_ENUM_MAX_DEPTH - 1) {
264 WARN_ON(1);
265 return;
266 }
267 graph->top++;
Javier Martinez Canillas313895f2015-12-11 15:16:36 -0200268 graph->stack[graph->top].link = entity->links.next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300269 graph->stack[graph->top].entity = entity;
270}
271
272static struct media_entity *stack_pop(struct media_entity_graph *graph)
273{
274 struct media_entity *entity;
275
276 entity = graph->stack[graph->top].entity;
277 graph->top--;
278
279 return entity;
280}
281
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300282#define link_top(en) ((en)->stack[(en)->top].link)
283#define stack_top(en) ((en)->stack[(en)->top].entity)
284
Sakari Ailuse03d2202015-12-16 11:32:22 -0200285/**
286 * media_entity_graph_walk_init - Allocate resources for graph walk
287 * @graph: Media graph structure that will be used to walk the graph
288 * @mdev: Media device
289 *
290 * Reserve resources for graph walk in media device's current
291 * state. The memory must be released using
292 * media_entity_graph_walk_free().
293 *
294 * Returns error on failure, zero on success.
295 */
296__must_check int media_entity_graph_walk_init(
297 struct media_entity_graph *graph, struct media_device *mdev)
298{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200299 return media_entity_enum_init(&graph->ent_enum, mdev);
Sakari Ailuse03d2202015-12-16 11:32:22 -0200300}
301EXPORT_SYMBOL_GPL(media_entity_graph_walk_init);
302
303/**
304 * media_entity_graph_walk_cleanup - Release resources related to graph walking
305 * @graph: Media graph structure that was used to walk the graph
306 */
307void media_entity_graph_walk_cleanup(struct media_entity_graph *graph)
308{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200309 media_entity_enum_cleanup(&graph->ent_enum);
Sakari Ailuse03d2202015-12-16 11:32:22 -0200310}
311EXPORT_SYMBOL_GPL(media_entity_graph_walk_cleanup);
312
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300313void media_entity_graph_walk_start(struct media_entity_graph *graph,
314 struct media_entity *entity)
315{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200316 media_entity_enum_zero(&graph->ent_enum);
317 media_entity_enum_set(&graph->ent_enum, entity);
318
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300319 graph->top = 0;
320 graph->stack[graph->top].entity = NULL;
321 stack_push(graph, entity);
322}
323EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
324
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300325struct media_entity *
326media_entity_graph_walk_next(struct media_entity_graph *graph)
327{
328 if (stack_top(graph) == NULL)
329 return NULL;
330
331 /*
332 * Depth first search. Push entity to stack and continue from
333 * top of the stack until no more entities on the level can be
334 * found.
335 */
Javier Martinez Canillas313895f2015-12-11 15:16:36 -0200336 while (link_top(graph) != &stack_top(graph)->links) {
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300337 struct media_entity *entity = stack_top(graph);
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300338 struct media_link *link;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300339 struct media_entity *next;
340
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300341 link = list_entry(link_top(graph), typeof(*link), list);
342
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300343 /* The link is not enabled so we do not follow. */
344 if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300345 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300346 continue;
347 }
348
349 /* Get the entity in the other end of the link . */
350 next = media_entity_other(entity, link);
351
Laurent Pinchart5c7b25b2013-06-07 12:45:11 -0300352 /* Has the entity already been visited? */
Sakari Ailus29d8da02015-12-16 11:32:28 -0200353 if (media_entity_enum_test_and_set(&graph->ent_enum, next)) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300354 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300355 continue;
356 }
357
358 /* Push the new entity to stack and start over. */
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300359 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300360 stack_push(graph, next);
361 }
362
363 return stack_pop(graph);
364}
365EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
366
367/* -----------------------------------------------------------------------------
Laurent Pincharte02188c2010-08-25 09:00:41 -0300368 * Pipeline management
369 */
370
Sakari Ailusaf88be32012-01-11 06:25:15 -0300371__must_check int media_entity_pipeline_start(struct media_entity *entity,
372 struct media_pipeline *pipe)
Laurent Pincharte02188c2010-08-25 09:00:41 -0300373{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300374 struct media_device *mdev = entity->graph_obj.mdev;
Sakari Ailus5dd87752015-12-16 11:32:21 -0200375 struct media_entity_graph *graph = &pipe->graph;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300376 struct media_entity *entity_err = entity;
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300377 struct media_link *link;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300378 int ret;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300379
380 mutex_lock(&mdev->graph_mutex);
381
Sakari Ailus74a41332015-12-16 11:32:29 -0200382 if (!pipe->streaming_count++) {
383 ret = media_entity_graph_walk_init(&pipe->graph, mdev);
384 if (ret)
385 goto error_graph_walk_start;
Sakari Ailus106b9902015-12-16 15:32:23 +0200386 }
387
388 media_entity_graph_walk_start(&pipe->graph, entity);
Laurent Pincharte02188c2010-08-25 09:00:41 -0300389
Sakari Ailus5dd87752015-12-16 11:32:21 -0200390 while ((entity = media_entity_graph_walk_next(graph))) {
Mauro Carvalho Chehabef69ee12015-10-01 18:07:53 -0300391 DECLARE_BITMAP(active, MEDIA_ENTITY_MAX_PADS);
392 DECLARE_BITMAP(has_no_links, MEDIA_ENTITY_MAX_PADS);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300393
Laurent Pincharte02188c2010-08-25 09:00:41 -0300394 entity->stream_count++;
Sakari Ailus8aaf62b2015-11-29 17:20:02 -0200395
396 if (WARN_ON(entity->pipe && entity->pipe != pipe)) {
397 ret = -EBUSY;
398 goto error;
399 }
400
Laurent Pincharte02188c2010-08-25 09:00:41 -0300401 entity->pipe = pipe;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300402
403 /* Already streaming --- no need to check. */
404 if (entity->stream_count > 1)
405 continue;
406
407 if (!entity->ops || !entity->ops->link_validate)
408 continue;
409
Sakari Ailusde49c282013-10-13 08:00:26 -0300410 bitmap_zero(active, entity->num_pads);
411 bitmap_fill(has_no_links, entity->num_pads);
412
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300413 list_for_each_entry(link, &entity->links, list) {
Sakari Ailusde49c282013-10-13 08:00:26 -0300414 struct media_pad *pad = link->sink->entity == entity
415 ? link->sink : link->source;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300416
Sakari Ailusde49c282013-10-13 08:00:26 -0300417 /* Mark that a pad is connected by a link. */
418 bitmap_clear(has_no_links, pad->index, 1);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300419
Sakari Ailusde49c282013-10-13 08:00:26 -0300420 /*
421 * Pads that either do not need to connect or
422 * are connected through an enabled link are
423 * fine.
424 */
425 if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
426 link->flags & MEDIA_LNK_FL_ENABLED)
427 bitmap_set(active, pad->index, 1);
428
429 /*
430 * Link validation will only take place for
431 * sink ends of the link that are enabled.
432 */
433 if (link->sink != pad ||
434 !(link->flags & MEDIA_LNK_FL_ENABLED))
Sakari Ailusaf88be32012-01-11 06:25:15 -0300435 continue;
436
437 ret = entity->ops->link_validate(link);
Sakari Ailusfab9d302014-10-28 20:35:04 -0300438 if (ret < 0 && ret != -ENOIOCTLCMD) {
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300439 dev_dbg(entity->graph_obj.mdev->dev,
Sakari Ailusfab9d302014-10-28 20:35:04 -0300440 "link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
Sakari Ailus823ea2a2015-02-12 11:43:11 -0200441 link->source->entity->name,
442 link->source->index,
443 entity->name, link->sink->index, ret);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300444 goto error;
Sakari Ailusfab9d302014-10-28 20:35:04 -0300445 }
Sakari Ailusaf88be32012-01-11 06:25:15 -0300446 }
Sakari Ailusde49c282013-10-13 08:00:26 -0300447
448 /* Either no links or validated links are fine. */
449 bitmap_or(active, active, has_no_links, entity->num_pads);
450
451 if (!bitmap_full(active, entity->num_pads)) {
452 ret = -EPIPE;
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300453 dev_dbg(entity->graph_obj.mdev->dev,
Sakari Ailusfab9d302014-10-28 20:35:04 -0300454 "\"%s\":%u must be connected by an enabled link\n",
455 entity->name,
Sakari Ailus094f1ca2014-11-03 17:55:51 -0300456 (unsigned)find_first_zero_bit(
457 active, entity->num_pads));
Sakari Ailusde49c282013-10-13 08:00:26 -0300458 goto error;
459 }
Laurent Pincharte02188c2010-08-25 09:00:41 -0300460 }
461
462 mutex_unlock(&mdev->graph_mutex);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300463
464 return 0;
465
466error:
467 /*
468 * Link validation on graph failed. We revert what we did and
469 * return the error.
470 */
Sakari Ailus5dd87752015-12-16 11:32:21 -0200471 media_entity_graph_walk_start(graph, entity_err);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300472
Sakari Ailus5dd87752015-12-16 11:32:21 -0200473 while ((entity_err = media_entity_graph_walk_next(graph))) {
Sakari Ailusaf88be32012-01-11 06:25:15 -0300474 entity_err->stream_count--;
475 if (entity_err->stream_count == 0)
476 entity_err->pipe = NULL;
477
478 /*
479 * We haven't increased stream_count further than this
480 * so we quit here.
481 */
482 if (entity_err == entity)
483 break;
484 }
485
Sakari Ailus74a41332015-12-16 11:32:29 -0200486error_graph_walk_start:
487 if (!--pipe->streaming_count)
488 media_entity_graph_walk_cleanup(graph);
Sakari Ailus106b9902015-12-16 15:32:23 +0200489
Sakari Ailusaf88be32012-01-11 06:25:15 -0300490 mutex_unlock(&mdev->graph_mutex);
491
492 return ret;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300493}
494EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
495
Laurent Pincharte02188c2010-08-25 09:00:41 -0300496void media_entity_pipeline_stop(struct media_entity *entity)
497{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300498 struct media_device *mdev = entity->graph_obj.mdev;
Sakari Ailus5dd87752015-12-16 11:32:21 -0200499 struct media_entity_graph *graph = &entity->pipe->graph;
Sakari Ailus74a41332015-12-16 11:32:29 -0200500 struct media_pipeline *pipe = entity->pipe;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300501
502 mutex_lock(&mdev->graph_mutex);
503
Sakari Ailus74a41332015-12-16 11:32:29 -0200504 WARN_ON(!pipe->streaming_count);
Sakari Ailus5dd87752015-12-16 11:32:21 -0200505 media_entity_graph_walk_start(graph, entity);
Laurent Pincharte02188c2010-08-25 09:00:41 -0300506
Sakari Ailus5dd87752015-12-16 11:32:21 -0200507 while ((entity = media_entity_graph_walk_next(graph))) {
Laurent Pincharte02188c2010-08-25 09:00:41 -0300508 entity->stream_count--;
509 if (entity->stream_count == 0)
510 entity->pipe = NULL;
511 }
512
Sakari Ailus74a41332015-12-16 11:32:29 -0200513 if (!--pipe->streaming_count)
514 media_entity_graph_walk_cleanup(graph);
Sakari Ailus106b9902015-12-16 15:32:23 +0200515
Laurent Pincharte02188c2010-08-25 09:00:41 -0300516 mutex_unlock(&mdev->graph_mutex);
517}
518EXPORT_SYMBOL_GPL(media_entity_pipeline_stop);
519
520/* -----------------------------------------------------------------------------
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300521 * Module use count
522 */
523
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300524struct media_entity *media_entity_get(struct media_entity *entity)
525{
526 if (entity == NULL)
527 return NULL;
528
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300529 if (entity->graph_obj.mdev->dev &&
530 !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300531 return NULL;
532
533 return entity;
534}
535EXPORT_SYMBOL_GPL(media_entity_get);
536
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300537void media_entity_put(struct media_entity *entity)
538{
539 if (entity == NULL)
540 return;
541
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300542 if (entity->graph_obj.mdev->dev)
543 module_put(entity->graph_obj.mdev->dev->driver->owner);
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300544}
545EXPORT_SYMBOL_GPL(media_entity_put);
546
547/* -----------------------------------------------------------------------------
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300548 * Links management
549 */
550
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300551static struct media_link *media_add_link(struct list_head *head)
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300552{
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300553 struct media_link *link;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300554
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300555 link = kzalloc(sizeof(*link), GFP_KERNEL);
556 if (link == NULL)
557 return NULL;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300558
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300559 list_add_tail(&link->list, head);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300560
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300561 return link;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300562}
563
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300564static void __media_entity_remove_link(struct media_entity *entity,
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200565 struct media_link *link)
566{
567 struct media_link *rlink, *tmp;
568 struct media_entity *remote;
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200569
570 if (link->source->entity == entity)
571 remote = link->sink->entity;
572 else
573 remote = link->source->entity;
574
575 list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
Mauro Carvalho Chehab58f69ee2015-12-11 11:25:23 -0200576 if (rlink != link->reverse)
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200577 continue;
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200578
579 if (link->source->entity == entity)
580 remote->num_backlinks--;
581
582 /* Remove the remote link */
583 list_del(&rlink->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200584 media_gobj_destroy(&rlink->graph_obj);
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200585 kfree(rlink);
586
587 if (--remote->num_links == 0)
588 break;
589 }
590 list_del(&link->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200591 media_gobj_destroy(&link->graph_obj);
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200592 kfree(link);
593}
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300594
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300595int
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300596media_create_pad_link(struct media_entity *source, u16 source_pad,
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300597 struct media_entity *sink, u16 sink_pad, u32 flags)
598{
599 struct media_link *link;
600 struct media_link *backlink;
601
602 BUG_ON(source == NULL || sink == NULL);
603 BUG_ON(source_pad >= source->num_pads);
604 BUG_ON(sink_pad >= sink->num_pads);
605
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300606 link = media_add_link(&source->links);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300607 if (link == NULL)
608 return -ENOMEM;
609
610 link->source = &source->pads[source_pad];
611 link->sink = &sink->pads[sink_pad];
Mauro Carvalho Chehab82ae2a52015-12-11 18:09:13 -0200612 link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300613
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300614 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200615 media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300616 &link->graph_obj);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300617
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300618 /* Create the backlink. Backlinks are used to help graph traversal and
619 * are not reported to userspace.
620 */
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300621 backlink = media_add_link(&sink->links);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300622 if (backlink == NULL) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300623 __media_entity_remove_link(source, link);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300624 return -ENOMEM;
625 }
626
627 backlink->source = &source->pads[source_pad];
628 backlink->sink = &sink->pads[sink_pad];
629 backlink->flags = flags;
Mauro Carvalho Chehab39d1ebc62015-08-30 09:53:57 -0300630 backlink->is_backlink = true;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300631
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300632 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200633 media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300634 &backlink->graph_obj);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300635
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300636 link->reverse = backlink;
637 backlink->reverse = link;
638
639 sink->num_backlinks++;
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300640 sink->num_links++;
641 source->num_links++;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300642
643 return 0;
644}
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300645EXPORT_SYMBOL_GPL(media_create_pad_link);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300646
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300647void __media_entity_remove_links(struct media_entity *entity)
648{
649 struct media_link *link, *tmp;
650
651 list_for_each_entry_safe(link, tmp, &entity->links, list)
652 __media_entity_remove_link(entity, link);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300653
654 entity->num_links = 0;
655 entity->num_backlinks = 0;
656}
657EXPORT_SYMBOL_GPL(__media_entity_remove_links);
658
659void media_entity_remove_links(struct media_entity *entity)
660{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200661 struct media_device *mdev = entity->graph_obj.mdev;
662
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300663 /* Do nothing if the entity is not registered. */
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200664 if (mdev == NULL)
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300665 return;
666
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200667 spin_lock(&mdev->lock);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300668 __media_entity_remove_links(entity);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200669 spin_unlock(&mdev->lock);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300670}
671EXPORT_SYMBOL_GPL(media_entity_remove_links);
672
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300673static int __media_entity_setup_link_notify(struct media_link *link, u32 flags)
674{
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300675 int ret;
676
677 /* Notify both entities. */
678 ret = media_entity_call(link->source->entity, link_setup,
679 link->source, link->sink, flags);
680 if (ret < 0 && ret != -ENOIOCTLCMD)
681 return ret;
682
683 ret = media_entity_call(link->sink->entity, link_setup,
684 link->sink, link->source, flags);
685 if (ret < 0 && ret != -ENOIOCTLCMD) {
686 media_entity_call(link->source->entity, link_setup,
687 link->source, link->sink, link->flags);
688 return ret;
689 }
690
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300691 link->flags = flags;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300692 link->reverse->flags = link->flags;
693
694 return 0;
695}
696
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300697int __media_entity_setup_link(struct media_link *link, u32 flags)
698{
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300699 const u32 mask = MEDIA_LNK_FL_ENABLED;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300700 struct media_device *mdev;
701 struct media_entity *source, *sink;
702 int ret = -EBUSY;
703
704 if (link == NULL)
705 return -EINVAL;
706
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300707 /* The non-modifiable link flags must not be modified. */
708 if ((link->flags & ~mask) != (flags & ~mask))
709 return -EINVAL;
710
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300711 if (link->flags & MEDIA_LNK_FL_IMMUTABLE)
712 return link->flags == flags ? 0 : -EINVAL;
713
714 if (link->flags == flags)
715 return 0;
716
717 source = link->source->entity;
718 sink = link->sink->entity;
719
Laurent Pincharte02188c2010-08-25 09:00:41 -0300720 if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) &&
721 (source->stream_count || sink->stream_count))
722 return -EBUSY;
723
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300724 mdev = source->graph_obj.mdev;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300725
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -0300726 if (mdev->link_notify) {
727 ret = mdev->link_notify(link, flags,
728 MEDIA_DEV_NOTIFY_PRE_LINK_CH);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300729 if (ret < 0)
730 return ret;
731 }
732
733 ret = __media_entity_setup_link_notify(link, flags);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300734
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -0300735 if (mdev->link_notify)
736 mdev->link_notify(link, flags, MEDIA_DEV_NOTIFY_POST_LINK_CH);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300737
738 return ret;
739}
740
741int media_entity_setup_link(struct media_link *link, u32 flags)
742{
743 int ret;
744
Mauro Carvalho Chehab5c883ed2015-12-15 07:58:18 -0200745 mutex_lock(&link->graph_obj.mdev->graph_mutex);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300746 ret = __media_entity_setup_link(link, flags);
Mauro Carvalho Chehab5c883ed2015-12-15 07:58:18 -0200747 mutex_unlock(&link->graph_obj.mdev->graph_mutex);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300748
749 return ret;
750}
751EXPORT_SYMBOL_GPL(media_entity_setup_link);
752
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300753struct media_link *
754media_entity_find_link(struct media_pad *source, struct media_pad *sink)
755{
756 struct media_link *link;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300757
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300758 list_for_each_entry(link, &source->entity->links, list) {
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300759 if (link->source->entity == source->entity &&
760 link->source->index == source->index &&
761 link->sink->entity == sink->entity &&
762 link->sink->index == sink->index)
763 return link;
764 }
765
766 return NULL;
767}
768EXPORT_SYMBOL_GPL(media_entity_find_link);
769
Andrzej Hajda1bddf1b2013-06-03 05:16:13 -0300770struct media_pad *media_entity_remote_pad(struct media_pad *pad)
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300771{
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300772 struct media_link *link;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300773
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300774 list_for_each_entry(link, &pad->entity->links, list) {
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300775 if (!(link->flags & MEDIA_LNK_FL_ENABLED))
776 continue;
777
778 if (link->source == pad)
779 return link->sink;
780
781 if (link->sink == pad)
782 return link->source;
783 }
784
785 return NULL;
786
787}
Andrzej Hajda1bddf1b2013-06-03 05:16:13 -0300788EXPORT_SYMBOL_GPL(media_entity_remote_pad);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300789
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300790static void media_interface_init(struct media_device *mdev,
791 struct media_interface *intf,
792 u32 gobj_type,
793 u32 intf_type, u32 flags)
794{
795 intf->type = intf_type;
796 intf->flags = flags;
797 INIT_LIST_HEAD(&intf->links);
798
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200799 media_gobj_create(mdev, gobj_type, &intf->graph_obj);
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300800}
801
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300802/* Functions related to the media interface via device nodes */
803
804struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
805 u32 type, u32 flags,
Mauro Carvalho Chehab0b3b72df92015-09-09 08:19:25 -0300806 u32 major, u32 minor)
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300807{
808 struct media_intf_devnode *devnode;
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300809
Mauro Carvalho Chehab0b3b72df92015-09-09 08:19:25 -0300810 devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300811 if (!devnode)
812 return NULL;
813
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300814 devnode->major = major;
815 devnode->minor = minor;
816
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300817 media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
818 type, flags);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300819
820 return devnode;
821}
822EXPORT_SYMBOL_GPL(media_devnode_create);
823
824void media_devnode_remove(struct media_intf_devnode *devnode)
825{
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300826 media_remove_intf_links(&devnode->intf);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200827 media_gobj_destroy(&devnode->intf.graph_obj);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300828 kfree(devnode);
829}
830EXPORT_SYMBOL_GPL(media_devnode_remove);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300831
832struct media_link *media_create_intf_link(struct media_entity *entity,
833 struct media_interface *intf,
834 u32 flags)
835{
836 struct media_link *link;
837
838 link = media_add_link(&intf->links);
839 if (link == NULL)
840 return NULL;
841
842 link->intf = intf;
843 link->entity = entity;
Mauro Carvalho Chehab82ae2a52015-12-11 18:09:13 -0200844 link->flags = flags | MEDIA_LNK_FL_INTERFACE_LINK;
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300845
846 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200847 media_gobj_create(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300848 &link->graph_obj);
849
850 return link;
851}
852EXPORT_SYMBOL_GPL(media_create_intf_link);
853
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300854void __media_remove_intf_link(struct media_link *link)
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300855{
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300856 list_del(&link->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200857 media_gobj_destroy(&link->graph_obj);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300858 kfree(link);
859}
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300860EXPORT_SYMBOL_GPL(__media_remove_intf_link);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300861
862void media_remove_intf_link(struct media_link *link)
863{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200864 struct media_device *mdev = link->graph_obj.mdev;
865
866 /* Do nothing if the intf is not registered. */
867 if (mdev == NULL)
868 return;
869
870 spin_lock(&mdev->lock);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300871 __media_remove_intf_link(link);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200872 spin_unlock(&mdev->lock);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300873}
874EXPORT_SYMBOL_GPL(media_remove_intf_link);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300875
876void __media_remove_intf_links(struct media_interface *intf)
877{
878 struct media_link *link, *tmp;
879
880 list_for_each_entry_safe(link, tmp, &intf->links, list)
881 __media_remove_intf_link(link);
882
883}
884EXPORT_SYMBOL_GPL(__media_remove_intf_links);
885
886void media_remove_intf_links(struct media_interface *intf)
887{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200888 struct media_device *mdev = intf->graph_obj.mdev;
889
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300890 /* Do nothing if the intf is not registered. */
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200891 if (mdev == NULL)
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300892 return;
893
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200894 spin_lock(&mdev->lock);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300895 __media_remove_intf_links(intf);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200896 spin_unlock(&mdev->lock);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300897}
898EXPORT_SYMBOL_GPL(media_remove_intf_links);