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