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 | ||
5c7b25b9 | 26 | #include <linux/bitops.h> |
0149a2e1 | 27 | #include <linux/kernel.h> |
53e269c1 | 28 | #include <linux/list.h> |
1651333b | 29 | #include <linux/media.h> |
53e269c1 | 30 | |
ec6e4c95 MCC |
31 | /* Enums used internally at the media controller to represent graphs */ |
32 | ||
33 | /** | |
34 | * enum media_gobj_type - type of a graph object | |
35 | * | |
bfab2aac | 36 | * @MEDIA_GRAPH_ENTITY: Identify a media entity |
18710dc6 | 37 | * @MEDIA_GRAPH_PAD: Identify a media pad |
6b6a4278 | 38 | * @MEDIA_GRAPH_LINK: Identify a media link |
27e543fa MCC |
39 | * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via |
40 | * a device node | |
ec6e4c95 MCC |
41 | */ |
42 | enum media_gobj_type { | |
bfab2aac | 43 | MEDIA_GRAPH_ENTITY, |
18710dc6 | 44 | MEDIA_GRAPH_PAD, |
6b6a4278 | 45 | MEDIA_GRAPH_LINK, |
27e543fa | 46 | MEDIA_GRAPH_INTF_DEVNODE, |
ec6e4c95 MCC |
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 | * | |
c358e80d | 58 | * @mdev: Pointer to the struct media_device that owns the object |
ec6e4c95 MCC |
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"). | |
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 | ||
e02188c9 LP |
74 | struct media_pipeline { |
75 | }; | |
76 | ||
c358e80d MCC |
77 | /** |
78 | * struct media_link - A link object part of a media graph. | |
79 | * | |
80 | * @graph_obj: Embedded structure containing the media object common data | |
81 | * @list: Linked list associated with an entity or an interface that | |
82 | * owns the link. | |
83 | * @gobj0: Part of a union. Used to get the pointer for the first | |
84 | * graph_object of the link. | |
85 | * @source: Part of a union. Used only if the first object (gobj0) is | |
86 | * a pad. In that case, it represents the source pad. | |
87 | * @intf: Part of a union. Used only if the first object (gobj0) is | |
88 | * an interface. | |
89 | * @gobj1: Part of a union. Used to get the pointer for the second | |
90 | * graph_object of the link. | |
91 | * @source: Part of a union. Used only if the second object (gobj1) is | |
92 | * a pad. In that case, it represents the sink pad. | |
93 | * @entity: Part of a union. Used only if the second object (gobj1) is | |
94 | * an entity. | |
95 | * @reverse: Pointer to the link for the reverse direction of a pad to pad | |
96 | * link. | |
97 | * @flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*) | |
39d1ebc6 | 98 | * @is_backlink: Indicate if the link is a backlink. |
c358e80d | 99 | */ |
53e269c1 | 100 | struct media_link { |
6b6a4278 | 101 | struct media_gobj graph_obj; |
57208e5e | 102 | struct list_head list; |
4b8a3c08 MCC |
103 | union { |
104 | struct media_gobj *gobj0; | |
105 | struct media_pad *source; | |
86e26620 | 106 | struct media_interface *intf; |
4b8a3c08 MCC |
107 | }; |
108 | union { | |
109 | struct media_gobj *gobj1; | |
110 | struct media_pad *sink; | |
86e26620 | 111 | struct media_entity *entity; |
4b8a3c08 | 112 | }; |
c358e80d MCC |
113 | struct media_link *reverse; |
114 | unsigned long flags; | |
39d1ebc6 | 115 | bool is_backlink; |
53e269c1 LP |
116 | }; |
117 | ||
c358e80d MCC |
118 | /** |
119 | * struct media_pad - A media pad graph object. | |
120 | * | |
121 | * @graph_obj: Embedded structure containing the media object common data | |
122 | * @entity: Entity this pad belongs to | |
123 | * @index: Pad index in the entity pads array, numbered from 0 to n | |
124 | * @flags: Pad flags, as defined in uapi/media.h (MEDIA_PAD_FL_*) | |
125 | */ | |
53e269c1 | 126 | struct media_pad { |
4b8a3c08 | 127 | struct media_gobj graph_obj; /* must be first field in struct */ |
c358e80d MCC |
128 | struct media_entity *entity; |
129 | u16 index; | |
130 | unsigned long flags; | |
53e269c1 LP |
131 | }; |
132 | ||
5a5394be LP |
133 | /** |
134 | * struct media_entity_operations - Media entity operations | |
135 | * @link_setup: Notify the entity of link changes. The operation can | |
136 | * return an error, in which case link setup will be | |
137 | * cancelled. Optional. | |
138 | * @link_validate: Return whether a link is valid from the entity point of | |
139 | * view. The media_entity_pipeline_start() function | |
140 | * validates all links by calling this operation. Optional. | |
141 | */ | |
97548ed4 LP |
142 | struct media_entity_operations { |
143 | int (*link_setup)(struct media_entity *entity, | |
144 | const struct media_pad *local, | |
145 | const struct media_pad *remote, u32 flags); | |
af88be38 | 146 | int (*link_validate)(struct media_link *link); |
97548ed4 LP |
147 | }; |
148 | ||
c358e80d MCC |
149 | /** |
150 | * struct media_entity - A media entity graph object. | |
151 | * | |
152 | * @graph_obj: Embedded structure containing the media object common data. | |
153 | * @name: Entity name. | |
0e576b76 MCC |
154 | * @function: Entity main function, as defined in uapi/media.h |
155 | * (MEDIA_ENT_F_*) | |
c358e80d | 156 | * @flags: Entity flags, as defined in uapi/media.h (MEDIA_ENT_FL_*) |
c358e80d MCC |
157 | * @num_pads: Number of sink and source pads. |
158 | * @num_links: Total number of links, forward and back, enabled and disabled. | |
159 | * @num_backlinks: Number of backlinks | |
160 | * @pads: Pads array with the size defined by @num_pads. | |
161 | * @links: List of data links. | |
162 | * @ops: Entity operations. | |
163 | * @stream_count: Stream count for the entity. | |
164 | * @use_count: Use count for the entity. | |
165 | * @pipe: Pipeline this entity belongs to. | |
166 | * @info: Union with devnode information. Kept just for backward | |
167 | * compatibility. | |
168 | * @major: Devnode major number (zero if not applicable). Kept just | |
169 | * for backward compatibility. | |
170 | * @minor: Devnode minor number (zero if not applicable). Kept just | |
171 | * for backward compatibility. | |
172 | * | |
173 | * NOTE: @stream_count and @use_count reference counts must never be | |
174 | * negative, but are signed integers on purpose: a simple WARN_ON(<0) check | |
175 | * can be used to detect reference count bugs that would make them negative. | |
176 | */ | |
53e269c1 | 177 | struct media_entity { |
4b8a3c08 | 178 | struct media_gobj graph_obj; /* must be first field in struct */ |
c358e80d | 179 | const char *name; |
0e576b76 | 180 | u32 function; |
c358e80d | 181 | unsigned long flags; |
53e269c1 | 182 | |
c358e80d MCC |
183 | u16 num_pads; |
184 | u16 num_links; | |
185 | u16 num_backlinks; | |
53e269c1 | 186 | |
c358e80d MCC |
187 | struct media_pad *pads; |
188 | struct list_head links; | |
53e269c1 | 189 | |
c358e80d | 190 | const struct media_entity_operations *ops; |
97548ed4 | 191 | |
503c3d82 LP |
192 | /* Reference counts must never be negative, but are signed integers on |
193 | * purpose: a simple WARN_ON(<0) check can be used to detect reference | |
194 | * count bugs that would make them negative. | |
195 | */ | |
c358e80d MCC |
196 | int stream_count; |
197 | int use_count; | |
503c3d82 | 198 | |
c358e80d | 199 | struct media_pipeline *pipe; |
e02188c9 | 200 | |
53e269c1 | 201 | union { |
53e269c1 LP |
202 | struct { |
203 | u32 major; | |
204 | u32 minor; | |
e31a0ba7 | 205 | } dev; |
fa5034c6 | 206 | } info; |
53e269c1 LP |
207 | }; |
208 | ||
27e543fa | 209 | /** |
c358e80d | 210 | * struct media_interface - A media interface graph object. |
27e543fa MCC |
211 | * |
212 | * @graph_obj: embedded graph object | |
86e26620 | 213 | * @links: List of links pointing to graph entities |
c358e80d | 214 | * @type: Type of the interface as defined in the |
27e543fa MCC |
215 | * uapi/media/media.h header, e. g. |
216 | * MEDIA_INTF_T_* | |
c358e80d | 217 | * @flags: Interface flags as defined in uapi/media/media.h |
27e543fa MCC |
218 | */ |
219 | struct media_interface { | |
220 | struct media_gobj graph_obj; | |
86e26620 | 221 | struct list_head links; |
27e543fa MCC |
222 | u32 type; |
223 | u32 flags; | |
224 | }; | |
225 | ||
226 | /** | |
c358e80d | 227 | * struct media_intf_devnode - A media interface via a device node. |
27e543fa MCC |
228 | * |
229 | * @intf: embedded interface object | |
230 | * @major: Major number of a device node | |
231 | * @minor: Minor number of a device node | |
232 | */ | |
233 | struct media_intf_devnode { | |
234 | struct media_interface intf; | |
c398bb64 MCC |
235 | |
236 | /* Should match the fields at media_v2_intf_devnode */ | |
27e543fa MCC |
237 | u32 major; |
238 | u32 minor; | |
239 | }; | |
240 | ||
fa762394 MCC |
241 | static inline u32 media_entity_id(struct media_entity *entity) |
242 | { | |
bfab2aac | 243 | return entity->graph_obj.id; |
fa762394 MCC |
244 | } |
245 | ||
ec6e4c95 MCC |
246 | static inline enum media_gobj_type media_type(struct media_gobj *gobj) |
247 | { | |
248 | return gobj->id >> MEDIA_BITS_PER_LOCAL_ID; | |
249 | } | |
250 | ||
251 | static inline u32 media_localid(struct media_gobj *gobj) | |
252 | { | |
253 | return gobj->id & MEDIA_LOCAL_ID_MASK; | |
254 | } | |
255 | ||
256 | static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id) | |
257 | { | |
258 | u32 id; | |
259 | ||
260 | id = type << MEDIA_BITS_PER_LOCAL_ID; | |
261 | id |= local_id & MEDIA_LOCAL_ID_MASK; | |
262 | ||
263 | return id; | |
264 | } | |
265 | ||
fa17b46a MCC |
266 | static inline bool is_media_entity_v4l2_io(struct media_entity *entity) |
267 | { | |
268 | if (!entity) | |
269 | return false; | |
270 | ||
0e576b76 | 271 | switch (entity->function) { |
4ca72efa MCC |
272 | case MEDIA_ENT_F_IO_V4L: |
273 | case MEDIA_ENT_F_IO_VBI: | |
274 | case MEDIA_ENT_F_IO_SWRADIO: | |
fa17b46a MCC |
275 | return true; |
276 | default: | |
277 | return false; | |
278 | } | |
279 | } | |
280 | ||
281 | static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity) | |
282 | { | |
283 | if (!entity) | |
284 | return false; | |
285 | ||
0e576b76 | 286 | switch (entity->function) { |
4ca72efa MCC |
287 | case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN: |
288 | case MEDIA_ENT_F_CAM_SENSOR: | |
289 | case MEDIA_ENT_F_FLASH: | |
290 | case MEDIA_ENT_F_LENS: | |
291 | case MEDIA_ENT_F_ATV_DECODER: | |
292 | case MEDIA_ENT_F_TUNER: | |
fa17b46a MCC |
293 | return true; |
294 | ||
295 | default: | |
296 | return false; | |
297 | } | |
298 | } | |
299 | ||
a5ccc48a | 300 | #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 |
5c7b25b9 | 301 | #define MEDIA_ENTITY_ENUM_MAX_ID 64 |
a5ccc48a | 302 | |
ef69ee1b MCC |
303 | /* |
304 | * The number of pads can't be bigger than the number of entities, | |
305 | * as the worse-case scenario is to have one entity linked up to | |
306 | * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities. | |
307 | */ | |
308 | #define MEDIA_ENTITY_MAX_PADS (MEDIA_ENTITY_ENUM_MAX_ID - 1) | |
309 | ||
a5ccc48a SA |
310 | struct media_entity_graph { |
311 | struct { | |
312 | struct media_entity *entity; | |
57208e5e | 313 | struct list_head *link; |
a5ccc48a | 314 | } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; |
5c7b25b9 LP |
315 | |
316 | DECLARE_BITMAP(entities, MEDIA_ENTITY_ENUM_MAX_ID); | |
a5ccc48a SA |
317 | int top; |
318 | }; | |
319 | ||
ec6e4c95 MCC |
320 | #define gobj_to_entity(gobj) \ |
321 | container_of(gobj, struct media_entity, graph_obj) | |
322 | ||
39a956c4 MCC |
323 | #define gobj_to_pad(gobj) \ |
324 | container_of(gobj, struct media_pad, graph_obj) | |
325 | ||
326 | #define gobj_to_link(gobj) \ | |
327 | container_of(gobj, struct media_link, graph_obj) | |
328 | ||
27e543fa MCC |
329 | #define gobj_to_link(gobj) \ |
330 | container_of(gobj, struct media_link, graph_obj) | |
331 | ||
332 | #define gobj_to_pad(gobj) \ | |
333 | container_of(gobj, struct media_pad, graph_obj) | |
334 | ||
335 | #define gobj_to_intf(gobj) \ | |
336 | container_of(gobj, struct media_interface, graph_obj) | |
337 | ||
338 | #define intf_to_devnode(intf) \ | |
339 | container_of(intf, struct media_intf_devnode, intf) | |
340 | ||
1fc25d30 MCC |
341 | /** |
342 | * media_gobj_create - Initialize a graph object | |
343 | * | |
344 | * @mdev: Pointer to the media_device that contains the object | |
345 | * @type: Type of the object | |
346 | * @gobj: Pointer to the graph object | |
347 | * | |
348 | * This routine initializes the embedded struct media_gobj inside a | |
349 | * media graph object. It is called automatically if media_*_create() | |
350 | * calls are used. However, if the object (entity, link, pad, interface) | |
351 | * is embedded on some other object, this function should be called before | |
352 | * registering the object at the media controller. | |
353 | */ | |
c350ef83 | 354 | void media_gobj_create(struct media_device *mdev, |
ec6e4c95 MCC |
355 | enum media_gobj_type type, |
356 | struct media_gobj *gobj); | |
1fc25d30 MCC |
357 | |
358 | /** | |
359 | * media_gobj_destroy - Stop using a graph object on a media device | |
360 | * | |
361 | * @gobj: Pointer to the graph object | |
362 | * | |
363 | * This should be called by all routines like media_device_unregister() | |
364 | * that remove/destroy media graph objects. | |
365 | */ | |
c350ef83 | 366 | void media_gobj_destroy(struct media_gobj *gobj); |
ec6e4c95 | 367 | |
db7ee32a MCC |
368 | /** |
369 | * media_entity_pads_init() - Initialize the entity pads | |
370 | * | |
371 | * @entity: entity where the pads belong | |
1fc25d30 MCC |
372 | * @num_pads: total number of sink and source pads |
373 | * @pads: Array of @num_pads pads. | |
374 | * | |
375 | * The pads array is managed by the entity driver and passed to | |
376 | * media_entity_pads_init() where its pointer will be stored in the entity | |
377 | * structure. | |
db7ee32a MCC |
378 | * |
379 | * If no pads are needed, drivers could either directly fill | |
380 | * &media_entity->@num_pads with 0 and &media_entity->@pads with NULL or call | |
381 | * this function that will do the same. | |
382 | * | |
383 | * As the number of pads is known in advance, the pads array is not allocated | |
384 | * dynamically but is managed by the entity driver. Most drivers will embed the | |
385 | * pads array in a driver-specific structure, avoiding dynamic allocation. | |
386 | * | |
387 | * Drivers must set the direction of every pad in the pads array before calling | |
388 | * media_entity_pads_init(). The function will initialize the other pads fields. | |
389 | */ | |
ab22e77c | 390 | int media_entity_pads_init(struct media_entity *entity, u16 num_pads, |
57208e5e | 391 | struct media_pad *pads); |
f1fd3289 | 392 | |
db7ee32a MCC |
393 | /** |
394 | * media_entity_cleanup() - free resources associated with an entity | |
395 | * | |
396 | * @entity: entity where the pads belong | |
397 | * | |
398 | * This function must be called during the cleanup phase after unregistering | |
399 | * the entity (currently, it does nothing). | |
400 | */ | |
f1fd3289 | 401 | static inline void media_entity_cleanup(struct media_entity *entity) {}; |
e02188c9 | 402 | |
db7ee32a MCC |
403 | /** |
404 | * media_create_pad_link() - creates a link between two entities. | |
405 | * | |
406 | * @source: pointer to &media_entity of the source pad. | |
407 | * @source_pad: number of the source pad in the pads array | |
408 | * @sink: pointer to &media_entity of the sink pad. | |
409 | * @sink_pad: number of the sink pad in the pads array. | |
410 | * @flags: Link flags, as defined in include/uapi/linux/media.h. | |
411 | * | |
412 | * Valid values for flags: | |
413 | * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be | |
414 | * used to transfer media data. When two or more links target a sink pad, | |
415 | * only one of them can be enabled at a time. | |
416 | * | |
417 | * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't | |
418 | * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then | |
419 | * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is | |
420 | * always enabled. | |
421 | * | |
422 | * NOTE: | |
423 | * | |
424 | * Before calling this function, media_entity_pads_init() and | |
425 | * media_device_register_entity() should be called previously for both ends. | |
426 | */ | |
77328043 MCC |
427 | __must_check int media_create_pad_link(struct media_entity *source, |
428 | u16 source_pad, struct media_entity *sink, | |
429 | u16 sink_pad, u32 flags); | |
7349cec1 | 430 | void __media_entity_remove_links(struct media_entity *entity); |
db7ee32a MCC |
431 | |
432 | /** | |
433 | * media_entity_remove_links() - remove all links associated with an entity | |
434 | * | |
435 | * @entity: pointer to &media_entity | |
436 | * | |
437 | * Note: this is called automatically when an entity is unregistered via | |
438 | * media_device_register_entity(). | |
439 | */ | |
7349cec1 SN |
440 | void media_entity_remove_links(struct media_entity *entity); |
441 | ||
1fc25d30 MCC |
442 | /** |
443 | * __media_entity_setup_link - Configure a media link without locking | |
444 | * @link: The link being configured | |
445 | * @flags: Link configuration flags | |
446 | * | |
447 | * The bulk of link setup is handled by the two entities connected through the | |
448 | * link. This function notifies both entities of the link configuration change. | |
449 | * | |
450 | * If the link is immutable or if the current and new configuration are | |
451 | * identical, return immediately. | |
452 | * | |
453 | * The user is expected to hold link->source->parent->mutex. If not, | |
454 | * media_entity_setup_link() should be used instead. | |
455 | */ | |
97548ed4 | 456 | int __media_entity_setup_link(struct media_link *link, u32 flags); |
db7ee32a MCC |
457 | |
458 | /** | |
459 | * media_entity_setup_link() - changes the link flags properties in runtime | |
460 | * | |
461 | * @link: pointer to &media_link | |
462 | * @flags: the requested new link flags | |
463 | * | |
464 | * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag | |
465 | * flag to enable/disable a link. Links marked with the | |
466 | * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled. | |
467 | * | |
468 | * When a link is enabled or disabled, the media framework calls the | |
469 | * link_setup operation for the two entities at the source and sink of the | |
470 | * link, in that order. If the second link_setup call fails, another | |
471 | * link_setup call is made on the first entity to restore the original link | |
472 | * flags. | |
473 | * | |
474 | * Media device drivers can be notified of link setup operations by setting the | |
475 | * media_device::link_notify pointer to a callback function. If provided, the | |
476 | * notification callback will be called before enabling and after disabling | |
477 | * links. | |
478 | * | |
479 | * Entity drivers must implement the link_setup operation if any of their links | |
480 | * is non-immutable. The operation must either configure the hardware or store | |
481 | * the configuration information to be applied later. | |
482 | * | |
483 | * Link configuration must not have any side effect on other links. If an | |
484 | * enabled link at a sink pad prevents another link at the same pad from | |
485 | * being enabled, the link_setup operation must return -EBUSY and can't | |
486 | * implicitly disable the first enabled link. | |
487 | * | |
488 | * NOTE: the valid values of the flags for the link is the same as described | |
489 | * on media_create_pad_link(), for pad to pad links or the same as described | |
490 | * on media_create_intf_link(), for interface to entity links. | |
491 | */ | |
97548ed4 | 492 | int media_entity_setup_link(struct media_link *link, u32 flags); |
1fc25d30 MCC |
493 | |
494 | /** | |
495 | * media_entity_find_link - Find a link between two pads | |
496 | * @source: Source pad | |
497 | * @sink: Sink pad | |
498 | * | |
499 | * Return a pointer to the link between the two entities. If no such link | |
500 | * exists, return NULL. | |
501 | */ | |
97548ed4 LP |
502 | struct media_link *media_entity_find_link(struct media_pad *source, |
503 | struct media_pad *sink); | |
1fc25d30 MCC |
504 | |
505 | /** | |
506 | * media_entity_remote_pad - Find the pad at the remote end of a link | |
507 | * @pad: Pad at the local end of the link | |
508 | * | |
509 | * Search for a remote pad connected to the given pad by iterating over all | |
510 | * links originating or terminating at that pad until an enabled link is found. | |
511 | * | |
512 | * Return a pointer to the pad at the remote end of the first found enabled | |
513 | * link, or NULL if no enabled link has been found. | |
514 | */ | |
1bddf1b3 | 515 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); |
53e269c1 | 516 | |
1fc25d30 MCC |
517 | /** |
518 | * media_entity_get - Get a reference to the parent module | |
519 | * | |
520 | * @entity: The entity | |
521 | * | |
522 | * Get a reference to the parent media device module. | |
523 | * | |
524 | * The function will return immediately if @entity is NULL. | |
525 | * | |
526 | * Return a pointer to the entity on success or NULL on failure. | |
527 | */ | |
503c3d82 | 528 | struct media_entity *media_entity_get(struct media_entity *entity); |
1fc25d30 MCC |
529 | |
530 | /** | |
531 | * media_entity_put - Release the reference to the parent module | |
532 | * | |
533 | * @entity: The entity | |
534 | * | |
535 | * Release the reference count acquired by media_entity_get(). | |
536 | * | |
537 | * The function will return immediately if @entity is NULL. | |
538 | */ | |
503c3d82 LP |
539 | void media_entity_put(struct media_entity *entity); |
540 | ||
1fc25d30 MCC |
541 | /** |
542 | * media_entity_graph_walk_start - Start walking the media graph at a given entity | |
543 | * @graph: Media graph structure that will be used to walk the graph | |
544 | * @entity: Starting entity | |
545 | * | |
546 | * This function initializes the graph traversal structure to walk the entities | |
547 | * graph starting at the given entity. The traversal structure must not be | |
548 | * modified by the caller during graph traversal. When done the structure can | |
549 | * safely be freed. | |
550 | */ | |
a5ccc48a SA |
551 | void media_entity_graph_walk_start(struct media_entity_graph *graph, |
552 | struct media_entity *entity); | |
1fc25d30 MCC |
553 | |
554 | /** | |
555 | * media_entity_graph_walk_next - Get the next entity in the graph | |
556 | * @graph: Media graph structure | |
557 | * | |
558 | * Perform a depth-first traversal of the given media entities graph. | |
559 | * | |
560 | * The graph structure must have been previously initialized with a call to | |
561 | * media_entity_graph_walk_start(). | |
562 | * | |
563 | * Return the next entity in the graph or NULL if the whole graph have been | |
564 | * traversed. | |
565 | */ | |
a5ccc48a SA |
566 | struct media_entity * |
567 | media_entity_graph_walk_next(struct media_entity_graph *graph); | |
1fc25d30 MCC |
568 | |
569 | /** | |
570 | * media_entity_pipeline_start - Mark a pipeline as streaming | |
571 | * @entity: Starting entity | |
572 | * @pipe: Media pipeline to be assigned to all entities in the pipeline. | |
573 | * | |
574 | * Mark all entities connected to a given entity through enabled links, either | |
575 | * directly or indirectly, as streaming. The given pipeline object is assigned to | |
576 | * every entity in the pipeline and stored in the media_entity pipe field. | |
577 | * | |
578 | * Calls to this function can be nested, in which case the same number of | |
579 | * media_entity_pipeline_stop() calls will be required to stop streaming. The | |
580 | * pipeline pointer must be identical for all nested calls to | |
581 | * media_entity_pipeline_start(). | |
582 | */ | |
af88be38 SA |
583 | __must_check int media_entity_pipeline_start(struct media_entity *entity, |
584 | struct media_pipeline *pipe); | |
1fc25d30 MCC |
585 | |
586 | /** | |
587 | * media_entity_pipeline_stop - Mark a pipeline as not streaming | |
588 | * @entity: Starting entity | |
589 | * | |
590 | * Mark all entities connected to a given entity through enabled links, either | |
591 | * directly or indirectly, as not streaming. The media_entity pipe field is | |
592 | * reset to NULL. | |
593 | * | |
594 | * If multiple calls to media_entity_pipeline_start() have been made, the same | |
595 | * number of calls to this function are required to mark the pipeline as not | |
596 | * streaming. | |
597 | */ | |
e02188c9 | 598 | void media_entity_pipeline_stop(struct media_entity *entity); |
a5ccc48a | 599 | |
db7ee32a MCC |
600 | /** |
601 | * media_devnode_create() - creates and initializes a device node interface | |
602 | * | |
603 | * @mdev: pointer to struct &media_device | |
604 | * @type: type of the interface, as given by MEDIA_INTF_T_* macros | |
605 | * as defined in the uapi/media/media.h header. | |
606 | * @flags: Interface flags as defined in uapi/media/media.h. | |
607 | * @major: Device node major number. | |
608 | * @minor: Device node minor number. | |
609 | * | |
610 | * Return: if succeeded, returns a pointer to the newly allocated | |
611 | * &media_intf_devnode pointer. | |
612 | */ | |
5e5387df MCC |
613 | struct media_intf_devnode * |
614 | __must_check media_devnode_create(struct media_device *mdev, | |
615 | u32 type, u32 flags, | |
0b3b72df | 616 | u32 major, u32 minor); |
db7ee32a MCC |
617 | /** |
618 | * media_devnode_remove() - removes a device node interface | |
619 | * | |
620 | * @devnode: pointer to &media_intf_devnode to be freed. | |
621 | * | |
622 | * When a device node interface is removed, all links to it are automatically | |
623 | * removed. | |
624 | */ | |
27e543fa | 625 | void media_devnode_remove(struct media_intf_devnode *devnode); |
5e5387df | 626 | struct media_link * |
db7ee32a MCC |
627 | |
628 | /** | |
629 | * media_create_intf_link() - creates a link between an entity and an interface | |
630 | * | |
631 | * @entity: pointer to %media_entity | |
632 | * @intf: pointer to %media_interface | |
633 | * @flags: Link flags, as defined in include/uapi/linux/media.h. | |
634 | * | |
635 | * | |
636 | * Valid values for flags: | |
637 | * The %MEDIA_LNK_FL_ENABLED flag indicates that the interface is connected to | |
638 | * the entity hardware. That's the default value for interfaces. An | |
639 | * interface may be disabled if the hardware is busy due to the usage | |
640 | * of some other interface that it is currently controlling the hardware. | |
641 | * A typical example is an hybrid TV device that handle only one type of | |
642 | * stream on a given time. So, when the digital TV is streaming, | |
643 | * the V4L2 interfaces won't be enabled, as such device is not able to | |
644 | * also stream analog TV or radio. | |
645 | * | |
646 | * Note: | |
647 | * | |
648 | * Before calling this function, media_devnode_create() should be called for | |
649 | * the interface and media_device_register_entity() should be called for the | |
650 | * interface that will be part of the link. | |
651 | */ | |
5e5387df MCC |
652 | __must_check media_create_intf_link(struct media_entity *entity, |
653 | struct media_interface *intf, | |
654 | u32 flags); | |
d47109fa | 655 | void __media_remove_intf_link(struct media_link *link); |
86e26620 | 656 | void media_remove_intf_link(struct media_link *link); |
7c4696a9 | 657 | void __media_remove_intf_links(struct media_interface *intf); |
db7ee32a MCC |
658 | /** |
659 | * media_remove_intf_links() - remove all links associated with an interface | |
660 | * | |
661 | * @intf: pointer to &media_interface | |
662 | * | |
663 | * Note: this is called automatically when an entity is unregistered via | |
664 | * media_device_register_entity() and by media_devnode_remove(). | |
665 | */ | |
7c4696a9 MCC |
666 | void media_remove_intf_links(struct media_interface *intf); |
667 | ||
86e26620 | 668 | |
97548ed4 LP |
669 | #define media_entity_call(entity, operation, args...) \ |
670 | (((entity)->ops && (entity)->ops->operation) ? \ | |
671 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) | |
672 | ||
53e269c1 | 673 | #endif |