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