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