]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - include/media/media-entity.h
[media] media: Add KernelDoc documentation for struct media_entity_graph
[mirror_ubuntu-hirsute-kernel.git] / include / media / media-entity.h
CommitLineData
53e269c1
LP
1/*
2 * Media entity
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 * Sakari Ailus <sakari.ailus@iki.fi>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef _MEDIA_ENTITY_H
24#define _MEDIA_ENTITY_H
25
c8d54cd5 26#include <linux/bitmap.h>
0149a2e1 27#include <linux/kernel.h>
53e269c1 28#include <linux/list.h>
1651333b 29#include <linux/media.h>
53e269c1 30
ec6e4c95
MCC
31/* Enums used internally at the media controller to represent graphs */
32
33/**
34 * enum media_gobj_type - type of a graph object
35 *
bfab2aac 36 * @MEDIA_GRAPH_ENTITY: Identify a media entity
18710dc6 37 * @MEDIA_GRAPH_PAD: Identify a media pad
6b6a4278 38 * @MEDIA_GRAPH_LINK: Identify a media link
27e543fa
MCC
39 * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via
40 * a device node
ec6e4c95
MCC
41 */
42enum media_gobj_type {
bfab2aac 43 MEDIA_GRAPH_ENTITY,
18710dc6 44 MEDIA_GRAPH_PAD,
6b6a4278 45 MEDIA_GRAPH_LINK,
27e543fa 46 MEDIA_GRAPH_INTF_DEVNODE,
ec6e4c95
MCC
47};
48
49#define MEDIA_BITS_PER_TYPE 8
50#define MEDIA_BITS_PER_LOCAL_ID (32 - MEDIA_BITS_PER_TYPE)
51#define MEDIA_LOCAL_ID_MASK GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
52
53/* Structs to represent the objects that belong to a media graph */
54
55/**
56 * struct media_gobj - Define a graph object.
57 *
c358e80d 58 * @mdev: Pointer to the struct media_device that owns the object
ec6e4c95
MCC
59 * @id: Non-zero object ID identifier. The ID should be unique
60 * inside a media_device, as it is composed by
61 * MEDIA_BITS_PER_TYPE to store the type plus
62 * MEDIA_BITS_PER_LOCAL_ID to store a per-type ID
63 * (called as "local ID").
c358e80d 64 * @list: List entry stored in one of the per-type mdev object lists
ec6e4c95
MCC
65 *
66 * All objects on the media graph should have this struct embedded
67 */
68struct media_gobj {
39a956c4 69 struct media_device *mdev;
ec6e4c95 70 u32 id;
05bfa9fa 71 struct list_head list;
ec6e4c95
MCC
72};
73
c8d54cd5
SA
74#define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
75#define MEDIA_ENTITY_ENUM_MAX_ID 64
76
77/*
78 * The number of pads can't be bigger than the number of entities,
79 * as the worse-case scenario is to have one entity linked up to
80 * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities.
81 */
82#define MEDIA_ENTITY_MAX_PADS (MEDIA_ENTITY_ENUM_MAX_ID - 1)
83
84/**
85 * struct media_entity_enum - An enumeration of media entities.
86 *
87 * @prealloc_bmap: Pre-allocated space reserved for media entities if the
88 * total number of entities does not exceed
89 * MEDIA_ENTITY_ENUM_MAX_ID.
90 * @bmap: Bit map in which each bit represents one entity at struct
91 * media_entity->internal_idx.
92 * @idx_max: Number of bits in bmap
93 */
94struct media_entity_enum {
95 DECLARE_BITMAP(prealloc_bmap, MEDIA_ENTITY_ENUM_MAX_ID);
96 unsigned long *bmap;
97 int idx_max;
98};
99
434257f1
SA
100/**
101 * struct media_entity_graph - Media graph traversal state
102 *
103 * @stack: Graph traversal stack; the stack contains information
104 * on the path the media entities to be walked and the
105 * links through which they were reached.
106 * @entities: Visited entities
107 * @top: The top of the stack
108 */
82c68290
SA
109struct media_entity_graph {
110 struct {
111 struct media_entity *entity;
112 struct list_head *link;
113 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
114
115 DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID);
116 int top;
117};
118
e02188c9
LP
119struct media_pipeline {
120};
121
c358e80d
MCC
122/**
123 * struct media_link - A link object part of a media graph.
124 *
125 * @graph_obj: Embedded structure containing the media object common data
126 * @list: Linked list associated with an entity or an interface that
127 * owns the link.
128 * @gobj0: Part of a union. Used to get the pointer for the first
129 * graph_object of the link.
130 * @source: Part of a union. Used only if the first object (gobj0) is
131 * a pad. In that case, it represents the source pad.
132 * @intf: Part of a union. Used only if the first object (gobj0) is
133 * an interface.
134 * @gobj1: Part of a union. Used to get the pointer for the second
135 * graph_object of the link.
136 * @source: Part of a union. Used only if the second object (gobj1) is
137 * a pad. In that case, it represents the sink pad.
138 * @entity: Part of a union. Used only if the second object (gobj1) is
139 * an entity.
140 * @reverse: Pointer to the link for the reverse direction of a pad to pad
141 * link.
142 * @flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*)
39d1ebc6 143 * @is_backlink: Indicate if the link is a backlink.
c358e80d 144 */
53e269c1 145struct media_link {
6b6a4278 146 struct media_gobj graph_obj;
57208e5e 147 struct list_head list;
4b8a3c08
MCC
148 union {
149 struct media_gobj *gobj0;
150 struct media_pad *source;
86e26620 151 struct media_interface *intf;
4b8a3c08
MCC
152 };
153 union {
154 struct media_gobj *gobj1;
155 struct media_pad *sink;
86e26620 156 struct media_entity *entity;
4b8a3c08 157 };
c358e80d
MCC
158 struct media_link *reverse;
159 unsigned long flags;
39d1ebc6 160 bool is_backlink;
53e269c1
LP
161};
162
c358e80d
MCC
163/**
164 * struct media_pad - A media pad graph object.
165 *
166 * @graph_obj: Embedded structure containing the media object common data
167 * @entity: Entity this pad belongs to
168 * @index: Pad index in the entity pads array, numbered from 0 to n
169 * @flags: Pad flags, as defined in uapi/media.h (MEDIA_PAD_FL_*)
170 */
53e269c1 171struct media_pad {
4b8a3c08 172 struct media_gobj graph_obj; /* must be first field in struct */
c358e80d
MCC
173 struct media_entity *entity;
174 u16 index;
175 unsigned long flags;
53e269c1
LP
176};
177
5a5394be
LP
178/**
179 * struct media_entity_operations - Media entity operations
180 * @link_setup: Notify the entity of link changes. The operation can
181 * return an error, in which case link setup will be
182 * cancelled. Optional.
183 * @link_validate: Return whether a link is valid from the entity point of
184 * view. The media_entity_pipeline_start() function
185 * validates all links by calling this operation. Optional.
186 */
97548ed4
LP
187struct media_entity_operations {
188 int (*link_setup)(struct media_entity *entity,
189 const struct media_pad *local,
190 const struct media_pad *remote, u32 flags);
af88be38 191 int (*link_validate)(struct media_link *link);
97548ed4
LP
192};
193
c358e80d
MCC
194/**
195 * struct media_entity - A media entity graph object.
196 *
197 * @graph_obj: Embedded structure containing the media object common data.
198 * @name: Entity name.
0e576b76
MCC
199 * @function: Entity main function, as defined in uapi/media.h
200 * (MEDIA_ENT_F_*)
c358e80d 201 * @flags: Entity flags, as defined in uapi/media.h (MEDIA_ENT_FL_*)
c358e80d
MCC
202 * @num_pads: Number of sink and source pads.
203 * @num_links: Total number of links, forward and back, enabled and disabled.
204 * @num_backlinks: Number of backlinks
665faa97
SA
205 * @internal_idx: An unique internal entity specific number. The numbers are
206 * re-used if entities are unregistered or registered again.
c358e80d
MCC
207 * @pads: Pads array with the size defined by @num_pads.
208 * @links: List of data links.
209 * @ops: Entity operations.
210 * @stream_count: Stream count for the entity.
211 * @use_count: Use count for the entity.
212 * @pipe: Pipeline this entity belongs to.
213 * @info: Union with devnode information. Kept just for backward
214 * compatibility.
215 * @major: Devnode major number (zero if not applicable). Kept just
216 * for backward compatibility.
217 * @minor: Devnode minor number (zero if not applicable). Kept just
218 * for backward compatibility.
219 *
220 * NOTE: @stream_count and @use_count reference counts must never be
221 * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
222 * can be used to detect reference count bugs that would make them negative.
223 */
53e269c1 224struct media_entity {
4b8a3c08 225 struct media_gobj graph_obj; /* must be first field in struct */
c358e80d 226 const char *name;
0e576b76 227 u32 function;
c358e80d 228 unsigned long flags;
53e269c1 229
c358e80d
MCC
230 u16 num_pads;
231 u16 num_links;
232 u16 num_backlinks;
665faa97 233 int internal_idx;
53e269c1 234
c358e80d
MCC
235 struct media_pad *pads;
236 struct list_head links;
53e269c1 237
c358e80d 238 const struct media_entity_operations *ops;
97548ed4 239
503c3d82
LP
240 /* Reference counts must never be negative, but are signed integers on
241 * purpose: a simple WARN_ON(<0) check can be used to detect reference
242 * count bugs that would make them negative.
243 */
c358e80d
MCC
244 int stream_count;
245 int use_count;
503c3d82 246
c358e80d 247 struct media_pipeline *pipe;
e02188c9 248
53e269c1 249 union {
53e269c1
LP
250 struct {
251 u32 major;
252 u32 minor;
e31a0ba7 253 } dev;
fa5034c6 254 } info;
53e269c1
LP
255};
256
27e543fa 257/**
c358e80d 258 * struct media_interface - A media interface graph object.
27e543fa
MCC
259 *
260 * @graph_obj: embedded graph object
86e26620 261 * @links: List of links pointing to graph entities
c358e80d 262 * @type: Type of the interface as defined in the
27e543fa
MCC
263 * uapi/media/media.h header, e. g.
264 * MEDIA_INTF_T_*
c358e80d 265 * @flags: Interface flags as defined in uapi/media/media.h
27e543fa
MCC
266 */
267struct media_interface {
268 struct media_gobj graph_obj;
86e26620 269 struct list_head links;
27e543fa
MCC
270 u32 type;
271 u32 flags;
272};
273
274/**
c358e80d 275 * struct media_intf_devnode - A media interface via a device node.
27e543fa
MCC
276 *
277 * @intf: embedded interface object
278 * @major: Major number of a device node
279 * @minor: Minor number of a device node
280 */
281struct media_intf_devnode {
282 struct media_interface intf;
c398bb64
MCC
283
284 /* Should match the fields at media_v2_intf_devnode */
27e543fa
MCC
285 u32 major;
286 u32 minor;
287};
288
60266185
MCC
289/**
290 * media_entity_id() - return the media entity graph object id
291 *
292 * @entity: pointer to entity
293 */
fa762394
MCC
294static inline u32 media_entity_id(struct media_entity *entity)
295{
bfab2aac 296 return entity->graph_obj.id;
fa762394
MCC
297}
298
60266185
MCC
299/**
300 * media_type() - return the media object type
301 *
302 * @gobj: pointer to the media graph object
303 */
ec6e4c95
MCC
304static inline enum media_gobj_type media_type(struct media_gobj *gobj)
305{
306 return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
307}
308
309static inline u32 media_localid(struct media_gobj *gobj)
310{
311 return gobj->id & MEDIA_LOCAL_ID_MASK;
312}
313
314static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
315{
316 u32 id;
317
318 id = type << MEDIA_BITS_PER_LOCAL_ID;
319 id |= local_id & MEDIA_LOCAL_ID_MASK;
320
321 return id;
322}
323
60266185
MCC
324/**
325 * is_media_entity_v4l2_io() - identify if the entity main function
326 * is a V4L2 I/O
327 *
328 * @entity: pointer to entity
329 *
330 * Return: true if the entity main function is one of the V4L2 I/O types
331 * (video, VBI or SDR radio); false otherwise.
332 */
fa17b46a
MCC
333static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
334{
335 if (!entity)
336 return false;
337
0e576b76 338 switch (entity->function) {
4ca72efa
MCC
339 case MEDIA_ENT_F_IO_V4L:
340 case MEDIA_ENT_F_IO_VBI:
341 case MEDIA_ENT_F_IO_SWRADIO:
fa17b46a
MCC
342 return true;
343 default:
344 return false;
345 }
346}
347
60266185
MCC
348/**
349 * is_media_entity_v4l2_subdev - return true if the entity main function is
350 * associated with the V4L2 API subdev usage
351 *
352 * @entity: pointer to entity
353 *
354 * This is an ancillary function used by subdev-based V4L2 drivers.
355 * It checks if the entity function is one of functions used by a V4L2 subdev,
356 * e. g. camera-relatef functions, analog TV decoder, TV tuner, V4L2 DSPs.
357 */
fa17b46a
MCC
358static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
359{
360 if (!entity)
361 return false;
362
0e576b76 363 switch (entity->function) {
4ca72efa
MCC
364 case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN:
365 case MEDIA_ENT_F_CAM_SENSOR:
366 case MEDIA_ENT_F_FLASH:
367 case MEDIA_ENT_F_LENS:
368 case MEDIA_ENT_F_ATV_DECODER:
369 case MEDIA_ENT_F_TUNER:
fa17b46a
MCC
370 return true;
371
372 default:
373 return false;
374 }
375}
376
c8d54cd5
SA
377__must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
378 int idx_max);
379void media_entity_enum_cleanup(struct media_entity_enum *e);
a5ccc48a 380
c8d54cd5
SA
381/**
382 * media_entity_enum_zero - Clear the entire enum
383 *
384 * @e: Entity enumeration to be cleared
ef69ee1b 385 */
c8d54cd5
SA
386static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum)
387{
388 bitmap_zero(ent_enum->bmap, ent_enum->idx_max);
389}
390
391/**
392 * media_entity_enum_set - Mark a single entity in the enum
393 *
394 * @e: Entity enumeration
395 * @entity: Entity to be marked
396 */
397static inline void media_entity_enum_set(struct media_entity_enum *ent_enum,
398 struct media_entity *entity)
399{
400 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
401 return;
402
403 __set_bit(entity->internal_idx, ent_enum->bmap);
404}
405
406/**
407 * media_entity_enum_clear - Unmark a single entity in the enum
408 *
409 * @e: Entity enumeration
410 * @entity: Entity to be unmarked
411 */
412static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum,
413 struct media_entity *entity)
414{
415 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
416 return;
417
418 __clear_bit(entity->internal_idx, ent_enum->bmap);
419}
420
421/**
422 * media_entity_enum_test - Test whether the entity is marked
423 *
424 * @e: Entity enumeration
425 * @entity: Entity to be tested
426 *
427 * Returns true if the entity was marked.
428 */
429static inline bool media_entity_enum_test(struct media_entity_enum *ent_enum,
430 struct media_entity *entity)
431{
432 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
433 return true;
434
435 return test_bit(entity->internal_idx, ent_enum->bmap);
436}
437
438/**
439 * media_entity_enum_test - Test whether the entity is marked, and mark it
440 *
441 * @e: Entity enumeration
442 * @entity: Entity to be tested
443 *
444 * Returns true if the entity was marked, and mark it before doing so.
445 */
446static inline bool media_entity_enum_test_and_set(
447 struct media_entity_enum *ent_enum, struct media_entity *entity)
448{
449 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
450 return true;
451
452 return __test_and_set_bit(entity->internal_idx, ent_enum->bmap);
453}
454
455/**
456 * media_entity_enum_test - Test whether the entire enum is empty
457 *
458 * @e: Entity enumeration
459 * @entity: Entity to be tested
460 *
461 * Returns true if the entity was marked.
462 */
463static inline bool media_entity_enum_empty(struct media_entity_enum *ent_enum)
464{
465 return bitmap_empty(ent_enum->bmap, ent_enum->idx_max);
466}
467
468/**
469 * media_entity_enum_intersects - Test whether two enums intersect
470 *
471 * @e: First entity enumeration
472 * @f: Second entity enumeration
473 *
474 * Returns true if entity enumerations e and f intersect, otherwise false.
475 */
476static inline bool media_entity_enum_intersects(
477 struct media_entity_enum *ent_enum1,
478 struct media_entity_enum *ent_enum2)
479{
480 WARN_ON(ent_enum1->idx_max != ent_enum2->idx_max);
481
482 return bitmap_intersects(ent_enum1->bmap, ent_enum2->bmap,
483 min(ent_enum1->idx_max, ent_enum2->idx_max));
484}
ef69ee1b 485
ec6e4c95
MCC
486#define gobj_to_entity(gobj) \
487 container_of(gobj, struct media_entity, graph_obj)
488
39a956c4
MCC
489#define gobj_to_pad(gobj) \
490 container_of(gobj, struct media_pad, graph_obj)
491
492#define gobj_to_link(gobj) \
493 container_of(gobj, struct media_link, graph_obj)
494
27e543fa
MCC
495#define gobj_to_link(gobj) \
496 container_of(gobj, struct media_link, graph_obj)
497
498#define gobj_to_pad(gobj) \
499 container_of(gobj, struct media_pad, graph_obj)
500
501#define gobj_to_intf(gobj) \
502 container_of(gobj, struct media_interface, graph_obj)
503
504#define intf_to_devnode(intf) \
505 container_of(intf, struct media_intf_devnode, intf)
506
1fc25d30
MCC
507/**
508 * media_gobj_create - Initialize a graph object
509 *
510 * @mdev: Pointer to the media_device that contains the object
511 * @type: Type of the object
512 * @gobj: Pointer to the graph object
513 *
514 * This routine initializes the embedded struct media_gobj inside a
515 * media graph object. It is called automatically if media_*_create()
516 * calls are used. However, if the object (entity, link, pad, interface)
517 * is embedded on some other object, this function should be called before
518 * registering the object at the media controller.
519 */
c350ef83 520void media_gobj_create(struct media_device *mdev,
ec6e4c95
MCC
521 enum media_gobj_type type,
522 struct media_gobj *gobj);
1fc25d30
MCC
523
524/**
525 * media_gobj_destroy - Stop using a graph object on a media device
526 *
527 * @gobj: Pointer to the graph object
528 *
529 * This should be called by all routines like media_device_unregister()
530 * that remove/destroy media graph objects.
531 */
c350ef83 532void media_gobj_destroy(struct media_gobj *gobj);
ec6e4c95 533
db7ee32a
MCC
534/**
535 * media_entity_pads_init() - Initialize the entity pads
536 *
537 * @entity: entity where the pads belong
1fc25d30
MCC
538 * @num_pads: total number of sink and source pads
539 * @pads: Array of @num_pads pads.
540 *
541 * The pads array is managed by the entity driver and passed to
542 * media_entity_pads_init() where its pointer will be stored in the entity
543 * structure.
db7ee32a
MCC
544 *
545 * If no pads are needed, drivers could either directly fill
546 * &media_entity->@num_pads with 0 and &media_entity->@pads with NULL or call
547 * this function that will do the same.
548 *
549 * As the number of pads is known in advance, the pads array is not allocated
550 * dynamically but is managed by the entity driver. Most drivers will embed the
551 * pads array in a driver-specific structure, avoiding dynamic allocation.
552 *
553 * Drivers must set the direction of every pad in the pads array before calling
554 * media_entity_pads_init(). The function will initialize the other pads fields.
555 */
ab22e77c 556int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
57208e5e 557 struct media_pad *pads);
f1fd3289 558
db7ee32a
MCC
559/**
560 * media_entity_cleanup() - free resources associated with an entity
561 *
562 * @entity: entity where the pads belong
563 *
564 * This function must be called during the cleanup phase after unregistering
565 * the entity (currently, it does nothing).
566 */
f1fd3289 567static inline void media_entity_cleanup(struct media_entity *entity) {};
e02188c9 568
db7ee32a
MCC
569/**
570 * media_create_pad_link() - creates a link between two entities.
571 *
572 * @source: pointer to &media_entity of the source pad.
573 * @source_pad: number of the source pad in the pads array
574 * @sink: pointer to &media_entity of the sink pad.
575 * @sink_pad: number of the sink pad in the pads array.
576 * @flags: Link flags, as defined in include/uapi/linux/media.h.
577 *
578 * Valid values for flags:
579 * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be
580 * used to transfer media data. When two or more links target a sink pad,
581 * only one of them can be enabled at a time.
582 *
583 * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't
584 * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then
585 * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is
586 * always enabled.
587 *
588 * NOTE:
589 *
590 * Before calling this function, media_entity_pads_init() and
591 * media_device_register_entity() should be called previously for both ends.
592 */
77328043
MCC
593__must_check int media_create_pad_link(struct media_entity *source,
594 u16 source_pad, struct media_entity *sink,
595 u16 sink_pad, u32 flags);
7349cec1 596void __media_entity_remove_links(struct media_entity *entity);
db7ee32a
MCC
597
598/**
599 * media_entity_remove_links() - remove all links associated with an entity
600 *
601 * @entity: pointer to &media_entity
602 *
603 * Note: this is called automatically when an entity is unregistered via
604 * media_device_register_entity().
605 */
7349cec1
SN
606void media_entity_remove_links(struct media_entity *entity);
607
1fc25d30
MCC
608/**
609 * __media_entity_setup_link - Configure a media link without locking
610 * @link: The link being configured
611 * @flags: Link configuration flags
612 *
613 * The bulk of link setup is handled by the two entities connected through the
614 * link. This function notifies both entities of the link configuration change.
615 *
616 * If the link is immutable or if the current and new configuration are
617 * identical, return immediately.
618 *
619 * The user is expected to hold link->source->parent->mutex. If not,
620 * media_entity_setup_link() should be used instead.
621 */
97548ed4 622int __media_entity_setup_link(struct media_link *link, u32 flags);
db7ee32a
MCC
623
624/**
625 * media_entity_setup_link() - changes the link flags properties in runtime
626 *
627 * @link: pointer to &media_link
628 * @flags: the requested new link flags
629 *
630 * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag
631 * flag to enable/disable a link. Links marked with the
632 * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled.
633 *
634 * When a link is enabled or disabled, the media framework calls the
635 * link_setup operation for the two entities at the source and sink of the
636 * link, in that order. If the second link_setup call fails, another
637 * link_setup call is made on the first entity to restore the original link
638 * flags.
639 *
640 * Media device drivers can be notified of link setup operations by setting the
641 * media_device::link_notify pointer to a callback function. If provided, the
642 * notification callback will be called before enabling and after disabling
643 * links.
644 *
645 * Entity drivers must implement the link_setup operation if any of their links
646 * is non-immutable. The operation must either configure the hardware or store
647 * the configuration information to be applied later.
648 *
649 * Link configuration must not have any side effect on other links. If an
650 * enabled link at a sink pad prevents another link at the same pad from
651 * being enabled, the link_setup operation must return -EBUSY and can't
652 * implicitly disable the first enabled link.
653 *
654 * NOTE: the valid values of the flags for the link is the same as described
655 * on media_create_pad_link(), for pad to pad links or the same as described
656 * on media_create_intf_link(), for interface to entity links.
657 */
97548ed4 658int media_entity_setup_link(struct media_link *link, u32 flags);
1fc25d30
MCC
659
660/**
661 * media_entity_find_link - Find a link between two pads
662 * @source: Source pad
663 * @sink: Sink pad
664 *
665 * Return a pointer to the link between the two entities. If no such link
666 * exists, return NULL.
667 */
97548ed4
LP
668struct media_link *media_entity_find_link(struct media_pad *source,
669 struct media_pad *sink);
1fc25d30
MCC
670
671/**
672 * media_entity_remote_pad - Find the pad at the remote end of a link
673 * @pad: Pad at the local end of the link
674 *
675 * Search for a remote pad connected to the given pad by iterating over all
676 * links originating or terminating at that pad until an enabled link is found.
677 *
678 * Return a pointer to the pad at the remote end of the first found enabled
679 * link, or NULL if no enabled link has been found.
680 */
1bddf1b3 681struct media_pad *media_entity_remote_pad(struct media_pad *pad);
53e269c1 682
1fc25d30
MCC
683/**
684 * media_entity_get - Get a reference to the parent module
685 *
686 * @entity: The entity
687 *
688 * Get a reference to the parent media device module.
689 *
690 * The function will return immediately if @entity is NULL.
691 *
692 * Return a pointer to the entity on success or NULL on failure.
693 */
503c3d82 694struct media_entity *media_entity_get(struct media_entity *entity);
1fc25d30
MCC
695
696/**
697 * media_entity_put - Release the reference to the parent module
698 *
699 * @entity: The entity
700 *
701 * Release the reference count acquired by media_entity_get().
702 *
703 * The function will return immediately if @entity is NULL.
704 */
503c3d82
LP
705void media_entity_put(struct media_entity *entity);
706
1fc25d30
MCC
707/**
708 * media_entity_graph_walk_start - Start walking the media graph at a given entity
709 * @graph: Media graph structure that will be used to walk the graph
710 * @entity: Starting entity
711 *
712 * This function initializes the graph traversal structure to walk the entities
713 * graph starting at the given entity. The traversal structure must not be
714 * modified by the caller during graph traversal. When done the structure can
715 * safely be freed.
716 */
a5ccc48a
SA
717void media_entity_graph_walk_start(struct media_entity_graph *graph,
718 struct media_entity *entity);
1fc25d30
MCC
719
720/**
721 * media_entity_graph_walk_next - Get the next entity in the graph
722 * @graph: Media graph structure
723 *
724 * Perform a depth-first traversal of the given media entities graph.
725 *
726 * The graph structure must have been previously initialized with a call to
727 * media_entity_graph_walk_start().
728 *
729 * Return the next entity in the graph or NULL if the whole graph have been
730 * traversed.
731 */
a5ccc48a
SA
732struct media_entity *
733media_entity_graph_walk_next(struct media_entity_graph *graph);
1fc25d30
MCC
734
735/**
736 * media_entity_pipeline_start - Mark a pipeline as streaming
737 * @entity: Starting entity
738 * @pipe: Media pipeline to be assigned to all entities in the pipeline.
739 *
740 * Mark all entities connected to a given entity through enabled links, either
741 * directly or indirectly, as streaming. The given pipeline object is assigned to
742 * every entity in the pipeline and stored in the media_entity pipe field.
743 *
744 * Calls to this function can be nested, in which case the same number of
745 * media_entity_pipeline_stop() calls will be required to stop streaming. The
746 * pipeline pointer must be identical for all nested calls to
747 * media_entity_pipeline_start().
748 */
af88be38
SA
749__must_check int media_entity_pipeline_start(struct media_entity *entity,
750 struct media_pipeline *pipe);
1fc25d30
MCC
751
752/**
753 * media_entity_pipeline_stop - Mark a pipeline as not streaming
754 * @entity: Starting entity
755 *
756 * Mark all entities connected to a given entity through enabled links, either
757 * directly or indirectly, as not streaming. The media_entity pipe field is
758 * reset to NULL.
759 *
760 * If multiple calls to media_entity_pipeline_start() have been made, the same
761 * number of calls to this function are required to mark the pipeline as not
762 * streaming.
763 */
e02188c9 764void media_entity_pipeline_stop(struct media_entity *entity);
a5ccc48a 765
db7ee32a
MCC
766/**
767 * media_devnode_create() - creates and initializes a device node interface
768 *
769 * @mdev: pointer to struct &media_device
770 * @type: type of the interface, as given by MEDIA_INTF_T_* macros
771 * as defined in the uapi/media/media.h header.
772 * @flags: Interface flags as defined in uapi/media/media.h.
773 * @major: Device node major number.
774 * @minor: Device node minor number.
775 *
776 * Return: if succeeded, returns a pointer to the newly allocated
777 * &media_intf_devnode pointer.
778 */
5e5387df
MCC
779struct media_intf_devnode *
780__must_check media_devnode_create(struct media_device *mdev,
781 u32 type, u32 flags,
0b3b72df 782 u32 major, u32 minor);
db7ee32a
MCC
783/**
784 * media_devnode_remove() - removes a device node interface
785 *
786 * @devnode: pointer to &media_intf_devnode to be freed.
787 *
788 * When a device node interface is removed, all links to it are automatically
789 * removed.
790 */
27e543fa 791void media_devnode_remove(struct media_intf_devnode *devnode);
5e5387df 792struct media_link *
db7ee32a
MCC
793
794/**
795 * media_create_intf_link() - creates a link between an entity and an interface
796 *
797 * @entity: pointer to %media_entity
798 * @intf: pointer to %media_interface
799 * @flags: Link flags, as defined in include/uapi/linux/media.h.
800 *
801 *
802 * Valid values for flags:
803 * The %MEDIA_LNK_FL_ENABLED flag indicates that the interface is connected to
804 * the entity hardware. That's the default value for interfaces. An
805 * interface may be disabled if the hardware is busy due to the usage
806 * of some other interface that it is currently controlling the hardware.
807 * A typical example is an hybrid TV device that handle only one type of
808 * stream on a given time. So, when the digital TV is streaming,
809 * the V4L2 interfaces won't be enabled, as such device is not able to
810 * also stream analog TV or radio.
811 *
812 * Note:
813 *
814 * Before calling this function, media_devnode_create() should be called for
815 * the interface and media_device_register_entity() should be called for the
816 * interface that will be part of the link.
817 */
5e5387df
MCC
818__must_check media_create_intf_link(struct media_entity *entity,
819 struct media_interface *intf,
820 u32 flags);
60266185
MCC
821/**
822 * __media_remove_intf_link() - remove a single interface link
823 *
824 * @link: pointer to &media_link.
825 *
826 * Note: this is an unlocked version of media_remove_intf_link()
827 */
d47109fa 828void __media_remove_intf_link(struct media_link *link);
60266185
MCC
829
830/**
831 * media_remove_intf_link() - remove a single interface link
832 *
833 * @link: pointer to &media_link.
834 *
835 * Note: prefer to use this one, instead of __media_remove_intf_link()
836 */
86e26620 837void media_remove_intf_link(struct media_link *link);
60266185
MCC
838
839/**
840 * __media_remove_intf_links() - remove all links associated with an interface
841 *
842 * @intf: pointer to &media_interface
843 *
844 * Note: this is an unlocked version of media_remove_intf_links().
845 */
7c4696a9 846void __media_remove_intf_links(struct media_interface *intf);
db7ee32a
MCC
847/**
848 * media_remove_intf_links() - remove all links associated with an interface
849 *
850 * @intf: pointer to &media_interface
851 *
60266185
MCC
852 * Notes:
853 *
854 * this is called automatically when an entity is unregistered via
db7ee32a 855 * media_device_register_entity() and by media_devnode_remove().
60266185
MCC
856 *
857 * Prefer to use this one, instead of __media_remove_intf_links().
db7ee32a 858 */
7c4696a9
MCC
859void media_remove_intf_links(struct media_interface *intf);
860
86e26620 861
97548ed4
LP
862#define media_entity_call(entity, operation, args...) \
863 (((entity)->ops && (entity)->ops->operation) ? \
864 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
865
53e269c1 866#endif