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> |
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 | ||
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 | ||
5dd8775d SA |
107 | /* |
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 | |
165 | * @flags: Pad flags, as defined in uapi/media.h (MEDIA_PAD_FL_*) | |
166 | */ | |
53e269c1 | 167 | struct media_pad { |
4b8a3c08 | 168 | struct media_gobj graph_obj; /* must be first field in struct */ |
c358e80d MCC |
169 | struct media_entity *entity; |
170 | u16 index; | |
171 | unsigned long flags; | |
53e269c1 LP |
172 | }; |
173 | ||
5a5394be LP |
174 | /** |
175 | * struct media_entity_operations - Media entity operations | |
176 | * @link_setup: Notify the entity of link changes. The operation can | |
177 | * return an error, in which case link setup will be | |
178 | * cancelled. Optional. | |
179 | * @link_validate: Return whether a link is valid from the entity point of | |
180 | * view. The media_entity_pipeline_start() function | |
181 | * validates all links by calling this operation. Optional. | |
182 | */ | |
97548ed4 LP |
183 | struct media_entity_operations { |
184 | int (*link_setup)(struct media_entity *entity, | |
185 | const struct media_pad *local, | |
186 | const struct media_pad *remote, u32 flags); | |
af88be38 | 187 | int (*link_validate)(struct media_link *link); |
97548ed4 LP |
188 | }; |
189 | ||
c358e80d MCC |
190 | /** |
191 | * struct media_entity - A media entity graph object. | |
192 | * | |
193 | * @graph_obj: Embedded structure containing the media object common data. | |
194 | * @name: Entity name. | |
0e576b76 MCC |
195 | * @function: Entity main function, as defined in uapi/media.h |
196 | * (MEDIA_ENT_F_*) | |
c358e80d | 197 | * @flags: Entity flags, as defined in uapi/media.h (MEDIA_ENT_FL_*) |
c358e80d MCC |
198 | * @num_pads: Number of sink and source pads. |
199 | * @num_links: Total number of links, forward and back, enabled and disabled. | |
200 | * @num_backlinks: Number of backlinks | |
665faa97 SA |
201 | * @internal_idx: An unique internal entity specific number. The numbers are |
202 | * re-used if entities are unregistered or registered again. | |
c358e80d MCC |
203 | * @pads: Pads array with the size defined by @num_pads. |
204 | * @links: List of data links. | |
205 | * @ops: Entity operations. | |
206 | * @stream_count: Stream count for the entity. | |
207 | * @use_count: Use count for the entity. | |
208 | * @pipe: Pipeline this entity belongs to. | |
209 | * @info: Union with devnode information. Kept just for backward | |
210 | * compatibility. | |
211 | * @major: Devnode major number (zero if not applicable). Kept just | |
212 | * for backward compatibility. | |
213 | * @minor: Devnode minor number (zero if not applicable). Kept just | |
214 | * for backward compatibility. | |
215 | * | |
216 | * NOTE: @stream_count and @use_count reference counts must never be | |
217 | * negative, but are signed integers on purpose: a simple WARN_ON(<0) check | |
218 | * can be used to detect reference count bugs that would make them negative. | |
219 | */ | |
53e269c1 | 220 | struct media_entity { |
4b8a3c08 | 221 | struct media_gobj graph_obj; /* must be first field in struct */ |
c358e80d | 222 | const char *name; |
0e576b76 | 223 | u32 function; |
c358e80d | 224 | unsigned long flags; |
53e269c1 | 225 | |
c358e80d MCC |
226 | u16 num_pads; |
227 | u16 num_links; | |
228 | u16 num_backlinks; | |
665faa97 | 229 | int internal_idx; |
53e269c1 | 230 | |
c358e80d MCC |
231 | struct media_pad *pads; |
232 | struct list_head links; | |
53e269c1 | 233 | |
c358e80d | 234 | const struct media_entity_operations *ops; |
97548ed4 | 235 | |
503c3d82 LP |
236 | /* Reference counts must never be negative, but are signed integers on |
237 | * purpose: a simple WARN_ON(<0) check can be used to detect reference | |
238 | * count bugs that would make them negative. | |
239 | */ | |
c358e80d MCC |
240 | int stream_count; |
241 | int use_count; | |
503c3d82 | 242 | |
c358e80d | 243 | struct media_pipeline *pipe; |
e02188c9 | 244 | |
53e269c1 | 245 | union { |
53e269c1 LP |
246 | struct { |
247 | u32 major; | |
248 | u32 minor; | |
e31a0ba7 | 249 | } dev; |
fa5034c6 | 250 | } info; |
53e269c1 LP |
251 | }; |
252 | ||
27e543fa | 253 | /** |
c358e80d | 254 | * struct media_interface - A media interface graph object. |
27e543fa MCC |
255 | * |
256 | * @graph_obj: embedded graph object | |
86e26620 | 257 | * @links: List of links pointing to graph entities |
c358e80d | 258 | * @type: Type of the interface as defined in the |
27e543fa MCC |
259 | * uapi/media/media.h header, e. g. |
260 | * MEDIA_INTF_T_* | |
c358e80d | 261 | * @flags: Interface flags as defined in uapi/media/media.h |
27e543fa MCC |
262 | */ |
263 | struct media_interface { | |
264 | struct media_gobj graph_obj; | |
86e26620 | 265 | struct list_head links; |
27e543fa MCC |
266 | u32 type; |
267 | u32 flags; | |
268 | }; | |
269 | ||
270 | /** | |
c358e80d | 271 | * struct media_intf_devnode - A media interface via a device node. |
27e543fa MCC |
272 | * |
273 | * @intf: embedded interface object | |
274 | * @major: Major number of a device node | |
275 | * @minor: Minor number of a device node | |
276 | */ | |
277 | struct media_intf_devnode { | |
278 | struct media_interface intf; | |
c398bb64 MCC |
279 | |
280 | /* Should match the fields at media_v2_intf_devnode */ | |
27e543fa MCC |
281 | u32 major; |
282 | u32 minor; | |
283 | }; | |
284 | ||
60266185 MCC |
285 | /** |
286 | * media_entity_id() - return the media entity graph object id | |
287 | * | |
288 | * @entity: pointer to entity | |
289 | */ | |
fa762394 MCC |
290 | static inline u32 media_entity_id(struct media_entity *entity) |
291 | { | |
bfab2aac | 292 | return entity->graph_obj.id; |
fa762394 MCC |
293 | } |
294 | ||
60266185 MCC |
295 | /** |
296 | * media_type() - return the media object type | |
297 | * | |
298 | * @gobj: pointer to the media graph object | |
299 | */ | |
ec6e4c95 MCC |
300 | static inline enum media_gobj_type media_type(struct media_gobj *gobj) |
301 | { | |
302 | return gobj->id >> MEDIA_BITS_PER_LOCAL_ID; | |
303 | } | |
304 | ||
305 | static inline u32 media_localid(struct media_gobj *gobj) | |
306 | { | |
307 | return gobj->id & MEDIA_LOCAL_ID_MASK; | |
308 | } | |
309 | ||
310 | static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id) | |
311 | { | |
312 | u32 id; | |
313 | ||
314 | id = type << MEDIA_BITS_PER_LOCAL_ID; | |
315 | id |= local_id & MEDIA_LOCAL_ID_MASK; | |
316 | ||
317 | return id; | |
318 | } | |
319 | ||
60266185 MCC |
320 | /** |
321 | * is_media_entity_v4l2_io() - identify if the entity main function | |
322 | * is a V4L2 I/O | |
323 | * | |
324 | * @entity: pointer to entity | |
325 | * | |
326 | * Return: true if the entity main function is one of the V4L2 I/O types | |
327 | * (video, VBI or SDR radio); false otherwise. | |
328 | */ | |
fa17b46a MCC |
329 | static inline bool is_media_entity_v4l2_io(struct media_entity *entity) |
330 | { | |
331 | if (!entity) | |
332 | return false; | |
333 | ||
0e576b76 | 334 | switch (entity->function) { |
4ca72efa MCC |
335 | case MEDIA_ENT_F_IO_V4L: |
336 | case MEDIA_ENT_F_IO_VBI: | |
337 | case MEDIA_ENT_F_IO_SWRADIO: | |
fa17b46a MCC |
338 | return true; |
339 | default: | |
340 | return false; | |
341 | } | |
342 | } | |
343 | ||
60266185 MCC |
344 | /** |
345 | * is_media_entity_v4l2_subdev - return true if the entity main function is | |
346 | * associated with the V4L2 API subdev usage | |
347 | * | |
348 | * @entity: pointer to entity | |
349 | * | |
350 | * This is an ancillary function used by subdev-based V4L2 drivers. | |
351 | * It checks if the entity function is one of functions used by a V4L2 subdev, | |
352 | * e. g. camera-relatef functions, analog TV decoder, TV tuner, V4L2 DSPs. | |
353 | */ | |
fa17b46a MCC |
354 | static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity) |
355 | { | |
356 | if (!entity) | |
357 | return false; | |
358 | ||
0e576b76 | 359 | switch (entity->function) { |
4ca72efa MCC |
360 | case MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN: |
361 | case MEDIA_ENT_F_CAM_SENSOR: | |
362 | case MEDIA_ENT_F_FLASH: | |
363 | case MEDIA_ENT_F_LENS: | |
364 | case MEDIA_ENT_F_ATV_DECODER: | |
365 | case MEDIA_ENT_F_TUNER: | |
fa17b46a MCC |
366 | return true; |
367 | ||
368 | default: | |
369 | return false; | |
370 | } | |
371 | } | |
372 | ||
c8d54cd5 SA |
373 | __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum, |
374 | int idx_max); | |
375 | void media_entity_enum_cleanup(struct media_entity_enum *e); | |
a5ccc48a | 376 | |
c8d54cd5 SA |
377 | /** |
378 | * media_entity_enum_zero - Clear the entire enum | |
379 | * | |
380 | * @e: Entity enumeration to be cleared | |
ef69ee1b | 381 | */ |
c8d54cd5 SA |
382 | static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum) |
383 | { | |
384 | bitmap_zero(ent_enum->bmap, ent_enum->idx_max); | |
385 | } | |
386 | ||
387 | /** | |
388 | * media_entity_enum_set - Mark a single entity in the enum | |
389 | * | |
390 | * @e: Entity enumeration | |
391 | * @entity: Entity to be marked | |
392 | */ | |
393 | static inline void media_entity_enum_set(struct media_entity_enum *ent_enum, | |
394 | struct media_entity *entity) | |
395 | { | |
396 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) | |
397 | return; | |
398 | ||
399 | __set_bit(entity->internal_idx, ent_enum->bmap); | |
400 | } | |
401 | ||
402 | /** | |
403 | * media_entity_enum_clear - Unmark a single entity in the enum | |
404 | * | |
405 | * @e: Entity enumeration | |
406 | * @entity: Entity to be unmarked | |
407 | */ | |
408 | static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum, | |
409 | struct media_entity *entity) | |
410 | { | |
411 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) | |
412 | return; | |
413 | ||
414 | __clear_bit(entity->internal_idx, ent_enum->bmap); | |
415 | } | |
416 | ||
417 | /** | |
418 | * media_entity_enum_test - Test whether the entity is marked | |
419 | * | |
420 | * @e: Entity enumeration | |
421 | * @entity: Entity to be tested | |
422 | * | |
423 | * Returns true if the entity was marked. | |
424 | */ | |
425 | static inline bool media_entity_enum_test(struct media_entity_enum *ent_enum, | |
426 | struct media_entity *entity) | |
427 | { | |
428 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) | |
429 | return true; | |
430 | ||
431 | return test_bit(entity->internal_idx, ent_enum->bmap); | |
432 | } | |
433 | ||
434 | /** | |
435 | * media_entity_enum_test - Test whether the entity is marked, and mark it | |
436 | * | |
437 | * @e: Entity enumeration | |
438 | * @entity: Entity to be tested | |
439 | * | |
440 | * Returns true if the entity was marked, and mark it before doing so. | |
441 | */ | |
442 | static inline bool media_entity_enum_test_and_set( | |
443 | struct media_entity_enum *ent_enum, struct media_entity *entity) | |
444 | { | |
445 | if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) | |
446 | return true; | |
447 | ||
448 | return __test_and_set_bit(entity->internal_idx, ent_enum->bmap); | |
449 | } | |
450 | ||
451 | /** | |
452 | * media_entity_enum_test - Test whether the entire enum is empty | |
453 | * | |
454 | * @e: Entity enumeration | |
455 | * @entity: Entity to be tested | |
456 | * | |
457 | * Returns true if the entity was marked. | |
458 | */ | |
459 | static inline bool media_entity_enum_empty(struct media_entity_enum *ent_enum) | |
460 | { | |
461 | return bitmap_empty(ent_enum->bmap, ent_enum->idx_max); | |
462 | } | |
463 | ||
464 | /** | |
465 | * media_entity_enum_intersects - Test whether two enums intersect | |
466 | * | |
467 | * @e: First entity enumeration | |
468 | * @f: Second entity enumeration | |
469 | * | |
470 | * Returns true if entity enumerations e and f intersect, otherwise false. | |
471 | */ | |
472 | static inline bool media_entity_enum_intersects( | |
473 | struct media_entity_enum *ent_enum1, | |
474 | struct media_entity_enum *ent_enum2) | |
475 | { | |
476 | WARN_ON(ent_enum1->idx_max != ent_enum2->idx_max); | |
477 | ||
478 | return bitmap_intersects(ent_enum1->bmap, ent_enum2->bmap, | |
479 | min(ent_enum1->idx_max, ent_enum2->idx_max)); | |
480 | } | |
ef69ee1b | 481 | |
ec6e4c95 MCC |
482 | #define gobj_to_entity(gobj) \ |
483 | container_of(gobj, struct media_entity, graph_obj) | |
484 | ||
39a956c4 MCC |
485 | #define gobj_to_pad(gobj) \ |
486 | container_of(gobj, struct media_pad, graph_obj) | |
487 | ||
488 | #define gobj_to_link(gobj) \ | |
489 | container_of(gobj, struct media_link, graph_obj) | |
490 | ||
27e543fa MCC |
491 | #define gobj_to_link(gobj) \ |
492 | container_of(gobj, struct media_link, graph_obj) | |
493 | ||
494 | #define gobj_to_pad(gobj) \ | |
495 | container_of(gobj, struct media_pad, graph_obj) | |
496 | ||
497 | #define gobj_to_intf(gobj) \ | |
498 | container_of(gobj, struct media_interface, graph_obj) | |
499 | ||
500 | #define intf_to_devnode(intf) \ | |
501 | container_of(intf, struct media_intf_devnode, intf) | |
502 | ||
1fc25d30 MCC |
503 | /** |
504 | * media_gobj_create - Initialize a graph object | |
505 | * | |
506 | * @mdev: Pointer to the media_device that contains the object | |
507 | * @type: Type of the object | |
508 | * @gobj: Pointer to the graph object | |
509 | * | |
510 | * This routine initializes the embedded struct media_gobj inside a | |
511 | * media graph object. It is called automatically if media_*_create() | |
512 | * calls are used. However, if the object (entity, link, pad, interface) | |
513 | * is embedded on some other object, this function should be called before | |
514 | * registering the object at the media controller. | |
515 | */ | |
c350ef83 | 516 | void media_gobj_create(struct media_device *mdev, |
ec6e4c95 MCC |
517 | enum media_gobj_type type, |
518 | struct media_gobj *gobj); | |
1fc25d30 MCC |
519 | |
520 | /** | |
521 | * media_gobj_destroy - Stop using a graph object on a media device | |
522 | * | |
523 | * @gobj: Pointer to the graph object | |
524 | * | |
525 | * This should be called by all routines like media_device_unregister() | |
526 | * that remove/destroy media graph objects. | |
527 | */ | |
c350ef83 | 528 | void media_gobj_destroy(struct media_gobj *gobj); |
ec6e4c95 | 529 | |
db7ee32a MCC |
530 | /** |
531 | * media_entity_pads_init() - Initialize the entity pads | |
532 | * | |
533 | * @entity: entity where the pads belong | |
1fc25d30 MCC |
534 | * @num_pads: total number of sink and source pads |
535 | * @pads: Array of @num_pads pads. | |
536 | * | |
537 | * The pads array is managed by the entity driver and passed to | |
538 | * media_entity_pads_init() where its pointer will be stored in the entity | |
539 | * structure. | |
db7ee32a MCC |
540 | * |
541 | * If no pads are needed, drivers could either directly fill | |
542 | * &media_entity->@num_pads with 0 and &media_entity->@pads with NULL or call | |
543 | * this function that will do the same. | |
544 | * | |
545 | * As the number of pads is known in advance, the pads array is not allocated | |
546 | * dynamically but is managed by the entity driver. Most drivers will embed the | |
547 | * pads array in a driver-specific structure, avoiding dynamic allocation. | |
548 | * | |
549 | * Drivers must set the direction of every pad in the pads array before calling | |
550 | * media_entity_pads_init(). The function will initialize the other pads fields. | |
551 | */ | |
ab22e77c | 552 | int media_entity_pads_init(struct media_entity *entity, u16 num_pads, |
57208e5e | 553 | struct media_pad *pads); |
f1fd3289 | 554 | |
db7ee32a MCC |
555 | /** |
556 | * media_entity_cleanup() - free resources associated with an entity | |
557 | * | |
558 | * @entity: entity where the pads belong | |
559 | * | |
560 | * This function must be called during the cleanup phase after unregistering | |
561 | * the entity (currently, it does nothing). | |
562 | */ | |
f1fd3289 | 563 | static inline void media_entity_cleanup(struct media_entity *entity) {}; |
e02188c9 | 564 | |
db7ee32a MCC |
565 | /** |
566 | * media_create_pad_link() - creates a link between two entities. | |
567 | * | |
568 | * @source: pointer to &media_entity of the source pad. | |
569 | * @source_pad: number of the source pad in the pads array | |
570 | * @sink: pointer to &media_entity of the sink pad. | |
571 | * @sink_pad: number of the sink pad in the pads array. | |
572 | * @flags: Link flags, as defined in include/uapi/linux/media.h. | |
573 | * | |
574 | * Valid values for flags: | |
575 | * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be | |
576 | * used to transfer media data. When two or more links target a sink pad, | |
577 | * only one of them can be enabled at a time. | |
578 | * | |
579 | * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't | |
580 | * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then | |
581 | * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is | |
582 | * always enabled. | |
583 | * | |
584 | * NOTE: | |
585 | * | |
586 | * Before calling this function, media_entity_pads_init() and | |
587 | * media_device_register_entity() should be called previously for both ends. | |
588 | */ | |
77328043 MCC |
589 | __must_check int media_create_pad_link(struct media_entity *source, |
590 | u16 source_pad, struct media_entity *sink, | |
591 | u16 sink_pad, u32 flags); | |
7349cec1 | 592 | void __media_entity_remove_links(struct media_entity *entity); |
db7ee32a MCC |
593 | |
594 | /** | |
595 | * media_entity_remove_links() - remove all links associated with an entity | |
596 | * | |
597 | * @entity: pointer to &media_entity | |
598 | * | |
599 | * Note: this is called automatically when an entity is unregistered via | |
600 | * media_device_register_entity(). | |
601 | */ | |
7349cec1 SN |
602 | void media_entity_remove_links(struct media_entity *entity); |
603 | ||
1fc25d30 MCC |
604 | /** |
605 | * __media_entity_setup_link - Configure a media link without locking | |
606 | * @link: The link being configured | |
607 | * @flags: Link configuration flags | |
608 | * | |
609 | * The bulk of link setup is handled by the two entities connected through the | |
610 | * link. This function notifies both entities of the link configuration change. | |
611 | * | |
612 | * If the link is immutable or if the current and new configuration are | |
613 | * identical, return immediately. | |
614 | * | |
615 | * The user is expected to hold link->source->parent->mutex. If not, | |
616 | * media_entity_setup_link() should be used instead. | |
617 | */ | |
97548ed4 | 618 | int __media_entity_setup_link(struct media_link *link, u32 flags); |
db7ee32a MCC |
619 | |
620 | /** | |
621 | * media_entity_setup_link() - changes the link flags properties in runtime | |
622 | * | |
623 | * @link: pointer to &media_link | |
624 | * @flags: the requested new link flags | |
625 | * | |
626 | * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag | |
627 | * flag to enable/disable a link. Links marked with the | |
628 | * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled. | |
629 | * | |
630 | * When a link is enabled or disabled, the media framework calls the | |
631 | * link_setup operation for the two entities at the source and sink of the | |
632 | * link, in that order. If the second link_setup call fails, another | |
633 | * link_setup call is made on the first entity to restore the original link | |
634 | * flags. | |
635 | * | |
636 | * Media device drivers can be notified of link setup operations by setting the | |
637 | * media_device::link_notify pointer to a callback function. If provided, the | |
638 | * notification callback will be called before enabling and after disabling | |
639 | * links. | |
640 | * | |
641 | * Entity drivers must implement the link_setup operation if any of their links | |
642 | * is non-immutable. The operation must either configure the hardware or store | |
643 | * the configuration information to be applied later. | |
644 | * | |
645 | * Link configuration must not have any side effect on other links. If an | |
646 | * enabled link at a sink pad prevents another link at the same pad from | |
647 | * being enabled, the link_setup operation must return -EBUSY and can't | |
648 | * implicitly disable the first enabled link. | |
649 | * | |
650 | * NOTE: the valid values of the flags for the link is the same as described | |
651 | * on media_create_pad_link(), for pad to pad links or the same as described | |
652 | * on media_create_intf_link(), for interface to entity links. | |
653 | */ | |
97548ed4 | 654 | int media_entity_setup_link(struct media_link *link, u32 flags); |
1fc25d30 MCC |
655 | |
656 | /** | |
657 | * media_entity_find_link - Find a link between two pads | |
658 | * @source: Source pad | |
659 | * @sink: Sink pad | |
660 | * | |
661 | * Return a pointer to the link between the two entities. If no such link | |
662 | * exists, return NULL. | |
663 | */ | |
97548ed4 LP |
664 | struct media_link *media_entity_find_link(struct media_pad *source, |
665 | struct media_pad *sink); | |
1fc25d30 MCC |
666 | |
667 | /** | |
668 | * media_entity_remote_pad - Find the pad at the remote end of a link | |
669 | * @pad: Pad at the local end of the link | |
670 | * | |
671 | * Search for a remote pad connected to the given pad by iterating over all | |
672 | * links originating or terminating at that pad until an enabled link is found. | |
673 | * | |
674 | * Return a pointer to the pad at the remote end of the first found enabled | |
675 | * link, or NULL if no enabled link has been found. | |
676 | */ | |
1bddf1b3 | 677 | struct media_pad *media_entity_remote_pad(struct media_pad *pad); |
53e269c1 | 678 | |
1fc25d30 MCC |
679 | /** |
680 | * media_entity_get - Get a reference to the parent module | |
681 | * | |
682 | * @entity: The entity | |
683 | * | |
684 | * Get a reference to the parent media device module. | |
685 | * | |
686 | * The function will return immediately if @entity is NULL. | |
687 | * | |
688 | * Return a pointer to the entity on success or NULL on failure. | |
689 | */ | |
503c3d82 | 690 | struct media_entity *media_entity_get(struct media_entity *entity); |
1fc25d30 | 691 | |
e03d2203 SA |
692 | __must_check int media_entity_graph_walk_init( |
693 | struct media_entity_graph *graph, struct media_device *mdev); | |
694 | void media_entity_graph_walk_cleanup(struct media_entity_graph *graph); | |
695 | ||
1fc25d30 MCC |
696 | /** |
697 | * media_entity_put - Release the reference to the parent module | |
698 | * | |
699 | * @entity: The entity | |
700 | * | |
701 | * Release the reference count acquired by media_entity_get(). | |
702 | * | |
703 | * The function will return immediately if @entity is NULL. | |
704 | */ | |
503c3d82 LP |
705 | void media_entity_put(struct media_entity *entity); |
706 | ||
1fc25d30 MCC |
707 | /** |
708 | * media_entity_graph_walk_start - Start walking the media graph at a given entity | |
709 | * @graph: Media graph structure that will be used to walk the graph | |
710 | * @entity: Starting entity | |
711 | * | |
e03d2203 SA |
712 | * Before using this function, media_entity_graph_walk_init() must be |
713 | * used to allocate resources used for walking the graph. This | |
714 | * function initializes the graph traversal structure to walk the | |
715 | * entities graph starting at the given entity. The traversal | |
716 | * structure must not be modified by the caller during graph | |
717 | * traversal. After the graph walk, the resources must be released | |
718 | * using media_entity_graph_walk_cleanup(). | |
1fc25d30 | 719 | */ |
a5ccc48a | 720 | void media_entity_graph_walk_start(struct media_entity_graph *graph, |
e03d2203 | 721 | struct media_entity *entity); |
1fc25d30 MCC |
722 | |
723 | /** | |
724 | * media_entity_graph_walk_next - Get the next entity in the graph | |
725 | * @graph: Media graph structure | |
726 | * | |
727 | * Perform a depth-first traversal of the given media entities graph. | |
728 | * | |
729 | * The graph structure must have been previously initialized with a call to | |
730 | * media_entity_graph_walk_start(). | |
731 | * | |
732 | * Return the next entity in the graph or NULL if the whole graph have been | |
733 | * traversed. | |
734 | */ | |
a5ccc48a SA |
735 | struct media_entity * |
736 | media_entity_graph_walk_next(struct media_entity_graph *graph); | |
1fc25d30 MCC |
737 | |
738 | /** | |
739 | * media_entity_pipeline_start - Mark a pipeline as streaming | |
740 | * @entity: Starting entity | |
741 | * @pipe: Media pipeline to be assigned to all entities in the pipeline. | |
742 | * | |
743 | * Mark all entities connected to a given entity through enabled links, either | |
744 | * directly or indirectly, as streaming. The given pipeline object is assigned to | |
745 | * every entity in the pipeline and stored in the media_entity pipe field. | |
746 | * | |
747 | * Calls to this function can be nested, in which case the same number of | |
748 | * media_entity_pipeline_stop() calls will be required to stop streaming. The | |
749 | * pipeline pointer must be identical for all nested calls to | |
750 | * media_entity_pipeline_start(). | |
751 | */ | |
af88be38 SA |
752 | __must_check int media_entity_pipeline_start(struct media_entity *entity, |
753 | struct media_pipeline *pipe); | |
1fc25d30 MCC |
754 | |
755 | /** | |
756 | * media_entity_pipeline_stop - Mark a pipeline as not streaming | |
757 | * @entity: Starting entity | |
758 | * | |
759 | * Mark all entities connected to a given entity through enabled links, either | |
760 | * directly or indirectly, as not streaming. The media_entity pipe field is | |
761 | * reset to NULL. | |
762 | * | |
763 | * If multiple calls to media_entity_pipeline_start() have been made, the same | |
764 | * number of calls to this function are required to mark the pipeline as not | |
765 | * streaming. | |
766 | */ | |
e02188c9 | 767 | void media_entity_pipeline_stop(struct media_entity *entity); |
a5ccc48a | 768 | |
db7ee32a MCC |
769 | /** |
770 | * media_devnode_create() - creates and initializes a device node interface | |
771 | * | |
772 | * @mdev: pointer to struct &media_device | |
773 | * @type: type of the interface, as given by MEDIA_INTF_T_* macros | |
774 | * as defined in the uapi/media/media.h header. | |
775 | * @flags: Interface flags as defined in uapi/media/media.h. | |
776 | * @major: Device node major number. | |
777 | * @minor: Device node minor number. | |
778 | * | |
779 | * Return: if succeeded, returns a pointer to the newly allocated | |
780 | * &media_intf_devnode pointer. | |
781 | */ | |
5e5387df MCC |
782 | struct media_intf_devnode * |
783 | __must_check media_devnode_create(struct media_device *mdev, | |
784 | u32 type, u32 flags, | |
0b3b72df | 785 | u32 major, u32 minor); |
db7ee32a MCC |
786 | /** |
787 | * media_devnode_remove() - removes a device node interface | |
788 | * | |
789 | * @devnode: pointer to &media_intf_devnode to be freed. | |
790 | * | |
791 | * When a device node interface is removed, all links to it are automatically | |
792 | * removed. | |
793 | */ | |
27e543fa | 794 | void media_devnode_remove(struct media_intf_devnode *devnode); |
5e5387df | 795 | struct media_link * |
db7ee32a MCC |
796 | |
797 | /** | |
798 | * media_create_intf_link() - creates a link between an entity and an interface | |
799 | * | |
800 | * @entity: pointer to %media_entity | |
801 | * @intf: pointer to %media_interface | |
802 | * @flags: Link flags, as defined in include/uapi/linux/media.h. | |
803 | * | |
804 | * | |
805 | * Valid values for flags: | |
806 | * The %MEDIA_LNK_FL_ENABLED flag indicates that the interface is connected to | |
807 | * the entity hardware. That's the default value for interfaces. An | |
808 | * interface may be disabled if the hardware is busy due to the usage | |
809 | * of some other interface that it is currently controlling the hardware. | |
810 | * A typical example is an hybrid TV device that handle only one type of | |
811 | * stream on a given time. So, when the digital TV is streaming, | |
812 | * the V4L2 interfaces won't be enabled, as such device is not able to | |
813 | * also stream analog TV or radio. | |
814 | * | |
815 | * Note: | |
816 | * | |
817 | * Before calling this function, media_devnode_create() should be called for | |
818 | * the interface and media_device_register_entity() should be called for the | |
819 | * interface that will be part of the link. | |
820 | */ | |
5e5387df MCC |
821 | __must_check media_create_intf_link(struct media_entity *entity, |
822 | struct media_interface *intf, | |
823 | u32 flags); | |
60266185 MCC |
824 | /** |
825 | * __media_remove_intf_link() - remove a single interface link | |
826 | * | |
827 | * @link: pointer to &media_link. | |
828 | * | |
829 | * Note: this is an unlocked version of media_remove_intf_link() | |
830 | */ | |
d47109fa | 831 | void __media_remove_intf_link(struct media_link *link); |
60266185 MCC |
832 | |
833 | /** | |
834 | * media_remove_intf_link() - remove a single interface link | |
835 | * | |
836 | * @link: pointer to &media_link. | |
837 | * | |
838 | * Note: prefer to use this one, instead of __media_remove_intf_link() | |
839 | */ | |
86e26620 | 840 | void media_remove_intf_link(struct media_link *link); |
60266185 MCC |
841 | |
842 | /** | |
843 | * __media_remove_intf_links() - remove all links associated with an interface | |
844 | * | |
845 | * @intf: pointer to &media_interface | |
846 | * | |
847 | * Note: this is an unlocked version of media_remove_intf_links(). | |
848 | */ | |
7c4696a9 | 849 | void __media_remove_intf_links(struct media_interface *intf); |
db7ee32a MCC |
850 | /** |
851 | * media_remove_intf_links() - remove all links associated with an interface | |
852 | * | |
853 | * @intf: pointer to &media_interface | |
854 | * | |
60266185 MCC |
855 | * Notes: |
856 | * | |
857 | * this is called automatically when an entity is unregistered via | |
db7ee32a | 858 | * media_device_register_entity() and by media_devnode_remove(). |
60266185 MCC |
859 | * |
860 | * Prefer to use this one, instead of __media_remove_intf_links(). | |
db7ee32a | 861 | */ |
7c4696a9 MCC |
862 | void media_remove_intf_links(struct media_interface *intf); |
863 | ||
86e26620 | 864 | |
97548ed4 LP |
865 | #define media_entity_call(entity, operation, args...) \ |
866 | (((entity)->ops && (entity)->ops->operation) ? \ | |
867 | (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) | |
868 | ||
53e269c1 | 869 | #endif |