blob: f63be23e6ed4714c589a942bd9718485fdeda67d [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,
Mauro Carvalho Chehab05b3b772015-12-16 14:28:01 -0200109 "%s id %u: entity '%s'\n",
110 event_name, media_id(gobj),
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300111 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 Chehab05b3b772015-12-16 14:28:01 -0200118 "%s id %u: %s link id %u ==> id %u\n",
119 event_name, media_id(gobj),
120 media_type(link->gobj0) == MEDIA_GRAPH_PAD ?
121 "data" : "interface",
122 media_id(link->gobj0),
123 media_id(link->gobj1));
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300124 break;
125 }
126 case MEDIA_GRAPH_PAD:
127 {
128 struct media_pad *pad = gobj_to_pad(gobj);
129
130 dev_dbg(gobj->mdev->dev,
Mauro Carvalho Chehab05b3b772015-12-16 14:28:01 -0200131 "%s id %u: %s%spad '%s':%d\n",
132 event_name, media_id(gobj),
133 pad->flags & MEDIA_PAD_FL_SINK ? "sink " : "",
Mauro Carvalho Chehab6c24d462015-08-21 18:26:42 -0300134 pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300135 pad->entity->name, pad->index);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300136 break;
137 }
138 case MEDIA_GRAPH_INTF_DEVNODE:
139 {
140 struct media_interface *intf = gobj_to_intf(gobj);
141 struct media_intf_devnode *devnode = intf_to_devnode(intf);
142
143 dev_dbg(gobj->mdev->dev,
Mauro Carvalho Chehab05b3b772015-12-16 14:28:01 -0200144 "%s id %u: intf_devnode %s - major: %d, minor: %d\n",
145 event_name, media_id(gobj),
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300146 intf_type(intf),
147 devnode->major, devnode->minor);
148 break;
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300149 }
150 }
151#endif
152}
153
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200154void media_gobj_create(struct media_device *mdev,
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300155 enum media_gobj_type type,
156 struct media_gobj *gobj)
157{
Mauro Carvalho Chehab8f6d3682015-08-19 20:18:35 -0300158 BUG_ON(!mdev);
159
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300160 gobj->mdev = mdev;
161
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300162 /* Create a per-type unique object ID */
Mauro Carvalho Chehab05b3b772015-12-16 14:28:01 -0200163 gobj->id = media_gobj_gen_id(type, ++mdev->id);
164
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300165 switch (type) {
166 case MEDIA_GRAPH_ENTITY:
Mauro Carvalho Chehab05bfa9f2015-08-23 07:51:33 -0300167 list_add_tail(&gobj->list, &mdev->entities);
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300168 break;
Mauro Carvalho Chehab18710dc2015-08-14 12:50:08 -0300169 case MEDIA_GRAPH_PAD:
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300170 list_add_tail(&gobj->list, &mdev->pads);
Mauro Carvalho Chehab18710dc2015-08-14 12:50:08 -0300171 break;
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300172 case MEDIA_GRAPH_LINK:
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300173 list_add_tail(&gobj->list, &mdev->links);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300174 break;
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300175 case MEDIA_GRAPH_INTF_DEVNODE:
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300176 list_add_tail(&gobj->list, &mdev->interfaces);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300177 break;
Mauro Carvalho Chehabbfab2aac2015-08-14 12:47:48 -0300178 }
Mauro Carvalho Chehab2521fda2015-08-23 09:40:26 -0300179
180 mdev->topology_version++;
181
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300182 dev_dbg_obj(__func__, gobj);
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300183}
184
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200185void media_gobj_destroy(struct media_gobj *gobj)
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300186{
Mauro Carvalho Chehab39a956c2015-08-13 14:42:42 -0300187 dev_dbg_obj(__func__, gobj);
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300188
Mauro Carvalho Chehab2521fda2015-08-23 09:40:26 -0300189 gobj->mdev->topology_version++;
190
Mauro Carvalho Chehab9155d852015-08-23 08:00:33 -0300191 /* Remove the object from mdev list */
192 list_del(&gobj->list);
Mauro Carvalho Chehabec6e4c92015-08-25 10:28:36 -0300193}
194
Mauro Carvalho Chehab1fc25d32015-12-11 12:14:58 -0200195int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
196 struct media_pad *pads)
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300197{
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300198 struct media_device *mdev = entity->graph_obj.mdev;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300199 unsigned int i;
200
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300201 entity->num_pads = num_pads;
202 entity->pads = pads;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300203
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300204 if (mdev)
205 spin_lock(&mdev->lock);
206
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300207 for (i = 0; i < num_pads; i++) {
208 pads[i].entity = entity;
209 pads[i].index = i;
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300210 if (mdev)
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200211 media_gobj_create(mdev, MEDIA_GRAPH_PAD,
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300212 &entity->pads[i].graph_obj);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300213 }
214
Javier Martinez Canillasdb141a32015-09-08 14:10:56 -0300215 if (mdev)
216 spin_unlock(&mdev->lock);
217
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300218 return 0;
219}
Mauro Carvalho Chehabab22e772015-12-11 07:44:40 -0200220EXPORT_SYMBOL_GPL(media_entity_pads_init);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300221
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300222/* -----------------------------------------------------------------------------
223 * Graph traversal
224 */
225
226static struct media_entity *
227media_entity_other(struct media_entity *entity, struct media_link *link)
228{
229 if (link->source->entity == entity)
230 return link->sink->entity;
231 else
232 return link->source->entity;
233}
234
235/* push an entity to traversal stack */
236static void stack_push(struct media_entity_graph *graph,
237 struct media_entity *entity)
238{
239 if (graph->top == MEDIA_ENTITY_ENUM_MAX_DEPTH - 1) {
240 WARN_ON(1);
241 return;
242 }
243 graph->top++;
Javier Martinez Canillas313895f2015-12-11 15:16:36 -0200244 graph->stack[graph->top].link = entity->links.next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300245 graph->stack[graph->top].entity = entity;
246}
247
248static struct media_entity *stack_pop(struct media_entity_graph *graph)
249{
250 struct media_entity *entity;
251
252 entity = graph->stack[graph->top].entity;
253 graph->top--;
254
255 return entity;
256}
257
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300258#define link_top(en) ((en)->stack[(en)->top].link)
259#define stack_top(en) ((en)->stack[(en)->top].entity)
260
Sakari Ailus0798ce42015-12-16 11:32:37 -0200261/*
262 * TODO: Get rid of this.
263 */
264#define MEDIA_ENTITY_MAX_PADS 63
265
Sakari Ailuse03d2202015-12-16 11:32:22 -0200266/**
267 * media_entity_graph_walk_init - Allocate resources for graph walk
268 * @graph: Media graph structure that will be used to walk the graph
269 * @mdev: Media device
270 *
271 * Reserve resources for graph walk in media device's current
272 * state. The memory must be released using
273 * media_entity_graph_walk_free().
274 *
275 * Returns error on failure, zero on success.
276 */
277__must_check int media_entity_graph_walk_init(
278 struct media_entity_graph *graph, struct media_device *mdev)
279{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200280 return media_entity_enum_init(&graph->ent_enum, mdev);
Sakari Ailuse03d2202015-12-16 11:32:22 -0200281}
282EXPORT_SYMBOL_GPL(media_entity_graph_walk_init);
283
284/**
285 * media_entity_graph_walk_cleanup - Release resources related to graph walking
286 * @graph: Media graph structure that was used to walk the graph
287 */
288void media_entity_graph_walk_cleanup(struct media_entity_graph *graph)
289{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200290 media_entity_enum_cleanup(&graph->ent_enum);
Sakari Ailuse03d2202015-12-16 11:32:22 -0200291}
292EXPORT_SYMBOL_GPL(media_entity_graph_walk_cleanup);
293
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300294void media_entity_graph_walk_start(struct media_entity_graph *graph,
295 struct media_entity *entity)
296{
Sakari Ailus29d8da02015-12-16 11:32:28 -0200297 media_entity_enum_zero(&graph->ent_enum);
298 media_entity_enum_set(&graph->ent_enum, entity);
299
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300300 graph->top = 0;
301 graph->stack[graph->top].entity = NULL;
302 stack_push(graph, entity);
303}
304EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
305
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300306struct media_entity *
307media_entity_graph_walk_next(struct media_entity_graph *graph)
308{
309 if (stack_top(graph) == NULL)
310 return NULL;
311
312 /*
313 * Depth first search. Push entity to stack and continue from
314 * top of the stack until no more entities on the level can be
315 * found.
316 */
Javier Martinez Canillas313895f2015-12-11 15:16:36 -0200317 while (link_top(graph) != &stack_top(graph)->links) {
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300318 struct media_entity *entity = stack_top(graph);
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300319 struct media_link *link;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300320 struct media_entity *next;
321
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300322 link = list_entry(link_top(graph), typeof(*link), list);
323
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300324 /* The link is not enabled so we do not follow. */
325 if (!(link->flags & MEDIA_LNK_FL_ENABLED)) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300326 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300327 continue;
328 }
329
330 /* Get the entity in the other end of the link . */
331 next = media_entity_other(entity, link);
332
Laurent Pinchart5c7b25b2013-06-07 12:45:11 -0300333 /* Has the entity already been visited? */
Sakari Ailus29d8da02015-12-16 11:32:28 -0200334 if (media_entity_enum_test_and_set(&graph->ent_enum, next)) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300335 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300336 continue;
337 }
338
339 /* Push the new entity to stack and start over. */
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300340 link_top(graph) = link_top(graph)->next;
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300341 stack_push(graph, next);
342 }
343
344 return stack_pop(graph);
345}
346EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
347
348/* -----------------------------------------------------------------------------
Laurent Pincharte02188c2010-08-25 09:00:41 -0300349 * Pipeline management
350 */
351
Sakari Ailusaf88be32012-01-11 06:25:15 -0300352__must_check int media_entity_pipeline_start(struct media_entity *entity,
353 struct media_pipeline *pipe)
Laurent Pincharte02188c2010-08-25 09:00:41 -0300354{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300355 struct media_device *mdev = entity->graph_obj.mdev;
Sakari Ailus5dd87752015-12-16 11:32:21 -0200356 struct media_entity_graph *graph = &pipe->graph;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300357 struct media_entity *entity_err = entity;
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300358 struct media_link *link;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300359 int ret;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300360
361 mutex_lock(&mdev->graph_mutex);
362
Sakari Ailus74a41332015-12-16 11:32:29 -0200363 if (!pipe->streaming_count++) {
364 ret = media_entity_graph_walk_init(&pipe->graph, mdev);
365 if (ret)
366 goto error_graph_walk_start;
Sakari Ailus106b9902015-12-16 15:32:23 +0200367 }
368
369 media_entity_graph_walk_start(&pipe->graph, entity);
Laurent Pincharte02188c2010-08-25 09:00:41 -0300370
Sakari Ailus5dd87752015-12-16 11:32:21 -0200371 while ((entity = media_entity_graph_walk_next(graph))) {
Mauro Carvalho Chehabef69ee12015-10-01 18:07:53 -0300372 DECLARE_BITMAP(active, MEDIA_ENTITY_MAX_PADS);
373 DECLARE_BITMAP(has_no_links, MEDIA_ENTITY_MAX_PADS);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300374
Laurent Pincharte02188c2010-08-25 09:00:41 -0300375 entity->stream_count++;
Sakari Ailus8aaf62b2015-11-29 17:20:02 -0200376
377 if (WARN_ON(entity->pipe && entity->pipe != pipe)) {
378 ret = -EBUSY;
379 goto error;
380 }
381
Laurent Pincharte02188c2010-08-25 09:00:41 -0300382 entity->pipe = pipe;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300383
384 /* Already streaming --- no need to check. */
385 if (entity->stream_count > 1)
386 continue;
387
388 if (!entity->ops || !entity->ops->link_validate)
389 continue;
390
Sakari Ailusde49c282013-10-13 08:00:26 -0300391 bitmap_zero(active, entity->num_pads);
392 bitmap_fill(has_no_links, entity->num_pads);
393
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300394 list_for_each_entry(link, &entity->links, list) {
Sakari Ailusde49c282013-10-13 08:00:26 -0300395 struct media_pad *pad = link->sink->entity == entity
396 ? link->sink : link->source;
Sakari Ailusaf88be32012-01-11 06:25:15 -0300397
Sakari Ailusde49c282013-10-13 08:00:26 -0300398 /* Mark that a pad is connected by a link. */
399 bitmap_clear(has_no_links, pad->index, 1);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300400
Sakari Ailusde49c282013-10-13 08:00:26 -0300401 /*
402 * Pads that either do not need to connect or
403 * are connected through an enabled link are
404 * fine.
405 */
406 if (!(pad->flags & MEDIA_PAD_FL_MUST_CONNECT) ||
407 link->flags & MEDIA_LNK_FL_ENABLED)
408 bitmap_set(active, pad->index, 1);
409
410 /*
411 * Link validation will only take place for
412 * sink ends of the link that are enabled.
413 */
414 if (link->sink != pad ||
415 !(link->flags & MEDIA_LNK_FL_ENABLED))
Sakari Ailusaf88be32012-01-11 06:25:15 -0300416 continue;
417
418 ret = entity->ops->link_validate(link);
Sakari Ailusfab9d302014-10-28 20:35:04 -0300419 if (ret < 0 && ret != -ENOIOCTLCMD) {
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300420 dev_dbg(entity->graph_obj.mdev->dev,
Sakari Ailusfab9d302014-10-28 20:35:04 -0300421 "link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
Sakari Ailus823ea2a2015-02-12 11:43:11 -0200422 link->source->entity->name,
423 link->source->index,
424 entity->name, link->sink->index, ret);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300425 goto error;
Sakari Ailusfab9d302014-10-28 20:35:04 -0300426 }
Sakari Ailusaf88be32012-01-11 06:25:15 -0300427 }
Sakari Ailusde49c282013-10-13 08:00:26 -0300428
429 /* Either no links or validated links are fine. */
430 bitmap_or(active, active, has_no_links, entity->num_pads);
431
432 if (!bitmap_full(active, entity->num_pads)) {
433 ret = -EPIPE;
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300434 dev_dbg(entity->graph_obj.mdev->dev,
Sakari Ailusfab9d302014-10-28 20:35:04 -0300435 "\"%s\":%u must be connected by an enabled link\n",
436 entity->name,
Sakari Ailus094f1ca2014-11-03 17:55:51 -0300437 (unsigned)find_first_zero_bit(
438 active, entity->num_pads));
Sakari Ailusde49c282013-10-13 08:00:26 -0300439 goto error;
440 }
Laurent Pincharte02188c2010-08-25 09:00:41 -0300441 }
442
443 mutex_unlock(&mdev->graph_mutex);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300444
445 return 0;
446
447error:
448 /*
449 * Link validation on graph failed. We revert what we did and
450 * return the error.
451 */
Sakari Ailus5dd87752015-12-16 11:32:21 -0200452 media_entity_graph_walk_start(graph, entity_err);
Sakari Ailusaf88be32012-01-11 06:25:15 -0300453
Sakari Ailus5dd87752015-12-16 11:32:21 -0200454 while ((entity_err = media_entity_graph_walk_next(graph))) {
Sakari Ailusaf88be32012-01-11 06:25:15 -0300455 entity_err->stream_count--;
456 if (entity_err->stream_count == 0)
457 entity_err->pipe = NULL;
458
459 /*
460 * We haven't increased stream_count further than this
461 * so we quit here.
462 */
463 if (entity_err == entity)
464 break;
465 }
466
Sakari Ailus74a41332015-12-16 11:32:29 -0200467error_graph_walk_start:
468 if (!--pipe->streaming_count)
469 media_entity_graph_walk_cleanup(graph);
Sakari Ailus106b9902015-12-16 15:32:23 +0200470
Sakari Ailusaf88be32012-01-11 06:25:15 -0300471 mutex_unlock(&mdev->graph_mutex);
472
473 return ret;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300474}
475EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
476
Laurent Pincharte02188c2010-08-25 09:00:41 -0300477void media_entity_pipeline_stop(struct media_entity *entity)
478{
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300479 struct media_device *mdev = entity->graph_obj.mdev;
Sakari Ailus5dd87752015-12-16 11:32:21 -0200480 struct media_entity_graph *graph = &entity->pipe->graph;
Sakari Ailus74a41332015-12-16 11:32:29 -0200481 struct media_pipeline *pipe = entity->pipe;
Laurent Pincharte02188c2010-08-25 09:00:41 -0300482
483 mutex_lock(&mdev->graph_mutex);
484
Sakari Ailus74a41332015-12-16 11:32:29 -0200485 WARN_ON(!pipe->streaming_count);
Sakari Ailus5dd87752015-12-16 11:32:21 -0200486 media_entity_graph_walk_start(graph, entity);
Laurent Pincharte02188c2010-08-25 09:00:41 -0300487
Sakari Ailus5dd87752015-12-16 11:32:21 -0200488 while ((entity = media_entity_graph_walk_next(graph))) {
Laurent Pincharte02188c2010-08-25 09:00:41 -0300489 entity->stream_count--;
490 if (entity->stream_count == 0)
491 entity->pipe = NULL;
492 }
493
Sakari Ailus74a41332015-12-16 11:32:29 -0200494 if (!--pipe->streaming_count)
495 media_entity_graph_walk_cleanup(graph);
Sakari Ailus106b9902015-12-16 15:32:23 +0200496
Laurent Pincharte02188c2010-08-25 09:00:41 -0300497 mutex_unlock(&mdev->graph_mutex);
498}
499EXPORT_SYMBOL_GPL(media_entity_pipeline_stop);
500
501/* -----------------------------------------------------------------------------
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300502 * Module use count
503 */
504
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300505struct media_entity *media_entity_get(struct media_entity *entity)
506{
507 if (entity == NULL)
508 return NULL;
509
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300510 if (entity->graph_obj.mdev->dev &&
511 !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300512 return NULL;
513
514 return entity;
515}
516EXPORT_SYMBOL_GPL(media_entity_get);
517
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300518void media_entity_put(struct media_entity *entity)
519{
520 if (entity == NULL)
521 return;
522
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300523 if (entity->graph_obj.mdev->dev)
524 module_put(entity->graph_obj.mdev->dev->driver->owner);
Laurent Pinchart503c3d822010-03-07 15:04:59 -0300525}
526EXPORT_SYMBOL_GPL(media_entity_put);
527
528/* -----------------------------------------------------------------------------
Sakari Ailusa5ccc482010-03-07 16:14:14 -0300529 * Links management
530 */
531
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300532static struct media_link *media_add_link(struct list_head *head)
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300533{
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300534 struct media_link *link;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300535
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300536 link = kzalloc(sizeof(*link), GFP_KERNEL);
537 if (link == NULL)
538 return NULL;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300539
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300540 list_add_tail(&link->list, head);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300541
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300542 return link;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300543}
544
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300545static void __media_entity_remove_link(struct media_entity *entity,
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200546 struct media_link *link)
547{
548 struct media_link *rlink, *tmp;
549 struct media_entity *remote;
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200550
551 if (link->source->entity == entity)
552 remote = link->sink->entity;
553 else
554 remote = link->source->entity;
555
556 list_for_each_entry_safe(rlink, tmp, &remote->links, list) {
Mauro Carvalho Chehab58f69ee2015-12-11 11:25:23 -0200557 if (rlink != link->reverse)
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200558 continue;
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200559
560 if (link->source->entity == entity)
561 remote->num_backlinks--;
562
563 /* Remove the remote link */
564 list_del(&rlink->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200565 media_gobj_destroy(&rlink->graph_obj);
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200566 kfree(rlink);
567
568 if (--remote->num_links == 0)
569 break;
570 }
571 list_del(&link->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200572 media_gobj_destroy(&link->graph_obj);
Mauro Carvalho Chehab5abad222015-12-11 11:19:38 -0200573 kfree(link);
574}
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300575
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300576int
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300577media_create_pad_link(struct media_entity *source, u16 source_pad,
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300578 struct media_entity *sink, u16 sink_pad, u32 flags)
579{
580 struct media_link *link;
581 struct media_link *backlink;
582
583 BUG_ON(source == NULL || sink == NULL);
584 BUG_ON(source_pad >= source->num_pads);
585 BUG_ON(sink_pad >= sink->num_pads);
586
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300587 link = media_add_link(&source->links);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300588 if (link == NULL)
589 return -ENOMEM;
590
591 link->source = &source->pads[source_pad];
592 link->sink = &sink->pads[sink_pad];
Mauro Carvalho Chehab82ae2a52015-12-11 18:09:13 -0200593 link->flags = flags & ~MEDIA_LNK_FL_INTERFACE_LINK;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300594
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300595 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200596 media_gobj_create(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300597 &link->graph_obj);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300598
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300599 /* Create the backlink. Backlinks are used to help graph traversal and
600 * are not reported to userspace.
601 */
Mauro Carvalho Chehab23615de2015-08-20 08:21:35 -0300602 backlink = media_add_link(&sink->links);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300603 if (backlink == NULL) {
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300604 __media_entity_remove_link(source, link);
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300605 return -ENOMEM;
606 }
607
608 backlink->source = &source->pads[source_pad];
609 backlink->sink = &sink->pads[sink_pad];
610 backlink->flags = flags;
Mauro Carvalho Chehab39d1ebc62015-08-30 09:53:57 -0300611 backlink->is_backlink = true;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300612
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300613 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200614 media_gobj_create(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300615 &backlink->graph_obj);
Mauro Carvalho Chehab6b6a4272015-08-14 12:54:36 -0300616
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300617 link->reverse = backlink;
618 backlink->reverse = link;
619
620 sink->num_backlinks++;
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300621 sink->num_links++;
622 source->num_links++;
Laurent Pinchart53e269c2009-12-09 08:40:00 -0300623
624 return 0;
625}
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300626EXPORT_SYMBOL_GPL(media_create_pad_link);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300627
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300628void __media_entity_remove_links(struct media_entity *entity)
629{
630 struct media_link *link, *tmp;
631
632 list_for_each_entry_safe(link, tmp, &entity->links, list)
633 __media_entity_remove_link(entity, link);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300634
635 entity->num_links = 0;
636 entity->num_backlinks = 0;
637}
638EXPORT_SYMBOL_GPL(__media_entity_remove_links);
639
640void media_entity_remove_links(struct media_entity *entity)
641{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200642 struct media_device *mdev = entity->graph_obj.mdev;
643
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300644 /* Do nothing if the entity is not registered. */
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200645 if (mdev == NULL)
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300646 return;
647
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200648 spin_lock(&mdev->lock);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300649 __media_entity_remove_links(entity);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200650 spin_unlock(&mdev->lock);
Sylwester Nawrocki7349cec2013-05-09 08:29:32 -0300651}
652EXPORT_SYMBOL_GPL(media_entity_remove_links);
653
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300654static int __media_entity_setup_link_notify(struct media_link *link, u32 flags)
655{
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300656 int ret;
657
658 /* Notify both entities. */
659 ret = media_entity_call(link->source->entity, link_setup,
660 link->source, link->sink, flags);
661 if (ret < 0 && ret != -ENOIOCTLCMD)
662 return ret;
663
664 ret = media_entity_call(link->sink->entity, link_setup,
665 link->sink, link->source, flags);
666 if (ret < 0 && ret != -ENOIOCTLCMD) {
667 media_entity_call(link->source->entity, link_setup,
668 link->source, link->sink, link->flags);
669 return ret;
670 }
671
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300672 link->flags = flags;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300673 link->reverse->flags = link->flags;
674
675 return 0;
676}
677
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300678int __media_entity_setup_link(struct media_link *link, u32 flags)
679{
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300680 const u32 mask = MEDIA_LNK_FL_ENABLED;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300681 struct media_device *mdev;
682 struct media_entity *source, *sink;
683 int ret = -EBUSY;
684
685 if (link == NULL)
686 return -EINVAL;
687
Laurent Pinchart7a6f0b22011-03-11 11:34:35 -0300688 /* The non-modifiable link flags must not be modified. */
689 if ((link->flags & ~mask) != (flags & ~mask))
690 return -EINVAL;
691
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300692 if (link->flags & MEDIA_LNK_FL_IMMUTABLE)
693 return link->flags == flags ? 0 : -EINVAL;
694
695 if (link->flags == flags)
696 return 0;
697
698 source = link->source->entity;
699 sink = link->sink->entity;
700
Laurent Pincharte02188c2010-08-25 09:00:41 -0300701 if (!(link->flags & MEDIA_LNK_FL_DYNAMIC) &&
702 (source->stream_count || sink->stream_count))
703 return -EBUSY;
704
Javier Martinez Canillasd10c9892015-08-19 12:35:21 -0300705 mdev = source->graph_obj.mdev;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300706
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -0300707 if (mdev->link_notify) {
708 ret = mdev->link_notify(link, flags,
709 MEDIA_DEV_NOTIFY_PRE_LINK_CH);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300710 if (ret < 0)
711 return ret;
712 }
713
714 ret = __media_entity_setup_link_notify(link, flags);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300715
Sylwester Nawrocki813f5c02013-05-31 10:37:26 -0300716 if (mdev->link_notify)
717 mdev->link_notify(link, flags, MEDIA_DEV_NOTIFY_POST_LINK_CH);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300718
719 return ret;
720}
721
722int media_entity_setup_link(struct media_link *link, u32 flags)
723{
724 int ret;
725
Mauro Carvalho Chehab5c883ed2015-12-15 07:58:18 -0200726 mutex_lock(&link->graph_obj.mdev->graph_mutex);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300727 ret = __media_entity_setup_link(link, flags);
Mauro Carvalho Chehab5c883ed2015-12-15 07:58:18 -0200728 mutex_unlock(&link->graph_obj.mdev->graph_mutex);
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300729
730 return ret;
731}
732EXPORT_SYMBOL_GPL(media_entity_setup_link);
733
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300734struct media_link *
735media_entity_find_link(struct media_pad *source, struct media_pad *sink)
736{
737 struct media_link *link;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300738
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300739 list_for_each_entry(link, &source->entity->links, list) {
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300740 if (link->source->entity == source->entity &&
741 link->source->index == source->index &&
742 link->sink->entity == sink->entity &&
743 link->sink->index == sink->index)
744 return link;
745 }
746
747 return NULL;
748}
749EXPORT_SYMBOL_GPL(media_entity_find_link);
750
Andrzej Hajda1bddf1b2013-06-03 05:16:13 -0300751struct media_pad *media_entity_remote_pad(struct media_pad *pad)
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300752{
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300753 struct media_link *link;
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300754
Mauro Carvalho Chehab57208e52015-08-07 06:55:40 -0300755 list_for_each_entry(link, &pad->entity->links, list) {
Laurent Pinchart97548ed2009-12-09 08:40:03 -0300756 if (!(link->flags & MEDIA_LNK_FL_ENABLED))
757 continue;
758
759 if (link->source == pad)
760 return link->sink;
761
762 if (link->sink == pad)
763 return link->source;
764 }
765
766 return NULL;
767
768}
Andrzej Hajda1bddf1b2013-06-03 05:16:13 -0300769EXPORT_SYMBOL_GPL(media_entity_remote_pad);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300770
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300771static void media_interface_init(struct media_device *mdev,
772 struct media_interface *intf,
773 u32 gobj_type,
774 u32 intf_type, u32 flags)
775{
776 intf->type = intf_type;
777 intf->flags = flags;
778 INIT_LIST_HEAD(&intf->links);
779
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200780 media_gobj_create(mdev, gobj_type, &intf->graph_obj);
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300781}
782
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300783/* Functions related to the media interface via device nodes */
784
785struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
786 u32 type, u32 flags,
Mauro Carvalho Chehab0b3b72df92015-09-09 08:19:25 -0300787 u32 major, u32 minor)
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300788{
789 struct media_intf_devnode *devnode;
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300790
Mauro Carvalho Chehab0b3b72df92015-09-09 08:19:25 -0300791 devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300792 if (!devnode)
793 return NULL;
794
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300795 devnode->major = major;
796 devnode->minor = minor;
797
Mauro Carvalho Chehab1283f842015-08-28 15:43:36 -0300798 media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
799 type, flags);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300800
801 return devnode;
802}
803EXPORT_SYMBOL_GPL(media_devnode_create);
804
805void media_devnode_remove(struct media_intf_devnode *devnode)
806{
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300807 media_remove_intf_links(&devnode->intf);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200808 media_gobj_destroy(&devnode->intf.graph_obj);
Mauro Carvalho Chehab27e543f2015-08-20 09:07:34 -0300809 kfree(devnode);
810}
811EXPORT_SYMBOL_GPL(media_devnode_remove);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300812
813struct media_link *media_create_intf_link(struct media_entity *entity,
814 struct media_interface *intf,
815 u32 flags)
816{
817 struct media_link *link;
818
819 link = media_add_link(&intf->links);
820 if (link == NULL)
821 return NULL;
822
823 link->intf = intf;
824 link->entity = entity;
Mauro Carvalho Chehab82ae2a52015-12-11 18:09:13 -0200825 link->flags = flags | MEDIA_LNK_FL_INTERFACE_LINK;
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300826
827 /* Initialize graph object embedded at the new link */
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200828 media_gobj_create(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300829 &link->graph_obj);
830
831 return link;
832}
833EXPORT_SYMBOL_GPL(media_create_intf_link);
834
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300835void __media_remove_intf_link(struct media_link *link)
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300836{
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300837 list_del(&link->list);
Mauro Carvalho Chehabc350ef82015-12-11 11:55:40 -0200838 media_gobj_destroy(&link->graph_obj);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300839 kfree(link);
840}
Mauro Carvalho Chehabd47109f2015-08-29 21:23:44 -0300841EXPORT_SYMBOL_GPL(__media_remove_intf_link);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300842
843void media_remove_intf_link(struct media_link *link)
844{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200845 struct media_device *mdev = link->graph_obj.mdev;
846
847 /* Do nothing if the intf is not registered. */
848 if (mdev == NULL)
849 return;
850
851 spin_lock(&mdev->lock);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300852 __media_remove_intf_link(link);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200853 spin_unlock(&mdev->lock);
Mauro Carvalho Chehab86e26622015-08-07 10:36:25 -0300854}
855EXPORT_SYMBOL_GPL(media_remove_intf_link);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300856
857void __media_remove_intf_links(struct media_interface *intf)
858{
859 struct media_link *link, *tmp;
860
861 list_for_each_entry_safe(link, tmp, &intf->links, list)
862 __media_remove_intf_link(link);
863
864}
865EXPORT_SYMBOL_GPL(__media_remove_intf_links);
866
867void media_remove_intf_links(struct media_interface *intf)
868{
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200869 struct media_device *mdev = intf->graph_obj.mdev;
870
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300871 /* Do nothing if the intf is not registered. */
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200872 if (mdev == NULL)
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300873 return;
874
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200875 spin_lock(&mdev->lock);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300876 __media_remove_intf_links(intf);
Mauro Carvalho Chehabcc4a8252015-12-15 08:01:13 -0200877 spin_unlock(&mdev->lock);
Mauro Carvalho Chehab7c4696a2015-08-24 08:46:46 -0300878}
879EXPORT_SYMBOL_GPL(media_remove_intf_links);