Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 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. |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #ifndef _MEDIA_ENTITY_H |
| 20 | #define _MEDIA_ENTITY_H |
| 21 | |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 22 | #include <linux/bitmap.h> |
Philipp Zabel | 2899d35 | 2016-02-15 09:08:06 -0200 | [diff] [blame] | 23 | #include <linux/bug.h> |
Sakari Ailus | 0149a2e | 2013-12-13 08:58:37 -0300 | [diff] [blame] | 24 | #include <linux/kernel.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 25 | #include <linux/list.h> |
Laurent Pinchart | 1651333 | 2009-12-09 08:40:01 -0300 | [diff] [blame] | 26 | #include <linux/media.h> |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 27 | |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 28 | /* Enums used internally at the media controller to represent graphs */ |
| 29 | |
| 30 | /** |
| 31 | * enum media_gobj_type - type of a graph object |
| 32 | * |
Mauro Carvalho Chehab | bfab2aac | 2015-08-14 12:47:48 -0300 | [diff] [blame] | 33 | * @MEDIA_GRAPH_ENTITY: Identify a media entity |
Mauro Carvalho Chehab | 18710dc | 2015-08-14 12:50:08 -0300 | [diff] [blame] | 34 | * @MEDIA_GRAPH_PAD: Identify a media pad |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 35 | * @MEDIA_GRAPH_LINK: Identify a media link |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 36 | * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via |
| 37 | * a device node |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 38 | */ |
| 39 | enum media_gobj_type { |
Mauro Carvalho Chehab | bfab2aac | 2015-08-14 12:47:48 -0300 | [diff] [blame] | 40 | MEDIA_GRAPH_ENTITY, |
Mauro Carvalho Chehab | 18710dc | 2015-08-14 12:50:08 -0300 | [diff] [blame] | 41 | MEDIA_GRAPH_PAD, |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 42 | MEDIA_GRAPH_LINK, |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 43 | MEDIA_GRAPH_INTF_DEVNODE, |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | #define MEDIA_BITS_PER_TYPE 8 |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 47 | #define MEDIA_BITS_PER_ID (32 - MEDIA_BITS_PER_TYPE) |
| 48 | #define MEDIA_ID_MASK GENMASK_ULL(MEDIA_BITS_PER_ID - 1, 0) |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 49 | |
| 50 | /* Structs to represent the objects that belong to a media graph */ |
| 51 | |
| 52 | /** |
| 53 | * struct media_gobj - Define a graph object. |
| 54 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 55 | * @mdev: Pointer to the struct &media_device that owns the object |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 56 | * @id: Non-zero object ID identifier. The ID should be unique |
| 57 | * inside a media_device, as it is composed by |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 58 | * %MEDIA_BITS_PER_TYPE to store the type plus |
| 59 | * %MEDIA_BITS_PER_ID to store the ID |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 60 | * @list: List entry stored in one of the per-type mdev object lists |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 61 | * |
| 62 | * All objects on the media graph should have this struct embedded |
| 63 | */ |
| 64 | struct media_gobj { |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 65 | struct media_device *mdev; |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 66 | u32 id; |
Mauro Carvalho Chehab | 05bfa9f | 2015-08-23 07:51:33 -0300 | [diff] [blame] | 67 | struct list_head list; |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 68 | }; |
| 69 | |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 70 | #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 71 | |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 72 | /** |
| 73 | * struct media_entity_enum - An enumeration of media entities. |
| 74 | * |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 75 | * @bmap: Bit map in which each bit represents one entity at struct |
| 76 | * media_entity->internal_idx. |
| 77 | * @idx_max: Number of bits in bmap |
| 78 | */ |
| 79 | struct media_entity_enum { |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 80 | unsigned long *bmap; |
| 81 | int idx_max; |
| 82 | }; |
| 83 | |
Sakari Ailus | 434257f | 2015-12-16 11:32:20 -0200 | [diff] [blame] | 84 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 85 | * struct media_graph - Media graph traversal state |
Sakari Ailus | 434257f | 2015-12-16 11:32:20 -0200 | [diff] [blame] | 86 | * |
| 87 | * @stack: Graph traversal stack; the stack contains information |
| 88 | * on the path the media entities to be walked and the |
| 89 | * links through which they were reached. |
Sakari Ailus | 29d8da0 | 2015-12-16 11:32:28 -0200 | [diff] [blame] | 90 | * @ent_enum: Visited entities |
Sakari Ailus | 434257f | 2015-12-16 11:32:20 -0200 | [diff] [blame] | 91 | * @top: The top of the stack |
| 92 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 93 | struct media_graph { |
Sakari Ailus | 82c6829 | 2015-12-16 11:32:19 -0200 | [diff] [blame] | 94 | struct { |
| 95 | struct media_entity *entity; |
| 96 | struct list_head *link; |
| 97 | } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; |
| 98 | |
Sakari Ailus | 29d8da0 | 2015-12-16 11:32:28 -0200 | [diff] [blame] | 99 | struct media_entity_enum ent_enum; |
Sakari Ailus | 82c6829 | 2015-12-16 11:32:19 -0200 | [diff] [blame] | 100 | int top; |
| 101 | }; |
| 102 | |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 103 | /** |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 104 | * struct media_pipeline - Media pipeline related information |
| 105 | * |
Sakari Ailus | 74a4133 | 2015-12-16 11:32:29 -0200 | [diff] [blame] | 106 | * @streaming_count: Streaming start count - streaming stop count |
| 107 | * @graph: Media graph walk during pipeline start / stop |
Sakari Ailus | 5dd8775 | 2015-12-16 11:32:21 -0200 | [diff] [blame] | 108 | */ |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 109 | struct media_pipeline { |
Sakari Ailus | 74a4133 | 2015-12-16 11:32:29 -0200 | [diff] [blame] | 110 | int streaming_count; |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 111 | struct media_graph graph; |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 112 | }; |
| 113 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 114 | /** |
| 115 | * struct media_link - A link object part of a media graph. |
| 116 | * |
| 117 | * @graph_obj: Embedded structure containing the media object common data |
| 118 | * @list: Linked list associated with an entity or an interface that |
| 119 | * owns the link. |
| 120 | * @gobj0: Part of a union. Used to get the pointer for the first |
| 121 | * graph_object of the link. |
| 122 | * @source: Part of a union. Used only if the first object (gobj0) is |
| 123 | * a pad. In that case, it represents the source pad. |
| 124 | * @intf: Part of a union. Used only if the first object (gobj0) is |
| 125 | * an interface. |
| 126 | * @gobj1: Part of a union. Used to get the pointer for the second |
| 127 | * graph_object of the link. |
Mauro Carvalho Chehab | e383ce0 | 2016-09-22 07:59:03 -0300 | [diff] [blame] | 128 | * @sink: Part of a union. Used only if the second object (gobj1) is |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 129 | * a pad. In that case, it represents the sink pad. |
| 130 | * @entity: Part of a union. Used only if the second object (gobj1) is |
| 131 | * an entity. |
| 132 | * @reverse: Pointer to the link for the reverse direction of a pad to pad |
| 133 | * link. |
| 134 | * @flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*) |
Mauro Carvalho Chehab | 39d1ebc6 | 2015-08-30 09:53:57 -0300 | [diff] [blame] | 135 | * @is_backlink: Indicate if the link is a backlink. |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 136 | */ |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 137 | struct media_link { |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 138 | struct media_gobj graph_obj; |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 139 | struct list_head list; |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 140 | union { |
| 141 | struct media_gobj *gobj0; |
| 142 | struct media_pad *source; |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 143 | struct media_interface *intf; |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 144 | }; |
| 145 | union { |
| 146 | struct media_gobj *gobj1; |
| 147 | struct media_pad *sink; |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 148 | struct media_entity *entity; |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 149 | }; |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 150 | struct media_link *reverse; |
| 151 | unsigned long flags; |
Mauro Carvalho Chehab | 39d1ebc6 | 2015-08-30 09:53:57 -0300 | [diff] [blame] | 152 | bool is_backlink; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 153 | }; |
| 154 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 155 | /** |
| 156 | * struct media_pad - A media pad graph object. |
| 157 | * |
| 158 | * @graph_obj: Embedded structure containing the media object common data |
| 159 | * @entity: Entity this pad belongs to |
| 160 | * @index: Pad index in the entity pads array, numbered from 0 to n |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 161 | * @flags: Pad flags, as defined in |
| 162 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 163 | * (seek for ``MEDIA_PAD_FL_*``) |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 164 | */ |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 165 | struct media_pad { |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 166 | struct media_gobj graph_obj; /* must be first field in struct */ |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 167 | struct media_entity *entity; |
| 168 | u16 index; |
| 169 | unsigned long flags; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 170 | }; |
| 171 | |
Laurent Pinchart | 5a5394b | 2014-03-26 00:01:44 -0300 | [diff] [blame] | 172 | /** |
| 173 | * struct media_entity_operations - Media entity operations |
| 174 | * @link_setup: Notify the entity of link changes. The operation can |
| 175 | * return an error, in which case link setup will be |
| 176 | * cancelled. Optional. |
| 177 | * @link_validate: Return whether a link is valid from the entity point of |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 178 | * view. The media_pipeline_start() function |
Laurent Pinchart | 5a5394b | 2014-03-26 00:01:44 -0300 | [diff] [blame] | 179 | * validates all links by calling this operation. Optional. |
Mauro Carvalho Chehab | 5ed470f | 2016-04-06 10:55:25 -0300 | [diff] [blame] | 180 | * |
Mauro Carvalho Chehab | 5b8700e | 2016-07-20 09:22:38 -0300 | [diff] [blame] | 181 | * .. note:: |
| 182 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 183 | * Those these callbacks are called with struct &media_device.graph_mutex |
Mauro Carvalho Chehab | 5b8700e | 2016-07-20 09:22:38 -0300 | [diff] [blame] | 184 | * mutex held. |
Laurent Pinchart | 5a5394b | 2014-03-26 00:01:44 -0300 | [diff] [blame] | 185 | */ |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 186 | struct media_entity_operations { |
| 187 | int (*link_setup)(struct media_entity *entity, |
| 188 | const struct media_pad *local, |
| 189 | const struct media_pad *remote, u32 flags); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 190 | int (*link_validate)(struct media_link *link); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 191 | }; |
| 192 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 193 | /** |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 194 | * enum media_entity_type - Media entity type |
| 195 | * |
| 196 | * @MEDIA_ENTITY_TYPE_BASE: |
| 197 | * The entity isn't embedded in another subsystem structure. |
| 198 | * @MEDIA_ENTITY_TYPE_VIDEO_DEVICE: |
| 199 | * The entity is embedded in a struct video_device instance. |
| 200 | * @MEDIA_ENTITY_TYPE_V4L2_SUBDEV: |
| 201 | * The entity is embedded in a struct v4l2_subdev instance. |
| 202 | * |
| 203 | * Media entity objects are often not instantiated directly, but the media |
| 204 | * entity structure is inherited by (through embedding) other subsystem-specific |
| 205 | * structures. The media entity type identifies the type of the subclass |
| 206 | * structure that implements a media entity instance. |
| 207 | * |
| 208 | * This allows runtime type identification of media entities and safe casting to |
| 209 | * the correct object type. For instance, a media entity structure instance |
| 210 | * embedded in a v4l2_subdev structure instance will have the type |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 211 | * %MEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to a &v4l2_subdev |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 212 | * structure using the container_of() macro. |
| 213 | */ |
| 214 | enum media_entity_type { |
| 215 | MEDIA_ENTITY_TYPE_BASE, |
| 216 | MEDIA_ENTITY_TYPE_VIDEO_DEVICE, |
| 217 | MEDIA_ENTITY_TYPE_V4L2_SUBDEV, |
| 218 | }; |
| 219 | |
| 220 | /** |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 221 | * struct media_entity - A media entity graph object. |
| 222 | * |
| 223 | * @graph_obj: Embedded structure containing the media object common data. |
| 224 | * @name: Entity name. |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 225 | * @obj_type: Type of the object that implements the media_entity. |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 226 | * @function: Entity main function, as defined in |
| 227 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 228 | * (seek for ``MEDIA_ENT_F_*``) |
| 229 | * @flags: Entity flags, as defined in |
| 230 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 231 | * (seek for ``MEDIA_ENT_FL_*``) |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 232 | * @num_pads: Number of sink and source pads. |
| 233 | * @num_links: Total number of links, forward and back, enabled and disabled. |
| 234 | * @num_backlinks: Number of backlinks |
Sakari Ailus | 665faa9 | 2015-12-16 11:32:17 -0200 | [diff] [blame] | 235 | * @internal_idx: An unique internal entity specific number. The numbers are |
| 236 | * re-used if entities are unregistered or registered again. |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 237 | * @pads: Pads array with the size defined by @num_pads. |
| 238 | * @links: List of data links. |
| 239 | * @ops: Entity operations. |
| 240 | * @stream_count: Stream count for the entity. |
| 241 | * @use_count: Use count for the entity. |
| 242 | * @pipe: Pipeline this entity belongs to. |
| 243 | * @info: Union with devnode information. Kept just for backward |
| 244 | * compatibility. |
| 245 | * @major: Devnode major number (zero if not applicable). Kept just |
| 246 | * for backward compatibility. |
| 247 | * @minor: Devnode minor number (zero if not applicable). Kept just |
| 248 | * for backward compatibility. |
| 249 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 250 | * .. note:: |
| 251 | * |
| 252 | * @stream_count and @use_count reference counts must never be |
| 253 | * negative, but are signed integers on purpose: a simple ``WARN_ON(<0)`` |
| 254 | * check can be used to detect reference count bugs that would make them |
| 255 | * negative. |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 256 | */ |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 257 | struct media_entity { |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 258 | struct media_gobj graph_obj; /* must be first field in struct */ |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 259 | const char *name; |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 260 | enum media_entity_type obj_type; |
Mauro Carvalho Chehab | 0e576b7 | 2015-09-06 09:33:39 -0300 | [diff] [blame] | 261 | u32 function; |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 262 | unsigned long flags; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 263 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 264 | u16 num_pads; |
| 265 | u16 num_links; |
| 266 | u16 num_backlinks; |
Sakari Ailus | 665faa9 | 2015-12-16 11:32:17 -0200 | [diff] [blame] | 267 | int internal_idx; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 268 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 269 | struct media_pad *pads; |
| 270 | struct list_head links; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 271 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 272 | const struct media_entity_operations *ops; |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 273 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 274 | int stream_count; |
| 275 | int use_count; |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 276 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 277 | struct media_pipeline *pipe; |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 278 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 279 | union { |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 280 | struct { |
| 281 | u32 major; |
| 282 | u32 minor; |
Mauro Carvalho Chehab | e31a0ba | 2015-01-02 12:18:23 -0300 | [diff] [blame] | 283 | } dev; |
Clemens Ladisch | fa5034c | 2011-11-05 18:42:01 -0300 | [diff] [blame] | 284 | } info; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 285 | }; |
| 286 | |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 287 | /** |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 288 | * struct media_interface - A media interface graph object. |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 289 | * |
| 290 | * @graph_obj: embedded graph object |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 291 | * @links: List of links pointing to graph entities |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 292 | * @type: Type of the interface as defined in |
| 293 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 294 | * (seek for ``MEDIA_INTF_T_*``) |
| 295 | * @flags: Interface flags as defined in |
| 296 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 297 | * (seek for ``MEDIA_INTF_FL_*``) |
| 298 | * |
| 299 | * .. note:: |
| 300 | * |
| 301 | * Currently, no flags for &media_interface is defined. |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 302 | */ |
| 303 | struct media_interface { |
| 304 | struct media_gobj graph_obj; |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 305 | struct list_head links; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 306 | u32 type; |
| 307 | u32 flags; |
| 308 | }; |
| 309 | |
| 310 | /** |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 311 | * struct media_intf_devnode - A media interface via a device node. |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 312 | * |
| 313 | * @intf: embedded interface object |
| 314 | * @major: Major number of a device node |
| 315 | * @minor: Minor number of a device node |
| 316 | */ |
| 317 | struct media_intf_devnode { |
| 318 | struct media_interface intf; |
Mauro Carvalho Chehab | c398bb6 | 2015-08-23 08:28:21 -0300 | [diff] [blame] | 319 | |
| 320 | /* Should match the fields at media_v2_intf_devnode */ |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 321 | u32 major; |
| 322 | u32 minor; |
| 323 | }; |
| 324 | |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 325 | /** |
| 326 | * media_entity_id() - return the media entity graph object id |
| 327 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 328 | * @entity: pointer to &media_entity |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 329 | */ |
Mauro Carvalho Chehab | fa76239 | 2015-08-14 10:42:05 -0300 | [diff] [blame] | 330 | static inline u32 media_entity_id(struct media_entity *entity) |
| 331 | { |
Mauro Carvalho Chehab | bfab2aac | 2015-08-14 12:47:48 -0300 | [diff] [blame] | 332 | return entity->graph_obj.id; |
Mauro Carvalho Chehab | fa76239 | 2015-08-14 10:42:05 -0300 | [diff] [blame] | 333 | } |
| 334 | |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 335 | /** |
| 336 | * media_type() - return the media object type |
| 337 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 338 | * @gobj: Pointer to the struct &media_gobj graph object |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 339 | */ |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 340 | static inline enum media_gobj_type media_type(struct media_gobj *gobj) |
| 341 | { |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 342 | return gobj->id >> MEDIA_BITS_PER_ID; |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 343 | } |
| 344 | |
Mauro Carvalho Chehab | 630c0e8 | 2015-12-16 15:15:18 -0200 | [diff] [blame] | 345 | /** |
| 346 | * media_id() - return the media object ID |
| 347 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 348 | * @gobj: Pointer to the struct &media_gobj graph object |
Mauro Carvalho Chehab | 630c0e8 | 2015-12-16 15:15:18 -0200 | [diff] [blame] | 349 | */ |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 350 | static inline u32 media_id(struct media_gobj *gobj) |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 351 | { |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 352 | return gobj->id & MEDIA_ID_MASK; |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 353 | } |
| 354 | |
Mauro Carvalho Chehab | 630c0e8 | 2015-12-16 15:15:18 -0200 | [diff] [blame] | 355 | /** |
| 356 | * media_gobj_gen_id() - encapsulates type and ID on at the object ID |
| 357 | * |
| 358 | * @type: object type as define at enum &media_gobj_type. |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 359 | * @local_id: next ID, from struct &media_device.id. |
Mauro Carvalho Chehab | 630c0e8 | 2015-12-16 15:15:18 -0200 | [diff] [blame] | 360 | */ |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 361 | static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id) |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 362 | { |
| 363 | u32 id; |
| 364 | |
Mauro Carvalho Chehab | 05b3b77 | 2015-12-16 14:28:01 -0200 | [diff] [blame] | 365 | id = type << MEDIA_BITS_PER_ID; |
| 366 | id |= local_id & MEDIA_ID_MASK; |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 367 | |
| 368 | return id; |
| 369 | } |
| 370 | |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 371 | /** |
Laurent Pinchart | 45b4687 | 2016-02-29 08:45:45 -0300 | [diff] [blame] | 372 | * is_media_entity_v4l2_video_device() - Check if the entity is a video_device |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 373 | * @entity: pointer to entity |
| 374 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 375 | * Return: %true if the entity is an instance of a video_device object and can |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 376 | * safely be cast to a struct video_device using the container_of() macro, or |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 377 | * %false otherwise. |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 378 | */ |
Laurent Pinchart | 45b4687 | 2016-02-29 08:45:45 -0300 | [diff] [blame] | 379 | static inline bool is_media_entity_v4l2_video_device(struct media_entity *entity) |
Mauro Carvalho Chehab | fa17b46 | 2015-08-21 12:17:40 -0300 | [diff] [blame] | 380 | { |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 381 | return entity && entity->obj_type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE; |
Mauro Carvalho Chehab | fa17b46 | 2015-08-21 12:17:40 -0300 | [diff] [blame] | 382 | } |
| 383 | |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 384 | /** |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 385 | * is_media_entity_v4l2_subdev() - Check if the entity is a v4l2_subdev |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 386 | * @entity: pointer to entity |
| 387 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 388 | * Return: %true if the entity is an instance of a &v4l2_subdev object and can |
| 389 | * safely be cast to a struct &v4l2_subdev using the container_of() macro, or |
| 390 | * %false otherwise. |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 391 | */ |
Mauro Carvalho Chehab | fa17b46 | 2015-08-21 12:17:40 -0300 | [diff] [blame] | 392 | static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity) |
| 393 | { |
Laurent Pinchart | b76a2a8 | 2016-02-29 08:45:44 -0300 | [diff] [blame] | 394 | return entity && entity->obj_type == MEDIA_ENTITY_TYPE_V4L2_SUBDEV; |
Mauro Carvalho Chehab | fa17b46 | 2015-08-21 12:17:40 -0300 | [diff] [blame] | 395 | } |
| 396 | |
Mauro Carvalho Chehab | 9277799 | 2015-12-16 13:53:04 -0200 | [diff] [blame] | 397 | /** |
| 398 | * __media_entity_enum_init - Initialise an entity enumeration |
| 399 | * |
| 400 | * @ent_enum: Entity enumeration to be initialised |
| 401 | * @idx_max: Maximum number of entities in the enumeration |
| 402 | * |
| 403 | * Return: Returns zero on success or a negative error code. |
| 404 | */ |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 405 | __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum, |
| 406 | int idx_max); |
Mauro Carvalho Chehab | 9277799 | 2015-12-16 13:53:04 -0200 | [diff] [blame] | 407 | |
| 408 | /** |
| 409 | * media_entity_enum_cleanup - Release resources of an entity enumeration |
| 410 | * |
| 411 | * @ent_enum: Entity enumeration to be released |
| 412 | */ |
| 413 | void media_entity_enum_cleanup(struct media_entity_enum *ent_enum); |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 414 | |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 415 | /** |
| 416 | * media_entity_enum_zero - Clear the entire enum |
| 417 | * |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 418 | * @ent_enum: Entity enumeration to be cleared |
Mauro Carvalho Chehab | ef69ee1 | 2015-10-01 18:07:53 -0300 | [diff] [blame] | 419 | */ |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 420 | static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum) |
| 421 | { |
| 422 | bitmap_zero(ent_enum->bmap, ent_enum->idx_max); |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * media_entity_enum_set - Mark a single entity in the enum |
| 427 | * |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 428 | * @ent_enum: Entity enumeration |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 429 | * @entity: Entity to be marked |
| 430 | */ |
| 431 | static inline void media_entity_enum_set(struct media_entity_enum *ent_enum, |
| 432 | struct media_entity *entity) |
| 433 | { |
| 434 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) |
| 435 | return; |
| 436 | |
| 437 | __set_bit(entity->internal_idx, ent_enum->bmap); |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * media_entity_enum_clear - Unmark a single entity in the enum |
| 442 | * |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 443 | * @ent_enum: Entity enumeration |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 444 | * @entity: Entity to be unmarked |
| 445 | */ |
| 446 | static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum, |
| 447 | struct media_entity *entity) |
| 448 | { |
| 449 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) |
| 450 | return; |
| 451 | |
| 452 | __clear_bit(entity->internal_idx, ent_enum->bmap); |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * media_entity_enum_test - Test whether the entity is marked |
| 457 | * |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 458 | * @ent_enum: Entity enumeration |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 459 | * @entity: Entity to be tested |
| 460 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 461 | * Returns %true if the entity was marked. |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 462 | */ |
| 463 | static inline bool media_entity_enum_test(struct media_entity_enum *ent_enum, |
| 464 | struct media_entity *entity) |
| 465 | { |
| 466 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) |
| 467 | return true; |
| 468 | |
| 469 | return test_bit(entity->internal_idx, ent_enum->bmap); |
| 470 | } |
| 471 | |
| 472 | /** |
Mauro Carvalho Chehab | e383ce0 | 2016-09-22 07:59:03 -0300 | [diff] [blame] | 473 | * media_entity_enum_test_and_set - Test whether the entity is marked, |
| 474 | * and mark it |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 475 | * |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 476 | * @ent_enum: Entity enumeration |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 477 | * @entity: Entity to be tested |
| 478 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 479 | * Returns %true if the entity was marked, and mark it before doing so. |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 480 | */ |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 481 | static inline bool |
| 482 | media_entity_enum_test_and_set(struct media_entity_enum *ent_enum, |
| 483 | struct media_entity *entity) |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 484 | { |
| 485 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) |
| 486 | return true; |
| 487 | |
| 488 | return __test_and_set_bit(entity->internal_idx, ent_enum->bmap); |
| 489 | } |
| 490 | |
| 491 | /** |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 492 | * media_entity_enum_empty - Test whether the entire enum is empty |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 493 | * |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 494 | * @ent_enum: Entity enumeration |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 495 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 496 | * Return: %true if the entity was empty. |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 497 | */ |
| 498 | static inline bool media_entity_enum_empty(struct media_entity_enum *ent_enum) |
| 499 | { |
| 500 | return bitmap_empty(ent_enum->bmap, ent_enum->idx_max); |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * media_entity_enum_intersects - Test whether two enums intersect |
| 505 | * |
Mauro Carvalho Chehab | 03e4933 | 2015-12-16 13:58:31 -0200 | [diff] [blame] | 506 | * @ent_enum1: First entity enumeration |
| 507 | * @ent_enum2: Second entity enumeration |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 508 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 509 | * Return: %true if entity enumerations @ent_enum1 and @ent_enum2 intersect, |
| 510 | * otherwise %false. |
Sakari Ailus | c8d54cd | 2015-12-16 11:44:32 -0200 | [diff] [blame] | 511 | */ |
| 512 | static inline bool media_entity_enum_intersects( |
| 513 | struct media_entity_enum *ent_enum1, |
| 514 | struct media_entity_enum *ent_enum2) |
| 515 | { |
| 516 | WARN_ON(ent_enum1->idx_max != ent_enum2->idx_max); |
| 517 | |
| 518 | return bitmap_intersects(ent_enum1->bmap, ent_enum2->bmap, |
| 519 | min(ent_enum1->idx_max, ent_enum2->idx_max)); |
| 520 | } |
Mauro Carvalho Chehab | ef69ee1 | 2015-10-01 18:07:53 -0300 | [diff] [blame] | 521 | |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 522 | /** |
| 523 | * gobj_to_entity - returns the struct &media_entity pointer from the |
| 524 | * @gobj contained on it. |
| 525 | * |
| 526 | * @gobj: Pointer to the struct &media_gobj graph object |
| 527 | */ |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 528 | #define gobj_to_entity(gobj) \ |
| 529 | container_of(gobj, struct media_entity, graph_obj) |
| 530 | |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 531 | /** |
Mauro Carvalho Chehab | e383ce0 | 2016-09-22 07:59:03 -0300 | [diff] [blame] | 532 | * gobj_to_pad - returns the struct &media_pad pointer from the |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 533 | * @gobj contained on it. |
| 534 | * |
| 535 | * @gobj: Pointer to the struct &media_gobj graph object |
| 536 | */ |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 537 | #define gobj_to_pad(gobj) \ |
| 538 | container_of(gobj, struct media_pad, graph_obj) |
| 539 | |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 540 | /** |
Mauro Carvalho Chehab | e383ce0 | 2016-09-22 07:59:03 -0300 | [diff] [blame] | 541 | * gobj_to_link - returns the struct &media_link pointer from the |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 542 | * @gobj contained on it. |
| 543 | * |
| 544 | * @gobj: Pointer to the struct &media_gobj graph object |
| 545 | */ |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 546 | #define gobj_to_link(gobj) \ |
| 547 | container_of(gobj, struct media_link, graph_obj) |
| 548 | |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 549 | /** |
Mauro Carvalho Chehab | e383ce0 | 2016-09-22 07:59:03 -0300 | [diff] [blame] | 550 | * gobj_to_intf - returns the struct &media_interface pointer from the |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 551 | * @gobj contained on it. |
| 552 | * |
| 553 | * @gobj: Pointer to the struct &media_gobj graph object |
| 554 | */ |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 555 | #define gobj_to_intf(gobj) \ |
| 556 | container_of(gobj, struct media_interface, graph_obj) |
| 557 | |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 558 | /** |
Mauro Carvalho Chehab | e383ce0 | 2016-09-22 07:59:03 -0300 | [diff] [blame] | 559 | * intf_to_devnode - returns the struct media_intf_devnode pointer from the |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 560 | * @intf contained on it. |
| 561 | * |
| 562 | * @intf: Pointer to struct &media_intf_devnode |
| 563 | */ |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 564 | #define intf_to_devnode(intf) \ |
| 565 | container_of(intf, struct media_intf_devnode, intf) |
| 566 | |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 567 | /** |
| 568 | * media_gobj_create - Initialize a graph object |
| 569 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 570 | * @mdev: Pointer to the &media_device that contains the object |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 571 | * @type: Type of the object |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 572 | * @gobj: Pointer to the struct &media_gobj graph object |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 573 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 574 | * This routine initializes the embedded struct &media_gobj inside a |
| 575 | * media graph object. It is called automatically if ``media_*_create`` |
| 576 | * function calls are used. However, if the object (entity, link, pad, |
| 577 | * interface) is embedded on some other object, this function should be |
| 578 | * called before registering the object at the media controller. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 579 | */ |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 580 | void media_gobj_create(struct media_device *mdev, |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 581 | enum media_gobj_type type, |
| 582 | struct media_gobj *gobj); |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 583 | |
| 584 | /** |
| 585 | * media_gobj_destroy - Stop using a graph object on a media device |
| 586 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 587 | * @gobj: Pointer to the struct &media_gobj graph object |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 588 | * |
| 589 | * This should be called by all routines like media_device_unregister() |
| 590 | * that remove/destroy media graph objects. |
| 591 | */ |
Mauro Carvalho Chehab | c350ef8 | 2015-12-11 11:55:40 -0200 | [diff] [blame] | 592 | void media_gobj_destroy(struct media_gobj *gobj); |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 593 | |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 594 | /** |
| 595 | * media_entity_pads_init() - Initialize the entity pads |
| 596 | * |
| 597 | * @entity: entity where the pads belong |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 598 | * @num_pads: total number of sink and source pads |
| 599 | * @pads: Array of @num_pads pads. |
| 600 | * |
| 601 | * The pads array is managed by the entity driver and passed to |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 602 | * media_entity_pads_init() where its pointer will be stored in the |
| 603 | * &media_entity structure. |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 604 | * |
| 605 | * If no pads are needed, drivers could either directly fill |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 606 | * &media_entity->num_pads with 0 and &media_entity->pads with %NULL or call |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 607 | * this function that will do the same. |
| 608 | * |
| 609 | * As the number of pads is known in advance, the pads array is not allocated |
| 610 | * dynamically but is managed by the entity driver. Most drivers will embed the |
| 611 | * pads array in a driver-specific structure, avoiding dynamic allocation. |
| 612 | * |
| 613 | * Drivers must set the direction of every pad in the pads array before calling |
| 614 | * media_entity_pads_init(). The function will initialize the other pads fields. |
| 615 | */ |
Mauro Carvalho Chehab | ab22e77 | 2015-12-11 07:44:40 -0200 | [diff] [blame] | 616 | int media_entity_pads_init(struct media_entity *entity, u16 num_pads, |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 617 | struct media_pad *pads); |
Mauro Carvalho Chehab | f1fd328 | 2015-12-11 09:13:23 -0200 | [diff] [blame] | 618 | |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 619 | /** |
| 620 | * media_entity_cleanup() - free resources associated with an entity |
| 621 | * |
| 622 | * @entity: entity where the pads belong |
| 623 | * |
| 624 | * This function must be called during the cleanup phase after unregistering |
| 625 | * the entity (currently, it does nothing). |
| 626 | */ |
Mauro Carvalho Chehab | f1fd328 | 2015-12-11 09:13:23 -0200 | [diff] [blame] | 627 | static inline void media_entity_cleanup(struct media_entity *entity) {}; |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 628 | |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 629 | /** |
| 630 | * media_create_pad_link() - creates a link between two entities. |
| 631 | * |
| 632 | * @source: pointer to &media_entity of the source pad. |
| 633 | * @source_pad: number of the source pad in the pads array |
| 634 | * @sink: pointer to &media_entity of the sink pad. |
| 635 | * @sink_pad: number of the sink pad in the pads array. |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 636 | * @flags: Link flags, as defined in |
| 637 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 638 | * ( seek for ``MEDIA_LNK_FL_*``) |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 639 | * |
| 640 | * Valid values for flags: |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 641 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 642 | * %MEDIA_LNK_FL_ENABLED |
| 643 | * Indicates that the link is enabled and can be used to transfer media data. |
| 644 | * When two or more links target a sink pad, only one of them can be |
| 645 | * enabled at a time. |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 646 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 647 | * %MEDIA_LNK_FL_IMMUTABLE |
| 648 | * Indicates that the link enabled state can't be modified at runtime. If |
| 649 | * %MEDIA_LNK_FL_IMMUTABLE is set, then %MEDIA_LNK_FL_ENABLED must also be |
| 650 | * set, since an immutable link is always enabled. |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 651 | * |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 652 | * .. note:: |
| 653 | * |
| 654 | * Before calling this function, media_entity_pads_init() and |
| 655 | * media_device_register_entity() should be called previously for both ends. |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 656 | */ |
Mauro Carvalho Chehab | 7732804 | 2015-09-04 16:08:24 -0300 | [diff] [blame] | 657 | __must_check int media_create_pad_link(struct media_entity *source, |
| 658 | u16 source_pad, struct media_entity *sink, |
| 659 | u16 sink_pad, u32 flags); |
Mauro Carvalho Chehab | b01cc9c | 2015-12-30 09:45:48 -0200 | [diff] [blame] | 660 | |
| 661 | /** |
| 662 | * media_create_pad_links() - creates a link between two entities. |
| 663 | * |
| 664 | * @mdev: Pointer to the media_device that contains the object |
| 665 | * @source_function: Function of the source entities. Used only if @source is |
| 666 | * NULL. |
| 667 | * @source: pointer to &media_entity of the source pad. If NULL, it will use |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 668 | * all entities that matches the @sink_function. |
Mauro Carvalho Chehab | b01cc9c | 2015-12-30 09:45:48 -0200 | [diff] [blame] | 669 | * @source_pad: number of the source pad in the pads array |
| 670 | * @sink_function: Function of the sink entities. Used only if @sink is NULL. |
| 671 | * @sink: pointer to &media_entity of the sink pad. If NULL, it will use |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 672 | * all entities that matches the @sink_function. |
Mauro Carvalho Chehab | b01cc9c | 2015-12-30 09:45:48 -0200 | [diff] [blame] | 673 | * @sink_pad: number of the sink pad in the pads array. |
| 674 | * @flags: Link flags, as defined in include/uapi/linux/media.h. |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 675 | * @allow_both_undefined: if %true, then both @source and @sink can be NULL. |
Mauro Carvalho Chehab | b01cc9c | 2015-12-30 09:45:48 -0200 | [diff] [blame] | 676 | * In such case, it will create a crossbar between all entities that |
| 677 | * matches @source_function to all entities that matches @sink_function. |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 678 | * If %false, it will return 0 and won't create any link if both @source |
Mauro Carvalho Chehab | b01cc9c | 2015-12-30 09:45:48 -0200 | [diff] [blame] | 679 | * and @sink are NULL. |
| 680 | * |
| 681 | * Valid values for flags: |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 682 | * |
Mauro Carvalho Chehab | b01cc9c | 2015-12-30 09:45:48 -0200 | [diff] [blame] | 683 | * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be |
| 684 | * used to transfer media data. If multiple links are created and this |
| 685 | * flag is passed as an argument, only the first created link will have |
| 686 | * this flag. |
| 687 | * |
| 688 | * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't |
| 689 | * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then |
| 690 | * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is |
| 691 | * always enabled. |
| 692 | * |
| 693 | * It is common for some devices to have multiple source and/or sink entities |
| 694 | * of the same type that should be linked. While media_create_pad_link() |
| 695 | * creates link by link, this function is meant to allow 1:n, n:1 and even |
| 696 | * cross-bar (n:n) links. |
| 697 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 698 | * .. note:: |
| 699 | * |
| 700 | * Before calling this function, media_entity_pads_init() and |
| 701 | * media_device_register_entity() should be called previously for the |
| 702 | * entities to be linked. |
Mauro Carvalho Chehab | b01cc9c | 2015-12-30 09:45:48 -0200 | [diff] [blame] | 703 | */ |
| 704 | int media_create_pad_links(const struct media_device *mdev, |
| 705 | const u32 source_function, |
| 706 | struct media_entity *source, |
| 707 | const u16 source_pad, |
| 708 | const u32 sink_function, |
| 709 | struct media_entity *sink, |
| 710 | const u16 sink_pad, |
| 711 | u32 flags, |
| 712 | const bool allow_both_undefined); |
| 713 | |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 714 | void __media_entity_remove_links(struct media_entity *entity); |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 715 | |
| 716 | /** |
| 717 | * media_entity_remove_links() - remove all links associated with an entity |
| 718 | * |
| 719 | * @entity: pointer to &media_entity |
| 720 | * |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 721 | * .. note:: |
| 722 | * |
| 723 | * This is called automatically when an entity is unregistered via |
| 724 | * media_device_register_entity(). |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 725 | */ |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 726 | void media_entity_remove_links(struct media_entity *entity); |
| 727 | |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 728 | /** |
| 729 | * __media_entity_setup_link - Configure a media link without locking |
| 730 | * @link: The link being configured |
| 731 | * @flags: Link configuration flags |
| 732 | * |
| 733 | * The bulk of link setup is handled by the two entities connected through the |
| 734 | * link. This function notifies both entities of the link configuration change. |
| 735 | * |
| 736 | * If the link is immutable or if the current and new configuration are |
| 737 | * identical, return immediately. |
| 738 | * |
| 739 | * The user is expected to hold link->source->parent->mutex. If not, |
| 740 | * media_entity_setup_link() should be used instead. |
| 741 | */ |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 742 | int __media_entity_setup_link(struct media_link *link, u32 flags); |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 743 | |
| 744 | /** |
| 745 | * media_entity_setup_link() - changes the link flags properties in runtime |
| 746 | * |
| 747 | * @link: pointer to &media_link |
| 748 | * @flags: the requested new link flags |
| 749 | * |
| 750 | * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag |
| 751 | * flag to enable/disable a link. Links marked with the |
| 752 | * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled. |
| 753 | * |
| 754 | * When a link is enabled or disabled, the media framework calls the |
| 755 | * link_setup operation for the two entities at the source and sink of the |
| 756 | * link, in that order. If the second link_setup call fails, another |
| 757 | * link_setup call is made on the first entity to restore the original link |
| 758 | * flags. |
| 759 | * |
| 760 | * Media device drivers can be notified of link setup operations by setting the |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 761 | * &media_device.link_notify pointer to a callback function. If provided, the |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 762 | * notification callback will be called before enabling and after disabling |
| 763 | * links. |
| 764 | * |
| 765 | * Entity drivers must implement the link_setup operation if any of their links |
| 766 | * is non-immutable. The operation must either configure the hardware or store |
| 767 | * the configuration information to be applied later. |
| 768 | * |
| 769 | * Link configuration must not have any side effect on other links. If an |
| 770 | * enabled link at a sink pad prevents another link at the same pad from |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 771 | * being enabled, the link_setup operation must return %-EBUSY and can't |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 772 | * implicitly disable the first enabled link. |
| 773 | * |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 774 | * .. note:: |
| 775 | * |
| 776 | * The valid values of the flags for the link is the same as described |
| 777 | * on media_create_pad_link(), for pad to pad links or the same as described |
| 778 | * on media_create_intf_link(), for interface to entity links. |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 779 | */ |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 780 | int media_entity_setup_link(struct media_link *link, u32 flags); |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 781 | |
| 782 | /** |
| 783 | * media_entity_find_link - Find a link between two pads |
| 784 | * @source: Source pad |
| 785 | * @sink: Sink pad |
| 786 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 787 | * Return: returns a pointer to the link between the two entities. If no |
| 788 | * such link exists, return %NULL. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 789 | */ |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 790 | struct media_link *media_entity_find_link(struct media_pad *source, |
| 791 | struct media_pad *sink); |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 792 | |
| 793 | /** |
| 794 | * media_entity_remote_pad - Find the pad at the remote end of a link |
| 795 | * @pad: Pad at the local end of the link |
| 796 | * |
| 797 | * Search for a remote pad connected to the given pad by iterating over all |
| 798 | * links originating or terminating at that pad until an enabled link is found. |
| 799 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 800 | * Return: returns a pointer to the pad at the remote end of the first found |
| 801 | * enabled link, or %NULL if no enabled link has been found. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 802 | */ |
Andrzej Hajda | 1bddf1b | 2013-06-03 05:16:13 -0300 | [diff] [blame] | 803 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 804 | |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 805 | /** |
| 806 | * media_entity_get - Get a reference to the parent module |
| 807 | * |
| 808 | * @entity: The entity |
| 809 | * |
| 810 | * Get a reference to the parent media device module. |
| 811 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 812 | * The function will return immediately if @entity is %NULL. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 813 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 814 | * Return: returns a pointer to the entity on success or %NULL on failure. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 815 | */ |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 816 | struct media_entity *media_entity_get(struct media_entity *entity); |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 817 | |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 818 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 819 | * media_graph_walk_init - Allocate resources used by graph walk. |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 820 | * |
| 821 | * @graph: Media graph structure that will be used to walk the graph |
| 822 | * @mdev: Pointer to the &media_device that contains the object |
| 823 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 824 | __must_check int media_graph_walk_init( |
| 825 | struct media_graph *graph, struct media_device *mdev); |
Mauro Carvalho Chehab | aa360d3 | 2015-12-16 13:56:14 -0200 | [diff] [blame] | 826 | |
| 827 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 828 | * media_graph_walk_cleanup - Release resources used by graph walk. |
Mauro Carvalho Chehab | aa360d3 | 2015-12-16 13:56:14 -0200 | [diff] [blame] | 829 | * |
| 830 | * @graph: Media graph structure that will be used to walk the graph |
| 831 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 832 | void media_graph_walk_cleanup(struct media_graph *graph); |
Sakari Ailus | e03d220 | 2015-12-16 11:32:22 -0200 | [diff] [blame] | 833 | |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 834 | /** |
| 835 | * media_entity_put - Release the reference to the parent module |
| 836 | * |
| 837 | * @entity: The entity |
| 838 | * |
| 839 | * Release the reference count acquired by media_entity_get(). |
| 840 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 841 | * The function will return immediately if @entity is %NULL. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 842 | */ |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 843 | void media_entity_put(struct media_entity *entity); |
| 844 | |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 845 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 846 | * media_graph_walk_start - Start walking the media graph at a |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 847 | * given entity |
| 848 | * |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 849 | * @graph: Media graph structure that will be used to walk the graph |
| 850 | * @entity: Starting entity |
| 851 | * |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 852 | * Before using this function, media_graph_walk_init() must be |
Sakari Ailus | e03d220 | 2015-12-16 11:32:22 -0200 | [diff] [blame] | 853 | * used to allocate resources used for walking the graph. This |
| 854 | * function initializes the graph traversal structure to walk the |
| 855 | * entities graph starting at the given entity. The traversal |
| 856 | * structure must not be modified by the caller during graph |
| 857 | * traversal. After the graph walk, the resources must be released |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 858 | * using media_graph_walk_cleanup(). |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 859 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 860 | void media_graph_walk_start(struct media_graph *graph, |
| 861 | struct media_entity *entity); |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 862 | |
| 863 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 864 | * media_graph_walk_next - Get the next entity in the graph |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 865 | * @graph: Media graph structure |
| 866 | * |
| 867 | * Perform a depth-first traversal of the given media entities graph. |
| 868 | * |
| 869 | * The graph structure must have been previously initialized with a call to |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 870 | * media_graph_walk_start(). |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 871 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 872 | * Return: returns the next entity in the graph or %NULL if the whole graph |
| 873 | * have been traversed. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 874 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 875 | struct media_entity *media_graph_walk_next(struct media_graph *graph); |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 876 | |
| 877 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 878 | * media_pipeline_start - Mark a pipeline as streaming |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 879 | * @entity: Starting entity |
| 880 | * @pipe: Media pipeline to be assigned to all entities in the pipeline. |
| 881 | * |
| 882 | * Mark all entities connected to a given entity through enabled links, either |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 883 | * directly or indirectly, as streaming. The given pipeline object is assigned |
| 884 | * to every entity in the pipeline and stored in the media_entity pipe field. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 885 | * |
| 886 | * Calls to this function can be nested, in which case the same number of |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 887 | * media_pipeline_stop() calls will be required to stop streaming. The |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 888 | * pipeline pointer must be identical for all nested calls to |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 889 | * media_pipeline_start(). |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 890 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 891 | __must_check int media_pipeline_start(struct media_entity *entity, |
| 892 | struct media_pipeline *pipe); |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 893 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 894 | * __media_pipeline_start - Mark a pipeline as streaming |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 895 | * |
| 896 | * @entity: Starting entity |
| 897 | * @pipe: Media pipeline to be assigned to all entities in the pipeline. |
| 898 | * |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 899 | * ..note:: This is the non-locking version of media_pipeline_start() |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 900 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 901 | __must_check int __media_pipeline_start(struct media_entity *entity, |
| 902 | struct media_pipeline *pipe); |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 903 | |
| 904 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 905 | * media_pipeline_stop - Mark a pipeline as not streaming |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 906 | * @entity: Starting entity |
| 907 | * |
| 908 | * Mark all entities connected to a given entity through enabled links, either |
| 909 | * directly or indirectly, as not streaming. The media_entity pipe field is |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 910 | * reset to %NULL. |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 911 | * |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 912 | * If multiple calls to media_pipeline_start() have been made, the same |
Mauro Carvalho Chehab | 1fc25d3 | 2015-12-11 12:14:58 -0200 | [diff] [blame] | 913 | * number of calls to this function are required to mark the pipeline as not |
| 914 | * streaming. |
| 915 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 916 | void media_pipeline_stop(struct media_entity *entity); |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 917 | |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 918 | /** |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 919 | * __media_pipeline_stop - Mark a pipeline as not streaming |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 920 | * |
| 921 | * @entity: Starting entity |
| 922 | * |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 923 | * .. note:: This is the non-locking version of media_pipeline_stop() |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 924 | */ |
Sakari Ailus | 20b8522 | 2016-11-21 14:48:30 -0200 | [diff] [blame] | 925 | void __media_pipeline_stop(struct media_entity *entity); |
Shuah Khan | fb49f20 | 2016-02-11 21:41:24 -0200 | [diff] [blame] | 926 | |
| 927 | /** |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 928 | * media_devnode_create() - creates and initializes a device node interface |
| 929 | * |
| 930 | * @mdev: pointer to struct &media_device |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 931 | * @type: type of the interface, as given by |
| 932 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 933 | * ( seek for ``MEDIA_INTF_T_*``) macros. |
| 934 | * @flags: Interface flags, as defined in |
| 935 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 936 | * ( seek for ``MEDIA_INTF_FL_*``) |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 937 | * @major: Device node major number. |
| 938 | * @minor: Device node minor number. |
| 939 | * |
| 940 | * Return: if succeeded, returns a pointer to the newly allocated |
| 941 | * &media_intf_devnode pointer. |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 942 | * |
| 943 | * .. note:: |
| 944 | * |
| 945 | * Currently, no flags for &media_interface is defined. |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 946 | */ |
Mauro Carvalho Chehab | 5e5387d | 2015-09-04 15:34:19 -0300 | [diff] [blame] | 947 | struct media_intf_devnode * |
| 948 | __must_check media_devnode_create(struct media_device *mdev, |
| 949 | u32 type, u32 flags, |
Mauro Carvalho Chehab | 0b3b72df9 | 2015-09-09 08:19:25 -0300 | [diff] [blame] | 950 | u32 major, u32 minor); |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 951 | /** |
| 952 | * media_devnode_remove() - removes a device node interface |
| 953 | * |
| 954 | * @devnode: pointer to &media_intf_devnode to be freed. |
| 955 | * |
| 956 | * When a device node interface is removed, all links to it are automatically |
| 957 | * removed. |
| 958 | */ |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 959 | void media_devnode_remove(struct media_intf_devnode *devnode); |
Mauro Carvalho Chehab | 5e5387d | 2015-09-04 15:34:19 -0300 | [diff] [blame] | 960 | struct media_link * |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 961 | |
| 962 | /** |
| 963 | * media_create_intf_link() - creates a link between an entity and an interface |
| 964 | * |
| 965 | * @entity: pointer to %media_entity |
| 966 | * @intf: pointer to %media_interface |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 967 | * @flags: Link flags, as defined in |
| 968 | * :ref:`include/uapi/linux/media.h <media_header>` |
| 969 | * ( seek for ``MEDIA_LNK_FL_*``) |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 970 | * |
| 971 | * |
| 972 | * Valid values for flags: |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 973 | * |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 974 | * %MEDIA_LNK_FL_ENABLED |
| 975 | * Indicates that the interface is connected to the entity hardware. |
| 976 | * That's the default value for interfaces. An interface may be disabled if |
| 977 | * the hardware is busy due to the usage of some other interface that it is |
| 978 | * currently controlling the hardware. |
| 979 | * |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 980 | * A typical example is an hybrid TV device that handle only one type of |
| 981 | * stream on a given time. So, when the digital TV is streaming, |
| 982 | * the V4L2 interfaces won't be enabled, as such device is not able to |
| 983 | * also stream analog TV or radio. |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 984 | * |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 985 | * .. note:: |
| 986 | * |
| 987 | * Before calling this function, media_devnode_create() should be called for |
| 988 | * the interface and media_device_register_entity() should be called for the |
| 989 | * interface that will be part of the link. |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 990 | */ |
Mauro Carvalho Chehab | 5e5387d | 2015-09-04 15:34:19 -0300 | [diff] [blame] | 991 | __must_check media_create_intf_link(struct media_entity *entity, |
| 992 | struct media_interface *intf, |
| 993 | u32 flags); |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 994 | /** |
| 995 | * __media_remove_intf_link() - remove a single interface link |
| 996 | * |
| 997 | * @link: pointer to &media_link. |
| 998 | * |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 999 | * .. note:: This is an unlocked version of media_remove_intf_link() |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 1000 | */ |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 1001 | void __media_remove_intf_link(struct media_link *link); |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 1002 | |
| 1003 | /** |
| 1004 | * media_remove_intf_link() - remove a single interface link |
| 1005 | * |
| 1006 | * @link: pointer to &media_link. |
| 1007 | * |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 1008 | * .. note:: Prefer to use this one, instead of __media_remove_intf_link() |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 1009 | */ |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 1010 | void media_remove_intf_link(struct media_link *link); |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 1011 | |
| 1012 | /** |
| 1013 | * __media_remove_intf_links() - remove all links associated with an interface |
| 1014 | * |
| 1015 | * @intf: pointer to &media_interface |
| 1016 | * |
Mauro Carvalho Chehab | 74604b7 | 2016-07-17 09:18:03 -0300 | [diff] [blame] | 1017 | * .. note:: This is an unlocked version of media_remove_intf_links(). |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 1018 | */ |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 1019 | void __media_remove_intf_links(struct media_interface *intf); |
Mauro Carvalho Chehab | 9277799 | 2015-12-16 13:53:04 -0200 | [diff] [blame] | 1020 | |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 1021 | /** |
| 1022 | * media_remove_intf_links() - remove all links associated with an interface |
| 1023 | * |
| 1024 | * @intf: pointer to &media_interface |
| 1025 | * |
Mauro Carvalho Chehab | f58cad2 | 2016-07-20 11:15:31 -0300 | [diff] [blame] | 1026 | * .. note:: |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 1027 | * |
Mauro Carvalho Chehab | f58cad2 | 2016-07-20 11:15:31 -0300 | [diff] [blame] | 1028 | * #) This is called automatically when an entity is unregistered via |
| 1029 | * media_device_register_entity() and by media_devnode_remove(). |
Mauro Carvalho Chehab | 6026618 | 2015-12-13 08:20:46 -0200 | [diff] [blame] | 1030 | * |
Mauro Carvalho Chehab | f58cad2 | 2016-07-20 11:15:31 -0300 | [diff] [blame] | 1031 | * #) Prefer to use this one, instead of __media_remove_intf_links(). |
Mauro Carvalho Chehab | db7ee32 | 2015-12-11 11:06:08 -0200 | [diff] [blame] | 1032 | */ |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 1033 | void media_remove_intf_links(struct media_interface *intf); |
| 1034 | |
Mauro Carvalho Chehab | 48a7c4b | 2016-08-29 16:09:11 -0300 | [diff] [blame] | 1035 | /** |
| 1036 | * media_entity_call - Calls a struct media_entity_operations operation on |
| 1037 | * an entity |
| 1038 | * |
| 1039 | * @entity: entity where the @operation will be called |
| 1040 | * @operation: type of the operation. Should be the name of a member of |
| 1041 | * struct &media_entity_operations. |
| 1042 | * |
| 1043 | * This helper function will check if @operation is not %NULL. On such case, |
| 1044 | * it will issue a call to @operation\(@entity, @args\). |
| 1045 | */ |
| 1046 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 1047 | #define media_entity_call(entity, operation, args...) \ |
| 1048 | (((entity)->ops && (entity)->ops->operation) ? \ |
| 1049 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) |
| 1050 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 1051 | #endif |