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