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