media: v4l2-async: Add notifier operation to destroy asd instances
[linux-block.git] / include / media / media-entity.h
CommitLineData
1802d0be 1/* SPDX-License-Identifier: GPL-2.0-only */
53e269c1
LP
2/*
3 * Media entity
4 *
5 * Copyright (C) 2010 Nokia Corporation
6 *
7 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 * Sakari Ailus <sakari.ailus@iki.fi>
53e269c1
LP
9 */
10
11#ifndef _MEDIA_ENTITY_H
12#define _MEDIA_ENTITY_H
13
c8d54cd5 14#include <linux/bitmap.h>
2899d35d 15#include <linux/bug.h>
28b2e8f3 16#include <linux/container_of.h>
ae45cd5e 17#include <linux/fwnode.h>
53e269c1 18#include <linux/list.h>
1651333b 19#include <linux/media.h>
28b2e8f3 20#include <linux/types.h>
53e269c1 21
ec6e4c95
MCC
22/* Enums used internally at the media controller to represent graphs */
23
24/**
25 * enum media_gobj_type - type of a graph object
26 *
bfab2aac 27 * @MEDIA_GRAPH_ENTITY: Identify a media entity
18710dc6 28 * @MEDIA_GRAPH_PAD: Identify a media pad
6b6a4278 29 * @MEDIA_GRAPH_LINK: Identify a media link
27e543fa
MCC
30 * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via
31 * a device node
ec6e4c95
MCC
32 */
33enum media_gobj_type {
bfab2aac 34 MEDIA_GRAPH_ENTITY,
18710dc6 35 MEDIA_GRAPH_PAD,
6b6a4278 36 MEDIA_GRAPH_LINK,
27e543fa 37 MEDIA_GRAPH_INTF_DEVNODE,
ec6e4c95
MCC
38};
39
40#define MEDIA_BITS_PER_TYPE 8
05b3b77c
MCC
41#define MEDIA_BITS_PER_ID (32 - MEDIA_BITS_PER_TYPE)
42#define MEDIA_ID_MASK GENMASK_ULL(MEDIA_BITS_PER_ID - 1, 0)
ec6e4c95
MCC
43
44/* Structs to represent the objects that belong to a media graph */
45
46/**
47 * struct media_gobj - Define a graph object.
48 *
48a7c4ba 49 * @mdev: Pointer to the struct &media_device that owns the object
ec6e4c95
MCC
50 * @id: Non-zero object ID identifier. The ID should be unique
51 * inside a media_device, as it is composed by
05b3b77c
MCC
52 * %MEDIA_BITS_PER_TYPE to store the type plus
53 * %MEDIA_BITS_PER_ID to store the ID
c358e80d 54 * @list: List entry stored in one of the per-type mdev object lists
ec6e4c95
MCC
55 *
56 * All objects on the media graph should have this struct embedded
57 */
58struct media_gobj {
39a956c4 59 struct media_device *mdev;
ec6e4c95 60 u32 id;
05bfa9fa 61 struct list_head list;
ec6e4c95
MCC
62};
63
c8d54cd5 64#define MEDIA_ENTITY_ENUM_MAX_DEPTH 16
c8d54cd5 65
c8d54cd5
SA
66/**
67 * struct media_entity_enum - An enumeration of media entities.
68 *
c8d54cd5
SA
69 * @bmap: Bit map in which each bit represents one entity at struct
70 * media_entity->internal_idx.
71 * @idx_max: Number of bits in bmap
72 */
73struct media_entity_enum {
c8d54cd5
SA
74 unsigned long *bmap;
75 int idx_max;
76};
77
434257f1 78/**
20b85227 79 * struct media_graph - Media graph traversal state
434257f1
SA
80 *
81 * @stack: Graph traversal stack; the stack contains information
82 * on the path the media entities to be walked and the
83 * links through which they were reached.
bd945e47
MCC
84 * @stack.entity: pointer to &struct media_entity at the graph.
85 * @stack.link: pointer to &struct list_head.
29d8da02 86 * @ent_enum: Visited entities
434257f1
SA
87 * @top: The top of the stack
88 */
20b85227 89struct media_graph {
82c68290
SA
90 struct {
91 struct media_entity *entity;
92 struct list_head *link;
93 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH];
94
29d8da02 95 struct media_entity_enum ent_enum;
82c68290
SA
96 int top;
97};
98
74604b73 99/**
5dd8775d
SA
100 * struct media_pipeline - Media pipeline related information
101 *
74a41330
SA
102 * @streaming_count: Streaming start count - streaming stop count
103 * @graph: Media graph walk during pipeline start / stop
5dd8775d 104 */
e02188c9 105struct media_pipeline {
74a41330 106 int streaming_count;
20b85227 107 struct media_graph graph;
e02188c9
LP
108};
109
c358e80d
MCC
110/**
111 * struct media_link - A link object part of a media graph.
112 *
113 * @graph_obj: Embedded structure containing the media object common data
114 * @list: Linked list associated with an entity or an interface that
115 * owns the link.
116 * @gobj0: Part of a union. Used to get the pointer for the first
117 * graph_object of the link.
118 * @source: Part of a union. Used only if the first object (gobj0) is
119 * a pad. In that case, it represents the source pad.
120 * @intf: Part of a union. Used only if the first object (gobj0) is
121 * an interface.
122 * @gobj1: Part of a union. Used to get the pointer for the second
123 * graph_object of the link.
e383ce07 124 * @sink: Part of a union. Used only if the second object (gobj1) is
c358e80d
MCC
125 * a pad. In that case, it represents the sink pad.
126 * @entity: Part of a union. Used only if the second object (gobj1) is
127 * an entity.
128 * @reverse: Pointer to the link for the reverse direction of a pad to pad
129 * link.
130 * @flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*)
39d1ebc6 131 * @is_backlink: Indicate if the link is a backlink.
c358e80d 132 */
53e269c1 133struct media_link {
6b6a4278 134 struct media_gobj graph_obj;
57208e5e 135 struct list_head list;
4b8a3c08
MCC
136 union {
137 struct media_gobj *gobj0;
138 struct media_pad *source;
86e26620 139 struct media_interface *intf;
4b8a3c08
MCC
140 };
141 union {
142 struct media_gobj *gobj1;
143 struct media_pad *sink;
86e26620 144 struct media_entity *entity;
4b8a3c08 145 };
c358e80d
MCC
146 struct media_link *reverse;
147 unsigned long flags;
39d1ebc6 148 bool is_backlink;
53e269c1
LP
149};
150
c1a37dd5
MCC
151/**
152 * enum media_pad_signal_type - type of the signal inside a media pad
153 *
154 * @PAD_SIGNAL_DEFAULT:
155 * Default signal. Use this when all inputs or all outputs are
156 * uniquely identified by the pad number.
157 * @PAD_SIGNAL_ANALOG:
158 * The pad contains an analog signal. It can be Radio Frequency,
45cdd2a0 159 * Intermediate Frequency, a baseband signal or sub-carriers.
c1a37dd5
MCC
160 * Tuner inputs, IF-PLL demodulators, composite and s-video signals
161 * should use it.
162 * @PAD_SIGNAL_DV:
163 * Contains a digital video signal, with can be a bitstream of samples
164 * taken from an analog TV video source. On such case, it usually
165 * contains the VBI data on it.
166 * @PAD_SIGNAL_AUDIO:
167 * Contains an Intermediate Frequency analog signal from an audio
168 * sub-carrier or an audio bitstream. IF signals are provided by tuners
169 * and consumed by audio AM/FM decoders. Bitstream audio is provided by
170 * an audio decoder.
171 */
172enum media_pad_signal_type {
173 PAD_SIGNAL_DEFAULT = 0,
174 PAD_SIGNAL_ANALOG,
175 PAD_SIGNAL_DV,
176 PAD_SIGNAL_AUDIO,
177};
178
c358e80d
MCC
179/**
180 * struct media_pad - A media pad graph object.
181 *
182 * @graph_obj: Embedded structure containing the media object common data
183 * @entity: Entity this pad belongs to
184 * @index: Pad index in the entity pads array, numbered from 0 to n
c1a37dd5 185 * @sig_type: Type of the signal inside a media pad
48a7c4ba
MCC
186 * @flags: Pad flags, as defined in
187 * :ref:`include/uapi/linux/media.h <media_header>`
188 * (seek for ``MEDIA_PAD_FL_*``)
c358e80d 189 */
53e269c1 190struct media_pad {
4b8a3c08 191 struct media_gobj graph_obj; /* must be first field in struct */
c358e80d
MCC
192 struct media_entity *entity;
193 u16 index;
c1a37dd5 194 enum media_pad_signal_type sig_type;
c358e80d 195 unsigned long flags;
53e269c1
LP
196};
197
5a5394be
LP
198/**
199 * struct media_entity_operations - Media entity operations
ae45cd5e
NS
200 * @get_fwnode_pad: Return the pad number based on a fwnode endpoint or
201 * a negative value on error. This operation can be used
202 * to map a fwnode to a media pad number. Optional.
5a5394be
LP
203 * @link_setup: Notify the entity of link changes. The operation can
204 * return an error, in which case link setup will be
205 * cancelled. Optional.
206 * @link_validate: Return whether a link is valid from the entity point of
20b85227 207 * view. The media_pipeline_start() function
5a5394be 208 * validates all links by calling this operation. Optional.
5ed470fe 209 *
5b8700e9
MCC
210 * .. note::
211 *
48a7c4ba 212 * Those these callbacks are called with struct &media_device.graph_mutex
5b8700e9 213 * mutex held.
5a5394be 214 */
97548ed4 215struct media_entity_operations {
70d4a9ef
SL
216 int (*get_fwnode_pad)(struct media_entity *entity,
217 struct fwnode_endpoint *endpoint);
97548ed4
LP
218 int (*link_setup)(struct media_entity *entity,
219 const struct media_pad *local,
220 const struct media_pad *remote, u32 flags);
af88be38 221 int (*link_validate)(struct media_link *link);
97548ed4
LP
222};
223
b76a2a8c
LP
224/**
225 * enum media_entity_type - Media entity type
226 *
227 * @MEDIA_ENTITY_TYPE_BASE:
228 * The entity isn't embedded in another subsystem structure.
229 * @MEDIA_ENTITY_TYPE_VIDEO_DEVICE:
230 * The entity is embedded in a struct video_device instance.
231 * @MEDIA_ENTITY_TYPE_V4L2_SUBDEV:
232 * The entity is embedded in a struct v4l2_subdev instance.
233 *
234 * Media entity objects are often not instantiated directly, but the media
235 * entity structure is inherited by (through embedding) other subsystem-specific
236 * structures. The media entity type identifies the type of the subclass
237 * structure that implements a media entity instance.
238 *
239 * This allows runtime type identification of media entities and safe casting to
240 * the correct object type. For instance, a media entity structure instance
241 * embedded in a v4l2_subdev structure instance will have the type
48a7c4ba 242 * %MEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to a &v4l2_subdev
b76a2a8c
LP
243 * structure using the container_of() macro.
244 */
245enum media_entity_type {
246 MEDIA_ENTITY_TYPE_BASE,
247 MEDIA_ENTITY_TYPE_VIDEO_DEVICE,
248 MEDIA_ENTITY_TYPE_V4L2_SUBDEV,
249};
250
c358e80d
MCC
251/**
252 * struct media_entity - A media entity graph object.
253 *
254 * @graph_obj: Embedded structure containing the media object common data.
255 * @name: Entity name.
b76a2a8c 256 * @obj_type: Type of the object that implements the media_entity.
48a7c4ba
MCC
257 * @function: Entity main function, as defined in
258 * :ref:`include/uapi/linux/media.h <media_header>`
259 * (seek for ``MEDIA_ENT_F_*``)
260 * @flags: Entity flags, as defined in
261 * :ref:`include/uapi/linux/media.h <media_header>`
262 * (seek for ``MEDIA_ENT_FL_*``)
c358e80d
MCC
263 * @num_pads: Number of sink and source pads.
264 * @num_links: Total number of links, forward and back, enabled and disabled.
265 * @num_backlinks: Number of backlinks
665faa97
SA
266 * @internal_idx: An unique internal entity specific number. The numbers are
267 * re-used if entities are unregistered or registered again.
c358e80d
MCC
268 * @pads: Pads array with the size defined by @num_pads.
269 * @links: List of data links.
270 * @ops: Entity operations.
c358e80d
MCC
271 * @use_count: Use count for the entity.
272 * @pipe: Pipeline this entity belongs to.
273 * @info: Union with devnode information. Kept just for backward
274 * compatibility.
bd945e47
MCC
275 * @info.dev: Contains device major and minor info.
276 * @info.dev.major: device node major, if the device is a devnode.
277 * @info.dev.minor: device node minor, if the device is a devnode.
c358e80d
MCC
278 * @major: Devnode major number (zero if not applicable). Kept just
279 * for backward compatibility.
280 * @minor: Devnode minor number (zero if not applicable). Kept just
281 * for backward compatibility.
282 *
48a7c4ba
MCC
283 * .. note::
284 *
3056a8e9
LP
285 * The @use_count reference count must never be negative, but is a signed
286 * integer on purpose: a simple ``WARN_ON(<0)`` check can be used to detect
287 * reference count bugs that would make it negative.
c358e80d 288 */
53e269c1 289struct media_entity {
4b8a3c08 290 struct media_gobj graph_obj; /* must be first field in struct */
c358e80d 291 const char *name;
b76a2a8c 292 enum media_entity_type obj_type;
0e576b76 293 u32 function;
c358e80d 294 unsigned long flags;
53e269c1 295
c358e80d
MCC
296 u16 num_pads;
297 u16 num_links;
298 u16 num_backlinks;
665faa97 299 int internal_idx;
53e269c1 300
c358e80d
MCC
301 struct media_pad *pads;
302 struct list_head links;
53e269c1 303
c358e80d 304 const struct media_entity_operations *ops;
97548ed4 305
c358e80d 306 int use_count;
503c3d82 307
c358e80d 308 struct media_pipeline *pipe;
e02188c9 309
53e269c1 310 union {
53e269c1
LP
311 struct {
312 u32 major;
313 u32 minor;
e31a0ba7 314 } dev;
fa5034c6 315 } info;
53e269c1
LP
316};
317
27e543fa 318/**
c358e80d 319 * struct media_interface - A media interface graph object.
27e543fa
MCC
320 *
321 * @graph_obj: embedded graph object
86e26620 322 * @links: List of links pointing to graph entities
48a7c4ba
MCC
323 * @type: Type of the interface as defined in
324 * :ref:`include/uapi/linux/media.h <media_header>`
325 * (seek for ``MEDIA_INTF_T_*``)
326 * @flags: Interface flags as defined in
327 * :ref:`include/uapi/linux/media.h <media_header>`
328 * (seek for ``MEDIA_INTF_FL_*``)
329 *
330 * .. note::
331 *
332 * Currently, no flags for &media_interface is defined.
27e543fa
MCC
333 */
334struct media_interface {
335 struct media_gobj graph_obj;
86e26620 336 struct list_head links;
27e543fa
MCC
337 u32 type;
338 u32 flags;
339};
340
341/**
c358e80d 342 * struct media_intf_devnode - A media interface via a device node.
27e543fa
MCC
343 *
344 * @intf: embedded interface object
345 * @major: Major number of a device node
346 * @minor: Minor number of a device node
347 */
348struct media_intf_devnode {
349 struct media_interface intf;
c398bb64
MCC
350
351 /* Should match the fields at media_v2_intf_devnode */
27e543fa
MCC
352 u32 major;
353 u32 minor;
354};
355
60266185
MCC
356/**
357 * media_entity_id() - return the media entity graph object id
358 *
48a7c4ba 359 * @entity: pointer to &media_entity
60266185 360 */
fa762394
MCC
361static inline u32 media_entity_id(struct media_entity *entity)
362{
bfab2aac 363 return entity->graph_obj.id;
fa762394
MCC
364}
365
60266185
MCC
366/**
367 * media_type() - return the media object type
368 *
48a7c4ba 369 * @gobj: Pointer to the struct &media_gobj graph object
60266185 370 */
ec6e4c95
MCC
371static inline enum media_gobj_type media_type(struct media_gobj *gobj)
372{
05b3b77c 373 return gobj->id >> MEDIA_BITS_PER_ID;
ec6e4c95
MCC
374}
375
630c0e80
MCC
376/**
377 * media_id() - return the media object ID
378 *
48a7c4ba 379 * @gobj: Pointer to the struct &media_gobj graph object
630c0e80 380 */
05b3b77c 381static inline u32 media_id(struct media_gobj *gobj)
ec6e4c95 382{
05b3b77c 383 return gobj->id & MEDIA_ID_MASK;
ec6e4c95
MCC
384}
385
630c0e80
MCC
386/**
387 * media_gobj_gen_id() - encapsulates type and ID on at the object ID
388 *
389 * @type: object type as define at enum &media_gobj_type.
48a7c4ba 390 * @local_id: next ID, from struct &media_device.id.
630c0e80 391 */
05b3b77c 392static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id)
ec6e4c95
MCC
393{
394 u32 id;
395
05b3b77c
MCC
396 id = type << MEDIA_BITS_PER_ID;
397 id |= local_id & MEDIA_ID_MASK;
ec6e4c95
MCC
398
399 return id;
400}
401
60266185 402/**
45b46879 403 * is_media_entity_v4l2_video_device() - Check if the entity is a video_device
60266185
MCC
404 * @entity: pointer to entity
405 *
48a7c4ba 406 * Return: %true if the entity is an instance of a video_device object and can
b76a2a8c 407 * safely be cast to a struct video_device using the container_of() macro, or
48a7c4ba 408 * %false otherwise.
60266185 409 */
45b46879 410static inline bool is_media_entity_v4l2_video_device(struct media_entity *entity)
fa17b46a 411{
b76a2a8c 412 return entity && entity->obj_type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
fa17b46a
MCC
413}
414
60266185 415/**
b76a2a8c 416 * is_media_entity_v4l2_subdev() - Check if the entity is a v4l2_subdev
60266185
MCC
417 * @entity: pointer to entity
418 *
48a7c4ba
MCC
419 * Return: %true if the entity is an instance of a &v4l2_subdev object and can
420 * safely be cast to a struct &v4l2_subdev using the container_of() macro, or
421 * %false otherwise.
60266185 422 */
fa17b46a
MCC
423static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
424{
b76a2a8c 425 return entity && entity->obj_type == MEDIA_ENTITY_TYPE_V4L2_SUBDEV;
fa17b46a
MCC
426}
427
92777994
MCC
428/**
429 * __media_entity_enum_init - Initialise an entity enumeration
430 *
431 * @ent_enum: Entity enumeration to be initialised
432 * @idx_max: Maximum number of entities in the enumeration
433 *
434 * Return: Returns zero on success or a negative error code.
435 */
c8d54cd5
SA
436__must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum,
437 int idx_max);
92777994
MCC
438
439/**
440 * media_entity_enum_cleanup - Release resources of an entity enumeration
441 *
442 * @ent_enum: Entity enumeration to be released
443 */
444void media_entity_enum_cleanup(struct media_entity_enum *ent_enum);
a5ccc48a 445
c8d54cd5
SA
446/**
447 * media_entity_enum_zero - Clear the entire enum
448 *
03e49338 449 * @ent_enum: Entity enumeration to be cleared
ef69ee1b 450 */
c8d54cd5
SA
451static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum)
452{
453 bitmap_zero(ent_enum->bmap, ent_enum->idx_max);
454}
455
456/**
457 * media_entity_enum_set - Mark a single entity in the enum
458 *
03e49338 459 * @ent_enum: Entity enumeration
c8d54cd5
SA
460 * @entity: Entity to be marked
461 */
462static inline void media_entity_enum_set(struct media_entity_enum *ent_enum,
463 struct media_entity *entity)
464{
465 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
466 return;
467
468 __set_bit(entity->internal_idx, ent_enum->bmap);
469}
470
471/**
472 * media_entity_enum_clear - Unmark a single entity in the enum
473 *
03e49338 474 * @ent_enum: Entity enumeration
c8d54cd5
SA
475 * @entity: Entity to be unmarked
476 */
477static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum,
478 struct media_entity *entity)
479{
480 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
481 return;
482
483 __clear_bit(entity->internal_idx, ent_enum->bmap);
484}
485
486/**
487 * media_entity_enum_test - Test whether the entity is marked
488 *
03e49338 489 * @ent_enum: Entity enumeration
c8d54cd5
SA
490 * @entity: Entity to be tested
491 *
48a7c4ba 492 * Returns %true if the entity was marked.
c8d54cd5
SA
493 */
494static inline bool media_entity_enum_test(struct media_entity_enum *ent_enum,
495 struct media_entity *entity)
496{
497 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
498 return true;
499
500 return test_bit(entity->internal_idx, ent_enum->bmap);
501}
502
503/**
e383ce07
MCC
504 * media_entity_enum_test_and_set - Test whether the entity is marked,
505 * and mark it
c8d54cd5 506 *
03e49338 507 * @ent_enum: Entity enumeration
c8d54cd5
SA
508 * @entity: Entity to be tested
509 *
48a7c4ba 510 * Returns %true if the entity was marked, and mark it before doing so.
c8d54cd5 511 */
03e49338
MCC
512static inline bool
513media_entity_enum_test_and_set(struct media_entity_enum *ent_enum,
514 struct media_entity *entity)
c8d54cd5
SA
515{
516 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
517 return true;
518
519 return __test_and_set_bit(entity->internal_idx, ent_enum->bmap);
520}
521
522/**
03e49338 523 * media_entity_enum_empty - Test whether the entire enum is empty
c8d54cd5 524 *
03e49338 525 * @ent_enum: Entity enumeration
c8d54cd5 526 *
48a7c4ba 527 * Return: %true if the entity was empty.
c8d54cd5
SA
528 */
529static inline bool media_entity_enum_empty(struct media_entity_enum *ent_enum)
530{
531 return bitmap_empty(ent_enum->bmap, ent_enum->idx_max);
532}
533
534/**
535 * media_entity_enum_intersects - Test whether two enums intersect
536 *
03e49338
MCC
537 * @ent_enum1: First entity enumeration
538 * @ent_enum2: Second entity enumeration
c8d54cd5 539 *
48a7c4ba
MCC
540 * Return: %true if entity enumerations @ent_enum1 and @ent_enum2 intersect,
541 * otherwise %false.
c8d54cd5
SA
542 */
543static inline bool media_entity_enum_intersects(
544 struct media_entity_enum *ent_enum1,
545 struct media_entity_enum *ent_enum2)
546{
547 WARN_ON(ent_enum1->idx_max != ent_enum2->idx_max);
548
549 return bitmap_intersects(ent_enum1->bmap, ent_enum2->bmap,
550 min(ent_enum1->idx_max, ent_enum2->idx_max));
551}
ef69ee1b 552
48a7c4ba
MCC
553/**
554 * gobj_to_entity - returns the struct &media_entity pointer from the
555 * @gobj contained on it.
556 *
557 * @gobj: Pointer to the struct &media_gobj graph object
558 */
ec6e4c95
MCC
559#define gobj_to_entity(gobj) \
560 container_of(gobj, struct media_entity, graph_obj)
561
48a7c4ba 562/**
e383ce07 563 * gobj_to_pad - returns the struct &media_pad pointer from the
48a7c4ba
MCC
564 * @gobj contained on it.
565 *
566 * @gobj: Pointer to the struct &media_gobj graph object
567 */
39a956c4
MCC
568#define gobj_to_pad(gobj) \
569 container_of(gobj, struct media_pad, graph_obj)
570
48a7c4ba 571/**
e383ce07 572 * gobj_to_link - returns the struct &media_link pointer from the
48a7c4ba
MCC
573 * @gobj contained on it.
574 *
575 * @gobj: Pointer to the struct &media_gobj graph object
576 */
39a956c4
MCC
577#define gobj_to_link(gobj) \
578 container_of(gobj, struct media_link, graph_obj)
579
48a7c4ba 580/**
e383ce07 581 * gobj_to_intf - returns the struct &media_interface pointer from the
48a7c4ba
MCC
582 * @gobj contained on it.
583 *
584 * @gobj: Pointer to the struct &media_gobj graph object
585 */
27e543fa
MCC
586#define gobj_to_intf(gobj) \
587 container_of(gobj, struct media_interface, graph_obj)
588
48a7c4ba 589/**
e383ce07 590 * intf_to_devnode - returns the struct media_intf_devnode pointer from the
48a7c4ba
MCC
591 * @intf contained on it.
592 *
593 * @intf: Pointer to struct &media_intf_devnode
594 */
27e543fa
MCC
595#define intf_to_devnode(intf) \
596 container_of(intf, struct media_intf_devnode, intf)
597
1fc25d30
MCC
598/**
599 * media_gobj_create - Initialize a graph object
600 *
48a7c4ba 601 * @mdev: Pointer to the &media_device that contains the object
1fc25d30 602 * @type: Type of the object
48a7c4ba 603 * @gobj: Pointer to the struct &media_gobj graph object
1fc25d30 604 *
48a7c4ba
MCC
605 * This routine initializes the embedded struct &media_gobj inside a
606 * media graph object. It is called automatically if ``media_*_create``
607 * function calls are used. However, if the object (entity, link, pad,
608 * interface) is embedded on some other object, this function should be
609 * called before registering the object at the media controller.
1fc25d30 610 */
c350ef83 611void media_gobj_create(struct media_device *mdev,
ec6e4c95
MCC
612 enum media_gobj_type type,
613 struct media_gobj *gobj);
1fc25d30
MCC
614
615/**
616 * media_gobj_destroy - Stop using a graph object on a media device
617 *
48a7c4ba 618 * @gobj: Pointer to the struct &media_gobj graph object
1fc25d30
MCC
619 *
620 * This should be called by all routines like media_device_unregister()
621 * that remove/destroy media graph objects.
622 */
c350ef83 623void media_gobj_destroy(struct media_gobj *gobj);
ec6e4c95 624
db7ee32a
MCC
625/**
626 * media_entity_pads_init() - Initialize the entity pads
627 *
628 * @entity: entity where the pads belong
1fc25d30
MCC
629 * @num_pads: total number of sink and source pads
630 * @pads: Array of @num_pads pads.
631 *
632 * The pads array is managed by the entity driver and passed to
48a7c4ba
MCC
633 * media_entity_pads_init() where its pointer will be stored in the
634 * &media_entity structure.
db7ee32a
MCC
635 *
636 * If no pads are needed, drivers could either directly fill
48a7c4ba 637 * &media_entity->num_pads with 0 and &media_entity->pads with %NULL or call
db7ee32a
MCC
638 * this function that will do the same.
639 *
640 * As the number of pads is known in advance, the pads array is not allocated
641 * dynamically but is managed by the entity driver. Most drivers will embed the
642 * pads array in a driver-specific structure, avoiding dynamic allocation.
643 *
644 * Drivers must set the direction of every pad in the pads array before calling
645 * media_entity_pads_init(). The function will initialize the other pads fields.
646 */
ab22e77c 647int media_entity_pads_init(struct media_entity *entity, u16 num_pads,
57208e5e 648 struct media_pad *pads);
f1fd3289 649
db7ee32a
MCC
650/**
651 * media_entity_cleanup() - free resources associated with an entity
652 *
653 * @entity: entity where the pads belong
654 *
655 * This function must be called during the cleanup phase after unregistering
656 * the entity (currently, it does nothing).
443bf23d
LP
657 *
658 * Calling media_entity_cleanup() on a media_entity whose memory has been
659 * zeroed but that has not been initialized with media_entity_pad_init() is
660 * valid and is a no-op.
db7ee32a 661 */
3580112b
SA
662#if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
663static inline void media_entity_cleanup(struct media_entity *entity) {}
664#else
665#define media_entity_cleanup(entity) do { } while (false)
666#endif
e02188c9 667
9d6d20e6
MCC
668/**
669 * media_get_pad_index() - retrieves a pad index from an entity
670 *
671 * @entity: entity where the pads belong
672 * @is_sink: true if the pad is a sink, false if it is a source
673 * @sig_type: type of signal of the pad to be search
674 *
675 * This helper function finds the first pad index inside an entity that
676 * satisfies both @is_sink and @sig_type conditions.
677 *
678 * Return:
679 *
680 * On success, return the pad number. If the pad was not found or the media
681 * entity is a NULL pointer, return -EINVAL.
682 */
683int media_get_pad_index(struct media_entity *entity, bool is_sink,
684 enum media_pad_signal_type sig_type);
685
db7ee32a
MCC
686/**
687 * media_create_pad_link() - creates a link between two entities.
688 *
689 * @source: pointer to &media_entity of the source pad.
690 * @source_pad: number of the source pad in the pads array
691 * @sink: pointer to &media_entity of the sink pad.
692 * @sink_pad: number of the sink pad in the pads array.
48a7c4ba
MCC
693 * @flags: Link flags, as defined in
694 * :ref:`include/uapi/linux/media.h <media_header>`
695 * ( seek for ``MEDIA_LNK_FL_*``)
db7ee32a
MCC
696 *
697 * Valid values for flags:
db7ee32a 698 *
48a7c4ba
MCC
699 * %MEDIA_LNK_FL_ENABLED
700 * Indicates that the link is enabled and can be used to transfer media data.
701 * When two or more links target a sink pad, only one of them can be
702 * enabled at a time.
74604b73 703 *
48a7c4ba
MCC
704 * %MEDIA_LNK_FL_IMMUTABLE
705 * Indicates that the link enabled state can't be modified at runtime. If
706 * %MEDIA_LNK_FL_IMMUTABLE is set, then %MEDIA_LNK_FL_ENABLED must also be
707 * set, since an immutable link is always enabled.
db7ee32a 708 *
74604b73 709 * .. note::
db7ee32a 710 *
74604b73
MCC
711 * Before calling this function, media_entity_pads_init() and
712 * media_device_register_entity() should be called previously for both ends.
db7ee32a 713 */
77328043
MCC
714__must_check int media_create_pad_link(struct media_entity *source,
715 u16 source_pad, struct media_entity *sink,
716 u16 sink_pad, u32 flags);
b01cc9ce
MCC
717
718/**
719 * media_create_pad_links() - creates a link between two entities.
720 *
721 * @mdev: Pointer to the media_device that contains the object
722 * @source_function: Function of the source entities. Used only if @source is
723 * NULL.
724 * @source: pointer to &media_entity of the source pad. If NULL, it will use
48a7c4ba 725 * all entities that matches the @sink_function.
b01cc9ce
MCC
726 * @source_pad: number of the source pad in the pads array
727 * @sink_function: Function of the sink entities. Used only if @sink is NULL.
728 * @sink: pointer to &media_entity of the sink pad. If NULL, it will use
48a7c4ba 729 * all entities that matches the @sink_function.
b01cc9ce
MCC
730 * @sink_pad: number of the sink pad in the pads array.
731 * @flags: Link flags, as defined in include/uapi/linux/media.h.
48a7c4ba 732 * @allow_both_undefined: if %true, then both @source and @sink can be NULL.
b01cc9ce
MCC
733 * In such case, it will create a crossbar between all entities that
734 * matches @source_function to all entities that matches @sink_function.
48a7c4ba 735 * If %false, it will return 0 and won't create any link if both @source
b01cc9ce
MCC
736 * and @sink are NULL.
737 *
738 * Valid values for flags:
74604b73 739 *
b01cc9ce
MCC
740 * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be
741 * used to transfer media data. If multiple links are created and this
742 * flag is passed as an argument, only the first created link will have
743 * this flag.
744 *
745 * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't
746 * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then
747 * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is
748 * always enabled.
749 *
750 * It is common for some devices to have multiple source and/or sink entities
751 * of the same type that should be linked. While media_create_pad_link()
752 * creates link by link, this function is meant to allow 1:n, n:1 and even
753 * cross-bar (n:n) links.
754 *
48a7c4ba
MCC
755 * .. note::
756 *
757 * Before calling this function, media_entity_pads_init() and
758 * media_device_register_entity() should be called previously for the
759 * entities to be linked.
b01cc9ce
MCC
760 */
761int media_create_pad_links(const struct media_device *mdev,
762 const u32 source_function,
763 struct media_entity *source,
764 const u16 source_pad,
765 const u32 sink_function,
766 struct media_entity *sink,
767 const u16 sink_pad,
768 u32 flags,
769 const bool allow_both_undefined);
770
7349cec1 771void __media_entity_remove_links(struct media_entity *entity);
db7ee32a
MCC
772
773/**
774 * media_entity_remove_links() - remove all links associated with an entity
775 *
776 * @entity: pointer to &media_entity
777 *
74604b73
MCC
778 * .. note::
779 *
780 * This is called automatically when an entity is unregistered via
781 * media_device_register_entity().
db7ee32a 782 */
7349cec1
SN
783void media_entity_remove_links(struct media_entity *entity);
784
1fc25d30
MCC
785/**
786 * __media_entity_setup_link - Configure a media link without locking
787 * @link: The link being configured
788 * @flags: Link configuration flags
789 *
790 * The bulk of link setup is handled by the two entities connected through the
791 * link. This function notifies both entities of the link configuration change.
792 *
793 * If the link is immutable or if the current and new configuration are
794 * identical, return immediately.
795 *
796 * The user is expected to hold link->source->parent->mutex. If not,
797 * media_entity_setup_link() should be used instead.
798 */
97548ed4 799int __media_entity_setup_link(struct media_link *link, u32 flags);
db7ee32a
MCC
800
801/**
802 * media_entity_setup_link() - changes the link flags properties in runtime
803 *
804 * @link: pointer to &media_link
805 * @flags: the requested new link flags
806 *
807 * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag
91bbbf24 808 * to enable/disable a link. Links marked with the
db7ee32a
MCC
809 * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled.
810 *
811 * When a link is enabled or disabled, the media framework calls the
812 * link_setup operation for the two entities at the source and sink of the
813 * link, in that order. If the second link_setup call fails, another
814 * link_setup call is made on the first entity to restore the original link
815 * flags.
816 *
817 * Media device drivers can be notified of link setup operations by setting the
48a7c4ba 818 * &media_device.link_notify pointer to a callback function. If provided, the
db7ee32a
MCC
819 * notification callback will be called before enabling and after disabling
820 * links.
821 *
822 * Entity drivers must implement the link_setup operation if any of their links
823 * is non-immutable. The operation must either configure the hardware or store
824 * the configuration information to be applied later.
825 *
826 * Link configuration must not have any side effect on other links. If an
827 * enabled link at a sink pad prevents another link at the same pad from
48a7c4ba 828 * being enabled, the link_setup operation must return %-EBUSY and can't
db7ee32a
MCC
829 * implicitly disable the first enabled link.
830 *
74604b73
MCC
831 * .. note::
832 *
833 * The valid values of the flags for the link is the same as described
834 * on media_create_pad_link(), for pad to pad links or the same as described
835 * on media_create_intf_link(), for interface to entity links.
db7ee32a 836 */
97548ed4 837int media_entity_setup_link(struct media_link *link, u32 flags);
1fc25d30
MCC
838
839/**
840 * media_entity_find_link - Find a link between two pads
841 * @source: Source pad
842 * @sink: Sink pad
843 *
48a7c4ba
MCC
844 * Return: returns a pointer to the link between the two entities. If no
845 * such link exists, return %NULL.
1fc25d30 846 */
97548ed4
LP
847struct media_link *media_entity_find_link(struct media_pad *source,
848 struct media_pad *sink);
1fc25d30
MCC
849
850/**
851 * media_entity_remote_pad - Find the pad at the remote end of a link
852 * @pad: Pad at the local end of the link
853 *
854 * Search for a remote pad connected to the given pad by iterating over all
855 * links originating or terminating at that pad until an enabled link is found.
856 *
48a7c4ba
MCC
857 * Return: returns a pointer to the pad at the remote end of the first found
858 * enabled link, or %NULL if no enabled link has been found.
1fc25d30 859 */
6538b02d 860struct media_pad *media_entity_remote_pad(const struct media_pad *pad);
53e269c1 861
f17bc788
LP
862/**
863 * media_entity_is_streaming - Test if an entity is part of a streaming pipeline
864 * @entity: The entity
865 *
866 * Return: True if the entity is part of a pipeline started with the
867 * media_pipeline_start() function, false otherwise.
868 */
869static inline bool media_entity_is_streaming(const struct media_entity *entity)
870{
3056a8e9 871 return entity->pipe;
f17bc788
LP
872}
873
d295c6a4
NS
874/**
875 * media_entity_get_fwnode_pad - Get pad number from fwnode
876 *
877 * @entity: The entity
878 * @fwnode: Pointer to the fwnode_handle which should be used to find the pad
879 * @direction_flags: Expected direction of the pad, as defined in
880 * :ref:`include/uapi/linux/media.h <media_header>`
881 * (seek for ``MEDIA_PAD_FL_*``)
882 *
883 * This function can be used to resolve the media pad number from
884 * a fwnode. This is useful for devices which use more complex
885 * mappings of media pads.
886 *
f0a3fa21 887 * If the entity does not implement the get_fwnode_pad() operation
d295c6a4
NS
888 * then this function searches the entity for the first pad that
889 * matches the @direction_flags.
890 *
891 * Return: returns the pad number on success or a negative error code.
892 */
893int media_entity_get_fwnode_pad(struct media_entity *entity,
894 struct fwnode_handle *fwnode,
895 unsigned long direction_flags);
896
48a7c4ba 897/**
20b85227 898 * media_graph_walk_init - Allocate resources used by graph walk.
48a7c4ba
MCC
899 *
900 * @graph: Media graph structure that will be used to walk the graph
901 * @mdev: Pointer to the &media_device that contains the object
4ebddb7c
SA
902 *
903 * The caller is required to hold the media_device graph_mutex during the graph
904 * walk until the graph state is released.
905 *
906 * Returns zero on success or a negative error code otherwise.
48a7c4ba 907 */
20b85227
SA
908__must_check int media_graph_walk_init(
909 struct media_graph *graph, struct media_device *mdev);
aa360d3d
MCC
910
911/**
20b85227 912 * media_graph_walk_cleanup - Release resources used by graph walk.
aa360d3d
MCC
913 *
914 * @graph: Media graph structure that will be used to walk the graph
915 */
20b85227 916void media_graph_walk_cleanup(struct media_graph *graph);
e03d2203 917
1fc25d30 918/**
20b85227 919 * media_graph_walk_start - Start walking the media graph at a
48a7c4ba
MCC
920 * given entity
921 *
1fc25d30
MCC
922 * @graph: Media graph structure that will be used to walk the graph
923 * @entity: Starting entity
924 *
20b85227 925 * Before using this function, media_graph_walk_init() must be
e03d2203
SA
926 * used to allocate resources used for walking the graph. This
927 * function initializes the graph traversal structure to walk the
928 * entities graph starting at the given entity. The traversal
929 * structure must not be modified by the caller during graph
930 * traversal. After the graph walk, the resources must be released
20b85227 931 * using media_graph_walk_cleanup().
1fc25d30 932 */
20b85227
SA
933void media_graph_walk_start(struct media_graph *graph,
934 struct media_entity *entity);
1fc25d30
MCC
935
936/**
20b85227 937 * media_graph_walk_next - Get the next entity in the graph
1fc25d30
MCC
938 * @graph: Media graph structure
939 *
940 * Perform a depth-first traversal of the given media entities graph.
941 *
942 * The graph structure must have been previously initialized with a call to
20b85227 943 * media_graph_walk_start().
1fc25d30 944 *
48a7c4ba
MCC
945 * Return: returns the next entity in the graph or %NULL if the whole graph
946 * have been traversed.
1fc25d30 947 */
20b85227 948struct media_entity *media_graph_walk_next(struct media_graph *graph);
1fc25d30
MCC
949
950/**
20b85227 951 * media_pipeline_start - Mark a pipeline as streaming
1fc25d30
MCC
952 * @entity: Starting entity
953 * @pipe: Media pipeline to be assigned to all entities in the pipeline.
954 *
955 * Mark all entities connected to a given entity through enabled links, either
48a7c4ba
MCC
956 * directly or indirectly, as streaming. The given pipeline object is assigned
957 * to every entity in the pipeline and stored in the media_entity pipe field.
1fc25d30
MCC
958 *
959 * Calls to this function can be nested, in which case the same number of
20b85227 960 * media_pipeline_stop() calls will be required to stop streaming. The
1fc25d30 961 * pipeline pointer must be identical for all nested calls to
20b85227 962 * media_pipeline_start().
1fc25d30 963 */
20b85227
SA
964__must_check int media_pipeline_start(struct media_entity *entity,
965 struct media_pipeline *pipe);
fb49f204 966/**
20b85227 967 * __media_pipeline_start - Mark a pipeline as streaming
fb49f204
SK
968 *
969 * @entity: Starting entity
970 * @pipe: Media pipeline to be assigned to all entities in the pipeline.
971 *
20b85227 972 * ..note:: This is the non-locking version of media_pipeline_start()
fb49f204 973 */
20b85227
SA
974__must_check int __media_pipeline_start(struct media_entity *entity,
975 struct media_pipeline *pipe);
1fc25d30
MCC
976
977/**
20b85227 978 * media_pipeline_stop - Mark a pipeline as not streaming
1fc25d30
MCC
979 * @entity: Starting entity
980 *
981 * Mark all entities connected to a given entity through enabled links, either
982 * directly or indirectly, as not streaming. The media_entity pipe field is
48a7c4ba 983 * reset to %NULL.
1fc25d30 984 *
20b85227 985 * If multiple calls to media_pipeline_start() have been made, the same
1fc25d30
MCC
986 * number of calls to this function are required to mark the pipeline as not
987 * streaming.
988 */
20b85227 989void media_pipeline_stop(struct media_entity *entity);
a5ccc48a 990
fb49f204 991/**
20b85227 992 * __media_pipeline_stop - Mark a pipeline as not streaming
fb49f204
SK
993 *
994 * @entity: Starting entity
995 *
20b85227 996 * .. note:: This is the non-locking version of media_pipeline_stop()
fb49f204 997 */
20b85227 998void __media_pipeline_stop(struct media_entity *entity);
fb49f204 999
db7ee32a
MCC
1000/**
1001 * media_devnode_create() - creates and initializes a device node interface
1002 *
1003 * @mdev: pointer to struct &media_device
48a7c4ba
MCC
1004 * @type: type of the interface, as given by
1005 * :ref:`include/uapi/linux/media.h <media_header>`
1006 * ( seek for ``MEDIA_INTF_T_*``) macros.
1007 * @flags: Interface flags, as defined in
1008 * :ref:`include/uapi/linux/media.h <media_header>`
1009 * ( seek for ``MEDIA_INTF_FL_*``)
db7ee32a
MCC
1010 * @major: Device node major number.
1011 * @minor: Device node minor number.
1012 *
1013 * Return: if succeeded, returns a pointer to the newly allocated
1014 * &media_intf_devnode pointer.
48a7c4ba
MCC
1015 *
1016 * .. note::
1017 *
1018 * Currently, no flags for &media_interface is defined.
db7ee32a 1019 */
5e5387df
MCC
1020struct media_intf_devnode *
1021__must_check media_devnode_create(struct media_device *mdev,
1022 u32 type, u32 flags,
0b3b72df 1023 u32 major, u32 minor);
db7ee32a
MCC
1024/**
1025 * media_devnode_remove() - removes a device node interface
1026 *
1027 * @devnode: pointer to &media_intf_devnode to be freed.
1028 *
1029 * When a device node interface is removed, all links to it are automatically
1030 * removed.
1031 */
27e543fa 1032void media_devnode_remove(struct media_intf_devnode *devnode);
db7ee32a
MCC
1033
1034/**
1035 * media_create_intf_link() - creates a link between an entity and an interface
1036 *
1037 * @entity: pointer to %media_entity
1038 * @intf: pointer to %media_interface
48a7c4ba
MCC
1039 * @flags: Link flags, as defined in
1040 * :ref:`include/uapi/linux/media.h <media_header>`
1041 * ( seek for ``MEDIA_LNK_FL_*``)
db7ee32a
MCC
1042 *
1043 *
1044 * Valid values for flags:
db7ee32a 1045 *
48a7c4ba
MCC
1046 * %MEDIA_LNK_FL_ENABLED
1047 * Indicates that the interface is connected to the entity hardware.
1048 * That's the default value for interfaces. An interface may be disabled if
1049 * the hardware is busy due to the usage of some other interface that it is
1050 * currently controlling the hardware.
1051 *
74604b73
MCC
1052 * A typical example is an hybrid TV device that handle only one type of
1053 * stream on a given time. So, when the digital TV is streaming,
1054 * the V4L2 interfaces won't be enabled, as such device is not able to
1055 * also stream analog TV or radio.
1056 *
1057 * .. note::
db7ee32a 1058 *
74604b73
MCC
1059 * Before calling this function, media_devnode_create() should be called for
1060 * the interface and media_device_register_entity() should be called for the
1061 * interface that will be part of the link.
db7ee32a 1062 */
3c9b04d9 1063struct media_link *
5e5387df
MCC
1064__must_check media_create_intf_link(struct media_entity *entity,
1065 struct media_interface *intf,
1066 u32 flags);
60266185
MCC
1067/**
1068 * __media_remove_intf_link() - remove a single interface link
1069 *
1070 * @link: pointer to &media_link.
1071 *
74604b73 1072 * .. note:: This is an unlocked version of media_remove_intf_link()
60266185 1073 */
d47109fa 1074void __media_remove_intf_link(struct media_link *link);
60266185
MCC
1075
1076/**
1077 * media_remove_intf_link() - remove a single interface link
1078 *
1079 * @link: pointer to &media_link.
1080 *
74604b73 1081 * .. note:: Prefer to use this one, instead of __media_remove_intf_link()
60266185 1082 */
86e26620 1083void media_remove_intf_link(struct media_link *link);
60266185
MCC
1084
1085/**
1086 * __media_remove_intf_links() - remove all links associated with an interface
1087 *
1088 * @intf: pointer to &media_interface
1089 *
74604b73 1090 * .. note:: This is an unlocked version of media_remove_intf_links().
60266185 1091 */
7c4696a9 1092void __media_remove_intf_links(struct media_interface *intf);
92777994 1093
db7ee32a
MCC
1094/**
1095 * media_remove_intf_links() - remove all links associated with an interface
1096 *
1097 * @intf: pointer to &media_interface
1098 *
f58cad22 1099 * .. note::
60266185 1100 *
f58cad22
MCC
1101 * #) This is called automatically when an entity is unregistered via
1102 * media_device_register_entity() and by media_devnode_remove().
60266185 1103 *
f58cad22 1104 * #) Prefer to use this one, instead of __media_remove_intf_links().
db7ee32a 1105 */
7c4696a9
MCC
1106void media_remove_intf_links(struct media_interface *intf);
1107
48a7c4ba
MCC
1108/**
1109 * media_entity_call - Calls a struct media_entity_operations operation on
1110 * an entity
1111 *
1112 * @entity: entity where the @operation will be called
1113 * @operation: type of the operation. Should be the name of a member of
1114 * struct &media_entity_operations.
1115 *
1116 * This helper function will check if @operation is not %NULL. On such case,
1117 * it will issue a call to @operation\(@entity, @args\).
1118 */
1119
97548ed4
LP
1120#define media_entity_call(entity, operation, args...) \
1121 (((entity)->ops && (entity)->ops->operation) ? \
1122 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
1123
012c87f7
DS
1124/**
1125 * media_create_ancillary_link() - create an ancillary link between two
1126 * instances of &media_entity
1127 *
1128 * @primary: pointer to the primary &media_entity
1129 * @ancillary: pointer to the ancillary &media_entity
1130 *
1131 * Create an ancillary link between two entities, indicating that they
1132 * represent two connected pieces of hardware that form a single logical unit.
1133 * A typical example is a camera lens controller being linked to the sensor that
1134 * it is supporting.
1135 *
1136 * The function sets both MEDIA_LNK_FL_ENABLED and MEDIA_LNK_FL_IMMUTABLE for
1137 * the new link.
1138 */
1139struct media_link *
1140media_create_ancillary_link(struct media_entity *primary,
1141 struct media_entity *ancillary);
1142
1ed3d644
DS
1143/**
1144 * __media_entity_next_link() - Iterate through a &media_entity's links
1145 *
1146 * @entity: pointer to the &media_entity
1147 * @link: pointer to a &media_link to hold the iterated values
1148 * @link_type: one of the MEDIA_LNK_FL_LINK_TYPE flags
1149 *
1150 * Return the next link against an entity matching a specific link type. This
1151 * allows iteration through an entity's links whilst guaranteeing all of the
1152 * returned links are of the given type.
1153 */
1154struct media_link *__media_entity_next_link(struct media_entity *entity,
1155 struct media_link *link,
1156 unsigned long link_type);
1157
1158/**
1159 * for_each_media_entity_data_link() - Iterate through an entity's data links
1160 *
1161 * @entity: pointer to the &media_entity
1162 * @link: pointer to a &media_link to hold the iterated values
1163 *
1164 * Iterate over a &media_entity's data links
1165 */
1166#define for_each_media_entity_data_link(entity, link) \
1167 for (link = __media_entity_next_link(entity, NULL, \
1168 MEDIA_LNK_FL_DATA_LINK); \
1169 link; \
1170 link = __media_entity_next_link(entity, link, \
1171 MEDIA_LNK_FL_DATA_LINK))
1172
53e269c1 1173#endif