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