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