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