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