blob: a2d28162213eac7c9754587e351c43eea5da112f [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
Sakari Ailusc8d54cd2015-12-16 11:44:32 -020073__must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
74 int idx_max)
75{
Sakari Ailus030e89e2015-12-16 11:32:36 -020076 ent_enum->bmap = kcalloc(DIV_ROUND_UP(idx_max, BITS_PER_LONG),
77 sizeof(long), GFP_KERNEL);
78 if (!ent_enum->bmap)
79 return -ENOMEM;
Sakari Ailusc8d54cd2015-12-16 11:44:32 -020080
81 bitmap_zero(ent_enum->bmap, idx_max);
82 ent_enum->idx_max = idx_max;
83
84 return 0;
85}
86EXPORT_SYMBOL_GPL(__media_entity_enum_init);
87
Sakari Ailusc8d54cd2015-12-16 11:44:32 -020088void media_entity_enum_cleanup(struct media_entity_enum *ent_enum)
89{
Sakari Ailus030e89e2015-12-16 11:32:36 -020090 kfree(ent_enum->bmap);
Sakari Ailusc8d54cd2015-12-16 11:44:32 -020091}
92EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
93
94/**
Mauro Carvalho Chehab1fc25d32015-12-11 12:14:58 -020095 * dev_dbg_obj - Prints in debug mode a change on some object
96 *
97 * @event_name: Name of the event to report. Could be __func__
98 * @gobj: Pointer to the object
99 *
100 * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it
101 * won't produce any code.
102 */
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300103static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj)
104{
105#if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
106 switch (media_type(gobj)) {
107 case MEDIA_GRAPH_ENTITY:
108 dev_dbg(gobj->mdev->dev,
109 "%s: id 0x%08x entity#%d: '%s'\n",
110 event_name, gobj->id, media_localid(gobj),
111 gobj_to_entity(gobj)->name);
112 break;
113 case MEDIA_GRAPH_LINK:
114 {
115 struct media_link *link = gobj_to_link(gobj);
116
117 dev_dbg(gobj->mdev->dev,
Mauro Carvalho Chehab3c0e2662015-08-21 08:45:34 -0300118 "%s: id 0x%08x link#%d: %s#%d ==> %s#%d\n",
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300119 event_name, gobj->id, media_localid(gobj),
120
Mauro Carvalho Chehab3c0e2662015-08-21 08:45:34 -0300121 gobj_type(media_type(link->gobj0)),
122 media_localid(link->gobj0),
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300123
Mauro Carvalho Chehab3c0e2662015-08-21 08:45:34 -0300124 gobj_type(media_type(link->gobj1)),
125 media_localid(link->gobj1));
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300126 break;
127 }
128 case MEDIA_GRAPH_PAD:
129 {
130 struct media_pad *pad = gobj_to_pad(gobj);
131
132 dev_dbg(gobj->mdev->dev,
Mauro Carvalho Chehab6c24d462015-08-21 18:26:42 -0300133 "%s: id 0x%08x %s%spad#%d: '%s':%d\n",
134 event_name, gobj->id,
135 pad->flags & MEDIA_PAD_FL_SINK ? " sink " : "",
136 pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
137 media_localid(gobj),
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300138 pad->entity->name, pad->index);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300139 break;
140 }
141 case MEDIA_GRAPH_INTF_DEVNODE:
142 {
143 struct media_interface *intf = gobj_to_intf(gobj);
144 struct media_intf_devnode *devnode = intf_to_devnode(intf);
145
146 dev_dbg(gobj->mdev->dev,
147 "%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
148 event_name, gobj->id, media_localid(gobj),
149 intf_type(intf),
150 devnode->major, devnode->minor);
151 break;
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300152 }
153 }
154#endif
155}
156
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200157void media_gobj_create(struct media_device *mdev,
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300158 enum media_gobj_type type,
159 struct media_gobj *gobj)
160{
Mauro Carvalho Chehab8f6d3682015-08-19 20:18:35 -0300161 BUG_ON(!mdev);
162
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300163 gobj->mdev = mdev;
164
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300165 /* Create a per-type unique object ID */
166 switch (type) {
167 case MEDIA_GRAPH_ENTITY:
168 gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
Mauro Carvalho Chehab05bfa9f2015-08-23 07:51:33 -0300169 list_add_tail(&gobj->list, &mdev->entities);
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300170 break;
Mauro Carvalho Chehab18710dc2015-08-14 12:50:08 -0300171 case MEDIA_GRAPH_PAD:
172 gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300173 list_add_tail(&gobj->list, &mdev->pads);
Mauro Carvalho Chehab18710dc2015-08-14 12:50:08 -0300174 break;
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300175 case MEDIA_GRAPH_LINK:
176 gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300177 list_add_tail(&gobj->list, &mdev->links);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300178 break;
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300179 case MEDIA_GRAPH_INTF_DEVNODE:
180 gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300181 list_add_tail(&gobj->list, &mdev->interfaces);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300182 break;
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300183 }
Mauro Carvalho Chehab2521fda2015-08-23 09:40:26 -0300184
185 mdev->topology_version++;
186
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300187 dev_dbg_obj(__func__, gobj);
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300188}
189
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200190void media_gobj_destroy(struct media_gobj *gobj)
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300191{
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300192 dev_dbg_obj(__func__, gobj);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300193
Mauro Carvalho Chehab2521fda2015-08-23 09:40:26 -0300194 gobj->mdev->topology_version++;
195
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300196 /* Remove the object from mdev list */
197 list_del(&gobj->list);
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300198}
199
Mauro Carvalho Chehab1fc25d32015-12-11 12:14:58 -0200200int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
201 struct media_pad *pads)
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300202{
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300203 struct media_device *mdev = entity->graph_obj.mdev;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300204 unsigned int i;
205
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300206 entity->num_pads = num_pads;
207 entity->pads = pads;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300208
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300209 if (mdev)
210 spin_lock(&mdev->lock);
211
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300212 for (i = 0; i < num_pads; i++) {
213 pads[i].entity = entity;
214 pads[i].index = i;
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300215 if (mdev)
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200216 media_gobj_create(mdev, MEDIA_GRAPH_PAD,
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300217 &entity->pads[i].graph_obj);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300218 }
219
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300220 if (mdev)
221 spin_unlock(&mdev->lock);
222
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300223 return 0;
224}
Mauro Carvalho Chehabab22e772015-12-11 07:44:40 -0200225EXPORT_SYMBOL_GPL(media_entity_pads_init);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300226
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300227/* -----------------------------------------------------------------------------
228 * Graph traversal
229 */
230
231static struct media_entity *
232media_entity_other(struct media_entity *entity, struct media_link *link)
233{
234 if (link->source->entity == entity)
235 return link->sink->entity;
236 else
237 return link->source->entity;
238}
239
240/* push an entity to traversal stack */
241static void stack_push(struct media_entity_graph *graph,
242 struct media_entity *entity)
243{
244 if (graph->top == MEDIA_ENTITY_ENUM_MAX_DEPTH - 1) {
245 WARN_ON(1);
246 return;
247 }
248 graph->top++;
Javier Martinez Canillas313895f2015-12-11 15:16:36 -0200249 graph->stack[graph->top].link = entity->links.next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300250 graph->stack[graph->top].entity = entity;
251}
252
253static struct media_entity *stack_pop(struct media_entity_graph *graph)
254{
255 struct media_entity *entity;
256
257 entity = graph->stack[graph->top].entity;
258 graph->top--;
259
260 return entity;
261}
262
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300263#define link_top(en) ((en)->stack[(en)->top].link)
264#define stack_top(en) ((en)->stack[(en)->top].entity)
265
Sakari Ailus0798ce42015-12-16 11:32:37 -0200266/*
267 * TODO: Get rid of this.
268 */
269#define MEDIA_ENTITY_MAX_PADS 63
270
Sakari Ailuse03d2202015-12-16 11:32:22 -0200271/**
272 * media_entity_graph_walk_init - Allocate resources for graph walk
273 * @graph: Media graph structure that will be used to walk the graph
274 * @mdev: Media device
275 *
276 * Reserve resources for graph walk in media device's current
277 * state. The memory must be released using
278 * media_entity_graph_walk_free().
279 *
280 * Returns error on failure, zero on success.
281 */
282__must_check int media_entity_graph_walk_init(
283 struct media_entity_graph *graph, struct media_device *mdev)
284{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200285 return media_entity_enum_init(&graph->ent_enum, mdev);
Sakari Ailuse03d2202015-12-16 11:32:22 -0200286}
287EXPORT_SYMBOL_GPL(media_entity_graph_walk_init);
288
289/**
290 * media_entity_graph_walk_cleanup - Release resources related to graph walking
291 * @graph: Media graph structure that was used to walk the graph
292 */
293void media_entity_graph_walk_cleanup(struct media_entity_graph *graph)
294{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200295 media_entity_enum_cleanup(&graph->ent_enum);
Sakari Ailuse03d2202015-12-16 11:32:22 -0200296}
297EXPORT_SYMBOL_GPL(media_entity_graph_walk_cleanup);
298
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300299void media_entity_graph_walk_start(struct media_entity_graph *graph,
300 struct media_entity *entity)
301{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200302 media_entity_enum_zero(&graph->ent_enum);
303 media_entity_enum_set(&graph->ent_enum, entity);
304
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300305 graph->top = 0;
306 graph->stack[graph->top].entity = NULL;
307 stack_push(graph, entity);
308}
309EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
310
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300311struct media_entity *
312media_entity_graph_walk_next(struct media_entity_graph *graph)
313{
314 if (stack_top(graph) == NULL)
315 return NULL;
316
317 /*
318 * Depth first search. Push entity to stack and continue from
319 * top of the stack until no more entities on the level can be
320 * found.
321 */
Javier Martinez Canillas313895f2015-12-11 15:16:36 -0200322 while (link_top(graph) != &stack_top(graph)->links) {
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300323 struct media_entity *entity = stack_top(graph);
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300324 struct media_link *link;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300325 struct media_entity *next;
326
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300327 link = list_entry(link_top(graph), typeof(*link), list);
328
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300329 /* The link is not enabled so we do not follow. */
330 if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300331 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300332 continue;
333 }
334
335 /* Get the entity in the other end of the link . */
336 next = media_entity_other(entity, link);
337
Laurent Pinchart5c7b25b2013-06-07 12:45:11 -0300338 /* Has the entity already been visited? */
Sakari Ailus29d8da02015-12-16 11:32:28 -0200339 if (media_entity_enum_test_and_set(&graph->ent_enum, next)) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300340 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300341 continue;
342 }
343
344 /* Push the new entity to stack and start over. */
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300345 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300346 stack_push(graph, next);
347 }
348
349 return stack_pop(graph);
350}
351EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
352
353/* -----------------------------------------------------------------------------
Laurent Pincharte02188c2010-08-25 09:00:41 -0300354 * Pipeline management
355 */
356
Sakari Ailusaf88be32012-01-11 06:25:15 -0300357__must_check int media_entity_pipeline_start(struct media_entity *entity,
358 struct media_pipeline *pipe)
Laurent Pincharte02188c2010-08-25 09:00:41 -0300359{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300360 struct media_device *mdev = entity->graph_obj.mdev;
Sakari Ailus5dd87752015-12-16 11:32:21 -0200361 struct media_entity_graph *graph = &pipe->graph;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300362 struct media_entity *entity_err = entity;
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300363 struct media_link *link;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300364 int ret;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300365
366 mutex_lock(&mdev->graph_mutex);
367
Sakari Ailus74a41332015-12-16 11:32:29 -0200368 if (!pipe->streaming_count++) {
369 ret = media_entity_graph_walk_init(&pipe->graph, mdev);
370 if (ret)
371 goto error_graph_walk_start;
Sakari Ailus106b9902015-12-16 15:32:23 +0200372 }
373
374 media_entity_graph_walk_start(&pipe->graph, entity);
Laurent Pincharte02188c2010-08-25 09:00:41 -0300375
Sakari Ailus5dd87752015-12-16 11:32:21 -0200376 while ((entity = media_entity_graph_walk_next(graph))) {
Mauro Carvalho Chehabef69ee12015-10-01 18:07:53 -0300377 DECLARE_BITMAP(active, MEDIA_ENTITY_MAX_PADS);
378 DECLARE_BITMAP(has_no_links, MEDIA_ENTITY_MAX_PADS);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300379
Laurent Pincharte02188c2010-08-25 09:00:41 -0300380 entity->stream_count++;
Sakari Ailus8aaf62b2015-11-29 17:20:02 -0200381
382 if (WARN_ON(entity->pipe && entity->pipe != pipe)) {
383 ret = -EBUSY;
384 goto error;
385 }
386
Laurent Pincharte02188c2010-08-25 09:00:41 -0300387 entity->pipe = pipe;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300388
389 /* Already streaming --- no need to check. */
390 if (entity->stream_count > 1)
391 continue;
392
393 if (!entity->ops || !entity->ops->link_validate)
394 continue;
395
Sakari Ailusde49c282013-10-13 08:00:26 -0300396 bitmap_zero(active, entity->num_pads);
397 bitmap_fill(has_no_links, entity->num_pads);
398
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300399 list_for_each_entry(link, &entity->links, list) {
Sakari Ailusde49c282013-10-13 08:00:26 -0300400 struct media_pad *pad = link->sink->entity == entity
401 ? link->sink : link->source;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300402
Sakari Ailusde49c282013-10-13 08:00:26 -0300403 /* Mark that a pad is connected by a link. */
404 bitmap_clear(has_no_links, pad->index, 1);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300405
Sakari Ailusde49c282013-10-13 08:00:26 -0300406 /*
407 * Pads that either do not need to connect or
408 * are connected through an enabled link are
409 * fine.
410 */
411 if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
412 link->flags & MEDIA_LNK_FL_ENABLED)
413 bitmap_set(active, pad->index, 1);
414
415 /*
416 * Link validation will only take place for
417 * sink ends of the link that are enabled.
418 */
419 if (link->sink != pad ||
420 !(link->flags & MEDIA_LNK_FL_ENABLED))
Sakari Ailusaf88be32012-01-11 06:25:15 -0300421 continue;
422
423 ret = entity->ops->link_validate(link);
Sakari Ailusfab9d302014-10-28 20:35:04 -0300424 if (ret < 0 && ret != -ENOIOCTLCMD) {
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300425 dev_dbg(entity->graph_obj.mdev->dev,
Sakari Ailusfab9d302014-10-28 20:35:04 -0300426 "link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
Sakari Ailus823ea2a2015-02-12 11:43:11 -0200427 link->source->entity->name,
428 link->source->index,
429 entity->name, link->sink->index, ret);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300430 goto error;
Sakari Ailusfab9d302014-10-28 20:35:04 -0300431 }
Sakari Ailusaf88be32012-01-11 06:25:15 -0300432 }
Sakari Ailusde49c282013-10-13 08:00:26 -0300433
434 /* Either no links or validated links are fine. */
435 bitmap_or(active, active, has_no_links, entity->num_pads);
436
437 if (!bitmap_full(active, entity->num_pads)) {
438 ret = -EPIPE;
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300439 dev_dbg(entity->graph_obj.mdev->dev,
Sakari Ailusfab9d302014-10-28 20:35:04 -0300440 "\"%s\":%u must be connected by an enabled link\n",
441 entity->name,
Sakari Ailus094f1ca2014-11-03 17:55:51 -0300442 (unsigned)find_first_zero_bit(
443 active, entity->num_pads));
Sakari Ailusde49c282013-10-13 08:00:26 -0300444 goto error;
445 }
Laurent Pincharte02188c2010-08-25 09:00:41 -0300446 }
447
448 mutex_unlock(&mdev->graph_mutex);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300449
450 return 0;
451
452error:
453 /*
454 * Link validation on graph failed. We revert what we did and
455 * return the error.
456 */
Sakari Ailus5dd87752015-12-16 11:32:21 -0200457 media_entity_graph_walk_start(graph, entity_err);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300458
Sakari Ailus5dd87752015-12-16 11:32:21 -0200459 while ((entity_err = media_entity_graph_walk_next(graph))) {
Sakari Ailusaf88be32012-01-11 06:25:15 -0300460 entity_err->stream_count--;
461 if (entity_err->stream_count == 0)
462 entity_err->pipe = NULL;
463
464 /*
465 * We haven't increased stream_count further than this
466 * so we quit here.
467 */
468 if (entity_err == entity)
469 break;
470 }
471
Sakari Ailus74a41332015-12-16 11:32:29 -0200472error_graph_walk_start:
473 if (!--pipe->streaming_count)
474 media_entity_graph_walk_cleanup(graph);
Sakari Ailus106b9902015-12-16 15:32:23 +0200475
Sakari Ailusaf88be32012-01-11 06:25:15 -0300476 mutex_unlock(&mdev->graph_mutex);
477
478 return ret;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300479}
480EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
481
Laurent Pincharte02188c2010-08-25 09:00:41 -0300482void media_entity_pipeline_stop(struct media_entity *entity)
483{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300484 struct media_device *mdev = entity->graph_obj.mdev;
Sakari Ailus5dd87752015-12-16 11:32:21 -0200485 struct media_entity_graph *graph = &entity->pipe->graph;
Sakari Ailus74a41332015-12-16 11:32:29 -0200486 struct media_pipeline *pipe = entity->pipe;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300487
488 mutex_lock(&mdev->graph_mutex);
489
Sakari Ailus74a41332015-12-16 11:32:29 -0200490 WARN_ON(!pipe->streaming_count);
Sakari Ailus5dd87752015-12-16 11:32:21 -0200491 media_entity_graph_walk_start(graph, entity);
Laurent Pincharte02188c2010-08-25 09:00:41 -0300492
Sakari Ailus5dd87752015-12-16 11:32:21 -0200493 while ((entity = media_entity_graph_walk_next(graph))) {
Laurent Pincharte02188c2010-08-25 09:00:41 -0300494 entity->stream_count--;
495 if (entity->stream_count == 0)
496 entity->pipe = NULL;
497 }
498
Sakari Ailus74a41332015-12-16 11:32:29 -0200499 if (!--pipe->streaming_count)
500 media_entity_graph_walk_cleanup(graph);
Sakari Ailus106b9902015-12-16 15:32:23 +0200501
Laurent Pincharte02188c2010-08-25 09:00:41 -0300502 mutex_unlock(&mdev->graph_mutex);
503}
504EXPORT_SYMBOL_GPL(media_entity_pipeline_stop);
505
506/* -----------------------------------------------------------------------------
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300507 * Module use count
508 */
509
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300510struct media_entity *media_entity_get(struct media_entity *entity)
511{
512 if (entity == NULL)
513 return NULL;
514
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300515 if (entity->graph_obj.mdev->dev &&
516 !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300517 return NULL;
518
519 return entity;
520}
521EXPORT_SYMBOL_GPL(media_entity_get);
522
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300523void media_entity_put(struct media_entity *entity)
524{
525 if (entity == NULL)
526 return;
527
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300528 if (entity->graph_obj.mdev->dev)
529 module_put(entity->graph_obj.mdev->dev->driver->owner);
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300530}
531EXPORT_SYMBOL_GPL(media_entity_put);
532
533/* -----------------------------------------------------------------------------
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300534 * Links management
535 */
536
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300537static struct media_link *media_add_link(struct list_head *head)
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300538{
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300539 struct media_link *link;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300540
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300541 link = kzalloc(sizeof(*link), GFP_KERNEL);
542 if (link == NULL)
543 return NULL;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300544
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300545 list_add_tail(&link->list, head);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300546
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300547 return link;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300548}
549
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300550static void __media_entity_remove_link(struct media_entity *entity,
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200551 struct media_link *link)
552{
553 struct media_link *rlink, *tmp;
554 struct media_entity *remote;
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200555
556 if (link->source->entity == entity)
557 remote = link->sink->entity;
558 else
559 remote = link->source->entity;
560
561 list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
Mauro Carvalho Chehab58f69ee2015-12-11 11:25:23 -0200562 if (rlink != link->reverse)
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200563 continue;
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200564
565 if (link->source->entity == entity)
566 remote->num_backlinks--;
567
568 /* Remove the remote link */
569 list_del(&rlink->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200570 media_gobj_destroy(&rlink->graph_obj);
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200571 kfree(rlink);
572
573 if (--remote->num_links == 0)
574 break;
575 }
576 list_del(&link->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200577 media_gobj_destroy(&link->graph_obj);
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200578 kfree(link);
579}
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300580
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300581int
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300582media_create_pad_link(struct media_entity *source, u16 source_pad,
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300583 struct media_entity *sink, u16 sink_pad, u32 flags)
584{
585 struct media_link *link;
586 struct media_link *backlink;
587
588 BUG_ON(source == NULL || sink == NULL);
589 BUG_ON(source_pad >= source->num_pads);
590 BUG_ON(sink_pad >= sink->num_pads);
591
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300592 link = media_add_link(&source->links);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300593 if (link == NULL)
594 return -ENOMEM;
595
596 link->source = &source->pads[source_pad];
597 link->sink = &sink->pads[sink_pad];
Mauro Carvalho Chehab82ae2a52015-12-11 18:09:13 -0200598 link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300599
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300600 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200601 media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300602 &link->graph_obj);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300603
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300604 /* Create the backlink. Backlinks are used to help graph traversal and
605 * are not reported to userspace.
606 */
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300607 backlink = media_add_link(&sink->links);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300608 if (backlink == NULL) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300609 __media_entity_remove_link(source, link);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300610 return -ENOMEM;
611 }
612
613 backlink->source = &source->pads[source_pad];
614 backlink->sink = &sink->pads[sink_pad];
615 backlink->flags = flags;
Mauro Carvalho Chehab39d1ebc62015-08-30 09:53:57 -0300616 backlink->is_backlink = true;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300617
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300618 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200619 media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300620 &backlink->graph_obj);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300621
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300622 link->reverse = backlink;
623 backlink->reverse = link;
624
625 sink->num_backlinks++;
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300626 sink->num_links++;
627 source->num_links++;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300628
629 return 0;
630}
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300631EXPORT_SYMBOL_GPL(media_create_pad_link);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300632
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300633void __media_entity_remove_links(struct media_entity *entity)
634{
635 struct media_link *link, *tmp;
636
637 list_for_each_entry_safe(link, tmp, &entity->links, list)
638 __media_entity_remove_link(entity, link);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300639
640 entity->num_links = 0;
641 entity->num_backlinks = 0;
642}
643EXPORT_SYMBOL_GPL(__media_entity_remove_links);
644
645void media_entity_remove_links(struct media_entity *entity)
646{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200647 struct media_device *mdev = entity->graph_obj.mdev;
648
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300649 /* Do nothing if the entity is not registered. */
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200650 if (mdev == NULL)
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300651 return;
652
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200653 spin_lock(&mdev->lock);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300654 __media_entity_remove_links(entity);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200655 spin_unlock(&mdev->lock);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300656}
657EXPORT_SYMBOL_GPL(media_entity_remove_links);
658
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300659static int __media_entity_setup_link_notify(struct media_link *link, u32 flags)
660{
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300661 int ret;
662
663 /* Notify both entities. */
664 ret = media_entity_call(link->source->entity, link_setup,
665 link->source, link->sink, flags);
666 if (ret < 0 && ret != -ENOIOCTLCMD)
667 return ret;
668
669 ret = media_entity_call(link->sink->entity, link_setup,
670 link->sink, link->source, flags);
671 if (ret < 0 && ret != -ENOIOCTLCMD) {
672 media_entity_call(link->source->entity, link_setup,
673 link->source, link->sink, link->flags);
674 return ret;
675 }
676
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300677 link->flags = flags;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300678 link->reverse->flags = link->flags;
679
680 return 0;
681}
682
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300683int __media_entity_setup_link(struct media_link *link, u32 flags)
684{
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300685 const u32 mask = MEDIA_LNK_FL_ENABLED;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300686 struct media_device *mdev;
687 struct media_entity *source, *sink;
688 int ret = -EBUSY;
689
690 if (link == NULL)
691 return -EINVAL;
692
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300693 /* The non-modifiable link flags must not be modified. */
694 if ((link->flags & ~mask) != (flags & ~mask))
695 return -EINVAL;
696
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300697 if (link->flags & MEDIA_LNK_FL_IMMUTABLE)
698 return link->flags == flags ? 0 : -EINVAL;
699
700 if (link->flags == flags)
701 return 0;
702
703 source = link->source->entity;
704 sink = link->sink->entity;
705
Laurent Pincharte02188c2010-08-25 09:00:41 -0300706 if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) &&
707 (source->stream_count || sink->stream_count))
708 return -EBUSY;
709
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300710 mdev = source->graph_obj.mdev;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300711
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -0300712 if (mdev->link_notify) {
713 ret = mdev->link_notify(link, flags,
714 MEDIA_DEV_NOTIFY_PRE_LINK_CH);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300715 if (ret < 0)
716 return ret;
717 }
718
719 ret = __media_entity_setup_link_notify(link, flags);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300720
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -0300721 if (mdev->link_notify)
722 mdev->link_notify(link, flags, MEDIA_DEV_NOTIFY_POST_LINK_CH);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300723
724 return ret;
725}
726
727int media_entity_setup_link(struct media_link *link, u32 flags)
728{
729 int ret;
730
Mauro Carvalho Chehab5c883ed2015-12-15 07:58:18 -0200731 mutex_lock(&link->graph_obj.mdev->graph_mutex);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300732 ret = __media_entity_setup_link(link, flags);
Mauro Carvalho Chehab5c883ed2015-12-15 07:58:18 -0200733 mutex_unlock(&link->graph_obj.mdev->graph_mutex);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300734
735 return ret;
736}
737EXPORT_SYMBOL_GPL(media_entity_setup_link);
738
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300739struct media_link *
740media_entity_find_link(struct media_pad *source, struct media_pad *sink)
741{
742 struct media_link *link;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300743
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300744 list_for_each_entry(link, &source->entity->links, list) {
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300745 if (link->source->entity == source->entity &&
746 link->source->index == source->index &&
747 link->sink->entity == sink->entity &&
748 link->sink->index == sink->index)
749 return link;
750 }
751
752 return NULL;
753}
754EXPORT_SYMBOL_GPL(media_entity_find_link);
755
Andrzej Hajda1bddf1b2013-06-03 05:16:13 -0300756struct media_pad *media_entity_remote_pad(struct media_pad *pad)
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300757{
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300758 struct media_link *link;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300759
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300760 list_for_each_entry(link, &pad->entity->links, list) {
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300761 if (!(link->flags & MEDIA_LNK_FL_ENABLED))
762 continue;
763
764 if (link->source == pad)
765 return link->sink;
766
767 if (link->sink == pad)
768 return link->source;
769 }
770
771 return NULL;
772
773}
Andrzej Hajda1bddf1b2013-06-03 05:16:13 -0300774EXPORT_SYMBOL_GPL(media_entity_remote_pad);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300775
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300776static void media_interface_init(struct media_device *mdev,
777 struct media_interface *intf,
778 u32 gobj_type,
779 u32 intf_type, u32 flags)
780{
781 intf->type = intf_type;
782 intf->flags = flags;
783 INIT_LIST_HEAD(&intf->links);
784
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200785 media_gobj_create(mdev, gobj_type, &intf->graph_obj);
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300786}
787
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300788/* Functions related to the media interface via device nodes */
789
790struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
791 u32 type, u32 flags,
Mauro Carvalho Chehab0b3b72df92015-09-09 08:19:25 -0300792 u32 major, u32 minor)
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300793{
794 struct media_intf_devnode *devnode;
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300795
Mauro Carvalho Chehab0b3b72df92015-09-09 08:19:25 -0300796 devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300797 if (!devnode)
798 return NULL;
799
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300800 devnode->major = major;
801 devnode->minor = minor;
802
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300803 media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
804 type, flags);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300805
806 return devnode;
807}
808EXPORT_SYMBOL_GPL(media_devnode_create);
809
810void media_devnode_remove(struct media_intf_devnode *devnode)
811{
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300812 media_remove_intf_links(&devnode->intf);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200813 media_gobj_destroy(&devnode->intf.graph_obj);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300814 kfree(devnode);
815}
816EXPORT_SYMBOL_GPL(media_devnode_remove);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300817
818struct media_link *media_create_intf_link(struct media_entity *entity,
819 struct media_interface *intf,
820 u32 flags)
821{
822 struct media_link *link;
823
824 link = media_add_link(&intf->links);
825 if (link == NULL)
826 return NULL;
827
828 link->intf = intf;
829 link->entity = entity;
Mauro Carvalho Chehab82ae2a52015-12-11 18:09:13 -0200830 link->flags = flags | MEDIA_LNK_FL_INTERFACE_LINK;
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300831
832 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200833 media_gobj_create(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300834 &link->graph_obj);
835
836 return link;
837}
838EXPORT_SYMBOL_GPL(media_create_intf_link);
839
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300840void __media_remove_intf_link(struct media_link *link)
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300841{
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300842 list_del(&link->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200843 media_gobj_destroy(&link->graph_obj);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300844 kfree(link);
845}
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300846EXPORT_SYMBOL_GPL(__media_remove_intf_link);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300847
848void media_remove_intf_link(struct media_link *link)
849{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200850 struct media_device *mdev = link->graph_obj.mdev;
851
852 /* Do nothing if the intf is not registered. */
853 if (mdev == NULL)
854 return;
855
856 spin_lock(&mdev->lock);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300857 __media_remove_intf_link(link);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200858 spin_unlock(&mdev->lock);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300859}
860EXPORT_SYMBOL_GPL(media_remove_intf_link);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300861
862void __media_remove_intf_links(struct media_interface *intf)
863{
864 struct media_link *link, *tmp;
865
866 list_for_each_entry_safe(link, tmp, &intf->links, list)
867 __media_remove_intf_link(link);
868
869}
870EXPORT_SYMBOL_GPL(__media_remove_intf_links);
871
872void media_remove_intf_links(struct media_interface *intf)
873{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200874 struct media_device *mdev = intf->graph_obj.mdev;
875
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300876 /* Do nothing if the intf is not registered. */
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200877 if (mdev == NULL)
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300878 return;
879
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200880 spin_lock(&mdev->lock);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300881 __media_remove_intf_links(intf);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200882 spin_unlock(&mdev->lock);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300883}
884EXPORT_SYMBOL_GPL(media_remove_intf_links);