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 | |
Laurent Pinchart | 5c7b25b | 2013-06-07 12:45:11 -0300 | [diff] [blame] | 26 | #include <linux/bitops.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 | |
| 74 | |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 75 | struct media_pipeline { |
| 76 | }; |
| 77 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 78 | /** |
| 79 | * struct media_link - A link object part of a media graph. |
| 80 | * |
| 81 | * @graph_obj: Embedded structure containing the media object common data |
| 82 | * @list: Linked list associated with an entity or an interface that |
| 83 | * owns the link. |
| 84 | * @gobj0: Part of a union. Used to get the pointer for the first |
| 85 | * graph_object of the link. |
| 86 | * @source: Part of a union. Used only if the first object (gobj0) is |
| 87 | * a pad. In that case, it represents the source pad. |
| 88 | * @intf: Part of a union. Used only if the first object (gobj0) is |
| 89 | * an interface. |
| 90 | * @gobj1: Part of a union. Used to get the pointer for the second |
| 91 | * graph_object of the link. |
| 92 | * @source: Part of a union. Used only if the second object (gobj1) is |
| 93 | * a pad. In that case, it represents the sink pad. |
| 94 | * @entity: Part of a union. Used only if the second object (gobj1) is |
| 95 | * an entity. |
| 96 | * @reverse: Pointer to the link for the reverse direction of a pad to pad |
| 97 | * link. |
| 98 | * @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] | 99 | * @is_backlink: Indicate if the link is a backlink. |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 100 | */ |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 101 | struct media_link { |
Mauro Carvalho Chehab | 6b6a427 | 2015-08-14 12:54:36 -0300 | [diff] [blame] | 102 | struct media_gobj graph_obj; |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 103 | struct list_head list; |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 104 | union { |
| 105 | struct media_gobj *gobj0; |
| 106 | struct media_pad *source; |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 107 | struct media_interface *intf; |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 108 | }; |
| 109 | union { |
| 110 | struct media_gobj *gobj1; |
| 111 | struct media_pad *sink; |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 112 | struct media_entity *entity; |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 113 | }; |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 114 | struct media_link *reverse; |
| 115 | unsigned long flags; |
Mauro Carvalho Chehab | 39d1ebc6 | 2015-08-30 09:53:57 -0300 | [diff] [blame] | 116 | bool is_backlink; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 117 | }; |
| 118 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 119 | /** |
| 120 | * struct media_pad - A media pad graph object. |
| 121 | * |
| 122 | * @graph_obj: Embedded structure containing the media object common data |
| 123 | * @entity: Entity this pad belongs to |
| 124 | * @index: Pad index in the entity pads array, numbered from 0 to n |
| 125 | * @flags: Pad flags, as defined in uapi/media.h (MEDIA_PAD_FL_*) |
| 126 | */ |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 127 | struct media_pad { |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 128 | struct media_gobj graph_obj; /* must be first field in struct */ |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 129 | struct media_entity *entity; |
| 130 | u16 index; |
| 131 | unsigned long flags; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 132 | }; |
| 133 | |
Laurent Pinchart | 5a5394b | 2014-03-26 00:01:44 -0300 | [diff] [blame] | 134 | /** |
| 135 | * struct media_entity_operations - Media entity operations |
| 136 | * @link_setup: Notify the entity of link changes. The operation can |
| 137 | * return an error, in which case link setup will be |
| 138 | * cancelled. Optional. |
| 139 | * @link_validate: Return whether a link is valid from the entity point of |
| 140 | * view. The media_entity_pipeline_start() function |
| 141 | * validates all links by calling this operation. Optional. |
| 142 | */ |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 143 | struct media_entity_operations { |
| 144 | int (*link_setup)(struct media_entity *entity, |
| 145 | const struct media_pad *local, |
| 146 | const struct media_pad *remote, u32 flags); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 147 | int (*link_validate)(struct media_link *link); |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 148 | }; |
| 149 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 150 | /** |
| 151 | * struct media_entity - A media entity graph object. |
| 152 | * |
| 153 | * @graph_obj: Embedded structure containing the media object common data. |
| 154 | * @name: Entity name. |
Mauro Carvalho Chehab | 0e576b7 | 2015-09-06 09:33:39 -0300 | [diff] [blame^] | 155 | * @function: Entity main function, as defined in uapi/media.h |
| 156 | * (MEDIA_ENT_F_*) |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 157 | * @revision: Entity revision - OBSOLETE - should be removed soon. |
| 158 | * @flags: Entity flags, as defined in uapi/media.h (MEDIA_ENT_FL_*) |
| 159 | * @group_id: Entity group ID - OBSOLETE - should be removed soon. |
| 160 | * @num_pads: Number of sink and source pads. |
| 161 | * @num_links: Total number of links, forward and back, enabled and disabled. |
| 162 | * @num_backlinks: Number of backlinks |
| 163 | * @pads: Pads array with the size defined by @num_pads. |
| 164 | * @links: List of data links. |
| 165 | * @ops: Entity operations. |
| 166 | * @stream_count: Stream count for the entity. |
| 167 | * @use_count: Use count for the entity. |
| 168 | * @pipe: Pipeline this entity belongs to. |
| 169 | * @info: Union with devnode information. Kept just for backward |
| 170 | * compatibility. |
| 171 | * @major: Devnode major number (zero if not applicable). Kept just |
| 172 | * for backward compatibility. |
| 173 | * @minor: Devnode minor number (zero if not applicable). Kept just |
| 174 | * for backward compatibility. |
| 175 | * |
| 176 | * NOTE: @stream_count and @use_count reference counts must never be |
| 177 | * negative, but are signed integers on purpose: a simple WARN_ON(<0) check |
| 178 | * can be used to detect reference count bugs that would make them negative. |
| 179 | */ |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 180 | struct media_entity { |
Mauro Carvalho Chehab | 4b8a3c0 | 2015-08-20 09:10:07 -0300 | [diff] [blame] | 181 | struct media_gobj graph_obj; /* must be first field in struct */ |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 182 | const char *name; |
Mauro Carvalho Chehab | 0e576b7 | 2015-09-06 09:33:39 -0300 | [diff] [blame^] | 183 | u32 function; |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 184 | u32 revision; |
| 185 | unsigned long flags; |
| 186 | u32 group_id; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 187 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 188 | u16 num_pads; |
| 189 | u16 num_links; |
| 190 | u16 num_backlinks; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 191 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 192 | struct media_pad *pads; |
| 193 | struct list_head links; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 194 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 195 | const struct media_entity_operations *ops; |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 196 | |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 197 | /* Reference counts must never be negative, but are signed integers on |
| 198 | * purpose: a simple WARN_ON(<0) check can be used to detect reference |
| 199 | * count bugs that would make them negative. |
| 200 | */ |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 201 | int stream_count; |
| 202 | int use_count; |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 203 | |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 204 | struct media_pipeline *pipe; |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 205 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 206 | union { |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 207 | struct { |
| 208 | u32 major; |
| 209 | u32 minor; |
Mauro Carvalho Chehab | e31a0ba | 2015-01-02 12:18:23 -0300 | [diff] [blame] | 210 | } dev; |
Clemens Ladisch | fa5034c | 2011-11-05 18:42:01 -0300 | [diff] [blame] | 211 | } info; |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 212 | }; |
| 213 | |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 214 | /** |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 215 | * struct media_interface - A media interface graph object. |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 216 | * |
| 217 | * @graph_obj: embedded graph object |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 218 | * @links: List of links pointing to graph entities |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 219 | * @type: Type of the interface as defined in the |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 220 | * uapi/media/media.h header, e. g. |
| 221 | * MEDIA_INTF_T_* |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 222 | * @flags: Interface flags as defined in uapi/media/media.h |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 223 | */ |
| 224 | struct media_interface { |
| 225 | struct media_gobj graph_obj; |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 226 | struct list_head links; |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 227 | u32 type; |
| 228 | u32 flags; |
| 229 | }; |
| 230 | |
| 231 | /** |
Mauro Carvalho Chehab | c358e80 | 2015-08-29 23:43:03 -0300 | [diff] [blame] | 232 | * struct media_intf_devnode - A media interface via a device node. |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 233 | * |
| 234 | * @intf: embedded interface object |
| 235 | * @major: Major number of a device node |
| 236 | * @minor: Minor number of a device node |
| 237 | */ |
| 238 | struct media_intf_devnode { |
| 239 | struct media_interface intf; |
Mauro Carvalho Chehab | c398bb6 | 2015-08-23 08:28:21 -0300 | [diff] [blame] | 240 | |
| 241 | /* Should match the fields at media_v2_intf_devnode */ |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 242 | u32 major; |
| 243 | u32 minor; |
| 244 | }; |
| 245 | |
Mauro Carvalho Chehab | fa76239 | 2015-08-14 10:42:05 -0300 | [diff] [blame] | 246 | static inline u32 media_entity_id(struct media_entity *entity) |
| 247 | { |
Mauro Carvalho Chehab | bfab2aac | 2015-08-14 12:47:48 -0300 | [diff] [blame] | 248 | return entity->graph_obj.id; |
Mauro Carvalho Chehab | fa76239 | 2015-08-14 10:42:05 -0300 | [diff] [blame] | 249 | } |
| 250 | |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 251 | static inline enum media_gobj_type media_type(struct media_gobj *gobj) |
| 252 | { |
| 253 | return gobj->id >> MEDIA_BITS_PER_LOCAL_ID; |
| 254 | } |
| 255 | |
| 256 | static inline u32 media_localid(struct media_gobj *gobj) |
| 257 | { |
| 258 | return gobj->id & MEDIA_LOCAL_ID_MASK; |
| 259 | } |
| 260 | |
| 261 | static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id) |
| 262 | { |
| 263 | u32 id; |
| 264 | |
| 265 | id = type << MEDIA_BITS_PER_LOCAL_ID; |
| 266 | id |= local_id & MEDIA_LOCAL_ID_MASK; |
| 267 | |
| 268 | return id; |
| 269 | } |
| 270 | |
Mauro Carvalho Chehab | fa17b46 | 2015-08-21 12:17:40 -0300 | [diff] [blame] | 271 | static inline bool is_media_entity_v4l2_io(struct media_entity *entity) |
| 272 | { |
| 273 | if (!entity) |
| 274 | return false; |
| 275 | |
Mauro Carvalho Chehab | 0e576b7 | 2015-09-06 09:33:39 -0300 | [diff] [blame^] | 276 | switch (entity->function) { |
Mauro Carvalho Chehab | fa17b46 | 2015-08-21 12:17:40 -0300 | [diff] [blame] | 277 | case MEDIA_ENT_T_V4L2_VIDEO: |
| 278 | case MEDIA_ENT_T_V4L2_VBI: |
| 279 | case MEDIA_ENT_T_V4L2_SWRADIO: |
| 280 | return true; |
| 281 | default: |
| 282 | return false; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity) |
| 287 | { |
| 288 | if (!entity) |
| 289 | return false; |
| 290 | |
Mauro Carvalho Chehab | 0e576b7 | 2015-09-06 09:33:39 -0300 | [diff] [blame^] | 291 | switch (entity->function) { |
Mauro Carvalho Chehab | fa17b46 | 2015-08-21 12:17:40 -0300 | [diff] [blame] | 292 | case MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN: |
| 293 | case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR: |
| 294 | case MEDIA_ENT_T_V4L2_SUBDEV_FLASH: |
| 295 | case MEDIA_ENT_T_V4L2_SUBDEV_LENS: |
| 296 | case MEDIA_ENT_T_V4L2_SUBDEV_DECODER: |
| 297 | case MEDIA_ENT_T_V4L2_SUBDEV_TUNER: |
| 298 | return true; |
| 299 | |
| 300 | default: |
| 301 | return false; |
| 302 | } |
| 303 | } |
| 304 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 305 | #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 |
Laurent Pinchart | 5c7b25b | 2013-06-07 12:45:11 -0300 | [diff] [blame] | 306 | #define MEDIA_ENTITY_ENUM_MAX_ID 64 |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 307 | |
Mauro Carvalho Chehab | ef69ee1 | 2015-10-01 18:07:53 -0300 | [diff] [blame] | 308 | /* |
| 309 | * The number of pads can't be bigger than the number of entities, |
| 310 | * as the worse-case scenario is to have one entity linked up to |
| 311 | * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities. |
| 312 | */ |
| 313 | #define MEDIA_ENTITY_MAX_PADS (MEDIA_ENTITY_ENUM_MAX_ID - 1) |
| 314 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 315 | struct media_entity_graph { |
| 316 | struct { |
| 317 | struct media_entity *entity; |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 318 | struct list_head *link; |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 319 | } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; |
Laurent Pinchart | 5c7b25b | 2013-06-07 12:45:11 -0300 | [diff] [blame] | 320 | |
| 321 | DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID); |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 322 | int top; |
| 323 | }; |
| 324 | |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 325 | #define gobj_to_entity(gobj) \ |
| 326 | container_of(gobj, struct media_entity, graph_obj) |
| 327 | |
Mauro Carvalho Chehab | 39a956c | 2015-08-13 14:42:42 -0300 | [diff] [blame] | 328 | #define gobj_to_pad(gobj) \ |
| 329 | container_of(gobj, struct media_pad, graph_obj) |
| 330 | |
| 331 | #define gobj_to_link(gobj) \ |
| 332 | container_of(gobj, struct media_link, graph_obj) |
| 333 | |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 334 | #define gobj_to_link(gobj) \ |
| 335 | container_of(gobj, struct media_link, graph_obj) |
| 336 | |
| 337 | #define gobj_to_pad(gobj) \ |
| 338 | container_of(gobj, struct media_pad, graph_obj) |
| 339 | |
| 340 | #define gobj_to_intf(gobj) \ |
| 341 | container_of(gobj, struct media_interface, graph_obj) |
| 342 | |
| 343 | #define intf_to_devnode(intf) \ |
| 344 | container_of(intf, struct media_intf_devnode, intf) |
| 345 | |
Mauro Carvalho Chehab | ec6e4c9 | 2015-08-25 10:28:36 -0300 | [diff] [blame] | 346 | void media_gobj_init(struct media_device *mdev, |
| 347 | enum media_gobj_type type, |
| 348 | struct media_gobj *gobj); |
| 349 | void media_gobj_remove(struct media_gobj *gobj); |
| 350 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 351 | int media_entity_init(struct media_entity *entity, u16 num_pads, |
Mauro Carvalho Chehab | 57208e5 | 2015-08-07 06:55:40 -0300 | [diff] [blame] | 352 | struct media_pad *pads); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 353 | void media_entity_cleanup(struct media_entity *entity); |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 354 | |
Mauro Carvalho Chehab | 7732804 | 2015-09-04 16:08:24 -0300 | [diff] [blame] | 355 | __must_check int media_create_pad_link(struct media_entity *source, |
| 356 | u16 source_pad, struct media_entity *sink, |
| 357 | u16 sink_pad, u32 flags); |
Sylwester Nawrocki | 7349cec | 2013-05-09 08:29:32 -0300 | [diff] [blame] | 358 | void __media_entity_remove_links(struct media_entity *entity); |
| 359 | void media_entity_remove_links(struct media_entity *entity); |
| 360 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 361 | int __media_entity_setup_link(struct media_link *link, u32 flags); |
| 362 | int media_entity_setup_link(struct media_link *link, u32 flags); |
| 363 | struct media_link *media_entity_find_link(struct media_pad *source, |
| 364 | struct media_pad *sink); |
Andrzej Hajda | 1bddf1b | 2013-06-03 05:16:13 -0300 | [diff] [blame] | 365 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 366 | |
Laurent Pinchart | 503c3d82 | 2010-03-07 15:04:59 -0300 | [diff] [blame] | 367 | struct media_entity *media_entity_get(struct media_entity *entity); |
| 368 | void media_entity_put(struct media_entity *entity); |
| 369 | |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 370 | void media_entity_graph_walk_start(struct media_entity_graph *graph, |
| 371 | struct media_entity *entity); |
| 372 | struct media_entity * |
| 373 | media_entity_graph_walk_next(struct media_entity_graph *graph); |
Sakari Ailus | af88be3 | 2012-01-11 06:25:15 -0300 | [diff] [blame] | 374 | __must_check int media_entity_pipeline_start(struct media_entity *entity, |
| 375 | struct media_pipeline *pipe); |
Laurent Pinchart | e02188c | 2010-08-25 09:00:41 -0300 | [diff] [blame] | 376 | void media_entity_pipeline_stop(struct media_entity *entity); |
Sakari Ailus | a5ccc48 | 2010-03-07 16:14:14 -0300 | [diff] [blame] | 377 | |
Mauro Carvalho Chehab | 5e5387d | 2015-09-04 15:34:19 -0300 | [diff] [blame] | 378 | struct media_intf_devnode * |
| 379 | __must_check media_devnode_create(struct media_device *mdev, |
| 380 | u32 type, u32 flags, |
| 381 | u32 major, u32 minor, |
| 382 | gfp_t gfp_flags); |
Mauro Carvalho Chehab | 27e543f | 2015-08-20 09:07:34 -0300 | [diff] [blame] | 383 | void media_devnode_remove(struct media_intf_devnode *devnode); |
Mauro Carvalho Chehab | 5e5387d | 2015-09-04 15:34:19 -0300 | [diff] [blame] | 384 | struct media_link * |
| 385 | __must_check media_create_intf_link(struct media_entity *entity, |
| 386 | struct media_interface *intf, |
| 387 | u32 flags); |
Mauro Carvalho Chehab | d47109f | 2015-08-29 21:23:44 -0300 | [diff] [blame] | 388 | void __media_remove_intf_link(struct media_link *link); |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 389 | void media_remove_intf_link(struct media_link *link); |
Mauro Carvalho Chehab | 7c4696a | 2015-08-24 08:46:46 -0300 | [diff] [blame] | 390 | void __media_remove_intf_links(struct media_interface *intf); |
| 391 | void media_remove_intf_links(struct media_interface *intf); |
| 392 | |
Mauro Carvalho Chehab | 86e2662 | 2015-08-07 10:36:25 -0300 | [diff] [blame] | 393 | |
Laurent Pinchart | 97548ed | 2009-12-09 08:40:03 -0300 | [diff] [blame] | 394 | #define media_entity_call(entity, operation, args...) \ |
| 395 | (((entity)->ops && (entity)->ops->operation) ? \ |
| 396 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) |
| 397 | |
Laurent Pinchart | 53e269c | 2009-12-09 08:40:00 -0300 | [diff] [blame] | 398 | #endif |