![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-only */ 0002 /* 0003 * Media entity 0004 * 0005 * Copyright (C) 2010 Nokia Corporation 0006 * 0007 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 0008 * Sakari Ailus <sakari.ailus@iki.fi> 0009 */ 0010 0011 #ifndef _MEDIA_ENTITY_H 0012 #define _MEDIA_ENTITY_H 0013 0014 #include <linux/bitmap.h> 0015 #include <linux/bug.h> 0016 #include <linux/container_of.h> 0017 #include <linux/fwnode.h> 0018 #include <linux/list.h> 0019 #include <linux/media.h> 0020 #include <linux/types.h> 0021 0022 /* Enums used internally at the media controller to represent graphs */ 0023 0024 /** 0025 * enum media_gobj_type - type of a graph object 0026 * 0027 * @MEDIA_GRAPH_ENTITY: Identify a media entity 0028 * @MEDIA_GRAPH_PAD: Identify a media pad 0029 * @MEDIA_GRAPH_LINK: Identify a media link 0030 * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via 0031 * a device node 0032 */ 0033 enum media_gobj_type { 0034 MEDIA_GRAPH_ENTITY, 0035 MEDIA_GRAPH_PAD, 0036 MEDIA_GRAPH_LINK, 0037 MEDIA_GRAPH_INTF_DEVNODE, 0038 }; 0039 0040 #define MEDIA_BITS_PER_TYPE 8 0041 #define MEDIA_BITS_PER_ID (32 - MEDIA_BITS_PER_TYPE) 0042 #define MEDIA_ID_MASK GENMASK_ULL(MEDIA_BITS_PER_ID - 1, 0) 0043 0044 /* Structs to represent the objects that belong to a media graph */ 0045 0046 /** 0047 * struct media_gobj - Define a graph object. 0048 * 0049 * @mdev: Pointer to the struct &media_device that owns the object 0050 * @id: Non-zero object ID identifier. The ID should be unique 0051 * inside a media_device, as it is composed by 0052 * %MEDIA_BITS_PER_TYPE to store the type plus 0053 * %MEDIA_BITS_PER_ID to store the ID 0054 * @list: List entry stored in one of the per-type mdev object lists 0055 * 0056 * All objects on the media graph should have this struct embedded 0057 */ 0058 struct media_gobj { 0059 struct media_device *mdev; 0060 u32 id; 0061 struct list_head list; 0062 }; 0063 0064 #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 0065 0066 /** 0067 * struct media_entity_enum - An enumeration of media entities. 0068 * 0069 * @bmap: Bit map in which each bit represents one entity at struct 0070 * media_entity->internal_idx. 0071 * @idx_max: Number of bits in bmap 0072 */ 0073 struct media_entity_enum { 0074 unsigned long *bmap; 0075 int idx_max; 0076 }; 0077 0078 /** 0079 * struct media_graph - Media graph traversal state 0080 * 0081 * @stack: Graph traversal stack; the stack contains information 0082 * on the path the media entities to be walked and the 0083 * links through which they were reached. 0084 * @stack.entity: pointer to &struct media_entity at the graph. 0085 * @stack.link: pointer to &struct list_head. 0086 * @ent_enum: Visited entities 0087 * @top: The top of the stack 0088 */ 0089 struct media_graph { 0090 struct { 0091 struct media_entity *entity; 0092 struct list_head *link; 0093 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; 0094 0095 struct media_entity_enum ent_enum; 0096 int top; 0097 }; 0098 0099 /** 0100 * struct media_pipeline - Media pipeline related information 0101 * 0102 * @streaming_count: Streaming start count - streaming stop count 0103 * @graph: Media graph walk during pipeline start / stop 0104 */ 0105 struct media_pipeline { 0106 int streaming_count; 0107 struct media_graph graph; 0108 }; 0109 0110 /** 0111 * struct media_link - A link object part of a media graph. 0112 * 0113 * @graph_obj: Embedded structure containing the media object common data 0114 * @list: Linked list associated with an entity or an interface that 0115 * owns the link. 0116 * @gobj0: Part of a union. Used to get the pointer for the first 0117 * graph_object of the link. 0118 * @source: Part of a union. Used only if the first object (gobj0) is 0119 * a pad. In that case, it represents the source pad. 0120 * @intf: Part of a union. Used only if the first object (gobj0) is 0121 * an interface. 0122 * @gobj1: Part of a union. Used to get the pointer for the second 0123 * graph_object of the link. 0124 * @sink: Part of a union. Used only if the second object (gobj1) is 0125 * a pad. In that case, it represents the sink pad. 0126 * @entity: Part of a union. Used only if the second object (gobj1) is 0127 * an entity. 0128 * @reverse: Pointer to the link for the reverse direction of a pad to pad 0129 * link. 0130 * @flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*) 0131 * @is_backlink: Indicate if the link is a backlink. 0132 */ 0133 struct media_link { 0134 struct media_gobj graph_obj; 0135 struct list_head list; 0136 union { 0137 struct media_gobj *gobj0; 0138 struct media_pad *source; 0139 struct media_interface *intf; 0140 }; 0141 union { 0142 struct media_gobj *gobj1; 0143 struct media_pad *sink; 0144 struct media_entity *entity; 0145 }; 0146 struct media_link *reverse; 0147 unsigned long flags; 0148 bool is_backlink; 0149 }; 0150 0151 /** 0152 * enum media_pad_signal_type - type of the signal inside a media pad 0153 * 0154 * @PAD_SIGNAL_DEFAULT: 0155 * Default signal. Use this when all inputs or all outputs are 0156 * uniquely identified by the pad number. 0157 * @PAD_SIGNAL_ANALOG: 0158 * The pad contains an analog signal. It can be Radio Frequency, 0159 * Intermediate Frequency, a baseband signal or sub-carriers. 0160 * Tuner inputs, IF-PLL demodulators, composite and s-video signals 0161 * should use it. 0162 * @PAD_SIGNAL_DV: 0163 * Contains a digital video signal, with can be a bitstream of samples 0164 * taken from an analog TV video source. On such case, it usually 0165 * contains the VBI data on it. 0166 * @PAD_SIGNAL_AUDIO: 0167 * Contains an Intermediate Frequency analog signal from an audio 0168 * sub-carrier or an audio bitstream. IF signals are provided by tuners 0169 * and consumed by audio AM/FM decoders. Bitstream audio is provided by 0170 * an audio decoder. 0171 */ 0172 enum media_pad_signal_type { 0173 PAD_SIGNAL_DEFAULT = 0, 0174 PAD_SIGNAL_ANALOG, 0175 PAD_SIGNAL_DV, 0176 PAD_SIGNAL_AUDIO, 0177 }; 0178 0179 /** 0180 * struct media_pad - A media pad graph object. 0181 * 0182 * @graph_obj: Embedded structure containing the media object common data 0183 * @entity: Entity this pad belongs to 0184 * @index: Pad index in the entity pads array, numbered from 0 to n 0185 * @sig_type: Type of the signal inside a media pad 0186 * @flags: Pad flags, as defined in 0187 * :ref:`include/uapi/linux/media.h <media_header>` 0188 * (seek for ``MEDIA_PAD_FL_*``) 0189 */ 0190 struct media_pad { 0191 struct media_gobj graph_obj; /* must be first field in struct */ 0192 struct media_entity *entity; 0193 u16 index; 0194 enum media_pad_signal_type sig_type; 0195 unsigned long flags; 0196 }; 0197 0198 /** 0199 * struct media_entity_operations - Media entity operations 0200 * @get_fwnode_pad: Return the pad number based on a fwnode endpoint or 0201 * a negative value on error. This operation can be used 0202 * to map a fwnode to a media pad number. Optional. 0203 * @link_setup: Notify the entity of link changes. The operation can 0204 * return an error, in which case link setup will be 0205 * cancelled. Optional. 0206 * @link_validate: Return whether a link is valid from the entity point of 0207 * view. The media_pipeline_start() function 0208 * validates all links by calling this operation. Optional. 0209 * 0210 * .. note:: 0211 * 0212 * Those these callbacks are called with struct &media_device.graph_mutex 0213 * mutex held. 0214 */ 0215 struct media_entity_operations { 0216 int (*get_fwnode_pad)(struct media_entity *entity, 0217 struct fwnode_endpoint *endpoint); 0218 int (*link_setup)(struct media_entity *entity, 0219 const struct media_pad *local, 0220 const struct media_pad *remote, u32 flags); 0221 int (*link_validate)(struct media_link *link); 0222 }; 0223 0224 /** 0225 * enum media_entity_type - Media entity type 0226 * 0227 * @MEDIA_ENTITY_TYPE_BASE: 0228 * The entity isn't embedded in another subsystem structure. 0229 * @MEDIA_ENTITY_TYPE_VIDEO_DEVICE: 0230 * The entity is embedded in a struct video_device instance. 0231 * @MEDIA_ENTITY_TYPE_V4L2_SUBDEV: 0232 * The entity is embedded in a struct v4l2_subdev instance. 0233 * 0234 * Media entity objects are often not instantiated directly, but the media 0235 * entity structure is inherited by (through embedding) other subsystem-specific 0236 * structures. The media entity type identifies the type of the subclass 0237 * structure that implements a media entity instance. 0238 * 0239 * This allows runtime type identification of media entities and safe casting to 0240 * the correct object type. For instance, a media entity structure instance 0241 * embedded in a v4l2_subdev structure instance will have the type 0242 * %MEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to a &v4l2_subdev 0243 * structure using the container_of() macro. 0244 */ 0245 enum media_entity_type { 0246 MEDIA_ENTITY_TYPE_BASE, 0247 MEDIA_ENTITY_TYPE_VIDEO_DEVICE, 0248 MEDIA_ENTITY_TYPE_V4L2_SUBDEV, 0249 }; 0250 0251 /** 0252 * struct media_entity - A media entity graph object. 0253 * 0254 * @graph_obj: Embedded structure containing the media object common data. 0255 * @name: Entity name. 0256 * @obj_type: Type of the object that implements the media_entity. 0257 * @function: Entity main function, as defined in 0258 * :ref:`include/uapi/linux/media.h <media_header>` 0259 * (seek for ``MEDIA_ENT_F_*``) 0260 * @flags: Entity flags, as defined in 0261 * :ref:`include/uapi/linux/media.h <media_header>` 0262 * (seek for ``MEDIA_ENT_FL_*``) 0263 * @num_pads: Number of sink and source pads. 0264 * @num_links: Total number of links, forward and back, enabled and disabled. 0265 * @num_backlinks: Number of backlinks 0266 * @internal_idx: An unique internal entity specific number. The numbers are 0267 * re-used if entities are unregistered or registered again. 0268 * @pads: Pads array with the size defined by @num_pads. 0269 * @links: List of data links. 0270 * @ops: Entity operations. 0271 * @use_count: Use count for the entity. 0272 * @pipe: Pipeline this entity belongs to. 0273 * @info: Union with devnode information. Kept just for backward 0274 * compatibility. 0275 * @info.dev: Contains device major and minor info. 0276 * @info.dev.major: device node major, if the device is a devnode. 0277 * @info.dev.minor: device node minor, if the device is a devnode. 0278 * @major: Devnode major number (zero if not applicable). Kept just 0279 * for backward compatibility. 0280 * @minor: Devnode minor number (zero if not applicable). Kept just 0281 * for backward compatibility. 0282 * 0283 * .. note:: 0284 * 0285 * The @use_count reference count must never be negative, but is a signed 0286 * integer on purpose: a simple ``WARN_ON(<0)`` check can be used to detect 0287 * reference count bugs that would make it negative. 0288 */ 0289 struct media_entity { 0290 struct media_gobj graph_obj; /* must be first field in struct */ 0291 const char *name; 0292 enum media_entity_type obj_type; 0293 u32 function; 0294 unsigned long flags; 0295 0296 u16 num_pads; 0297 u16 num_links; 0298 u16 num_backlinks; 0299 int internal_idx; 0300 0301 struct media_pad *pads; 0302 struct list_head links; 0303 0304 const struct media_entity_operations *ops; 0305 0306 int use_count; 0307 0308 struct media_pipeline *pipe; 0309 0310 union { 0311 struct { 0312 u32 major; 0313 u32 minor; 0314 } dev; 0315 } info; 0316 }; 0317 0318 /** 0319 * struct media_interface - A media interface graph object. 0320 * 0321 * @graph_obj: embedded graph object 0322 * @links: List of links pointing to graph entities 0323 * @type: Type of the interface as defined in 0324 * :ref:`include/uapi/linux/media.h <media_header>` 0325 * (seek for ``MEDIA_INTF_T_*``) 0326 * @flags: Interface flags as defined in 0327 * :ref:`include/uapi/linux/media.h <media_header>` 0328 * (seek for ``MEDIA_INTF_FL_*``) 0329 * 0330 * .. note:: 0331 * 0332 * Currently, no flags for &media_interface is defined. 0333 */ 0334 struct media_interface { 0335 struct media_gobj graph_obj; 0336 struct list_head links; 0337 u32 type; 0338 u32 flags; 0339 }; 0340 0341 /** 0342 * struct media_intf_devnode - A media interface via a device node. 0343 * 0344 * @intf: embedded interface object 0345 * @major: Major number of a device node 0346 * @minor: Minor number of a device node 0347 */ 0348 struct media_intf_devnode { 0349 struct media_interface intf; 0350 0351 /* Should match the fields at media_v2_intf_devnode */ 0352 u32 major; 0353 u32 minor; 0354 }; 0355 0356 /** 0357 * media_entity_id() - return the media entity graph object id 0358 * 0359 * @entity: pointer to &media_entity 0360 */ 0361 static inline u32 media_entity_id(struct media_entity *entity) 0362 { 0363 return entity->graph_obj.id; 0364 } 0365 0366 /** 0367 * media_type() - return the media object type 0368 * 0369 * @gobj: Pointer to the struct &media_gobj graph object 0370 */ 0371 static inline enum media_gobj_type media_type(struct media_gobj *gobj) 0372 { 0373 return gobj->id >> MEDIA_BITS_PER_ID; 0374 } 0375 0376 /** 0377 * media_id() - return the media object ID 0378 * 0379 * @gobj: Pointer to the struct &media_gobj graph object 0380 */ 0381 static inline u32 media_id(struct media_gobj *gobj) 0382 { 0383 return gobj->id & MEDIA_ID_MASK; 0384 } 0385 0386 /** 0387 * media_gobj_gen_id() - encapsulates type and ID on at the object ID 0388 * 0389 * @type: object type as define at enum &media_gobj_type. 0390 * @local_id: next ID, from struct &media_device.id. 0391 */ 0392 static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id) 0393 { 0394 u32 id; 0395 0396 id = type << MEDIA_BITS_PER_ID; 0397 id |= local_id & MEDIA_ID_MASK; 0398 0399 return id; 0400 } 0401 0402 /** 0403 * is_media_entity_v4l2_video_device() - Check if the entity is a video_device 0404 * @entity: pointer to entity 0405 * 0406 * Return: %true if the entity is an instance of a video_device object and can 0407 * safely be cast to a struct video_device using the container_of() macro, or 0408 * %false otherwise. 0409 */ 0410 static inline bool is_media_entity_v4l2_video_device(struct media_entity *entity) 0411 { 0412 return entity && entity->obj_type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE; 0413 } 0414 0415 /** 0416 * is_media_entity_v4l2_subdev() - Check if the entity is a v4l2_subdev 0417 * @entity: pointer to entity 0418 * 0419 * Return: %true if the entity is an instance of a &v4l2_subdev object and can 0420 * safely be cast to a struct &v4l2_subdev using the container_of() macro, or 0421 * %false otherwise. 0422 */ 0423 static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity) 0424 { 0425 return entity && entity->obj_type == MEDIA_ENTITY_TYPE_V4L2_SUBDEV; 0426 } 0427 0428 /** 0429 * __media_entity_enum_init - Initialise an entity enumeration 0430 * 0431 * @ent_enum: Entity enumeration to be initialised 0432 * @idx_max: Maximum number of entities in the enumeration 0433 * 0434 * Return: Returns zero on success or a negative error code. 0435 */ 0436 __must_check int __media_entity_enum_init(struct media_entity_enum *ent_enum, 0437 int idx_max); 0438 0439 /** 0440 * media_entity_enum_cleanup - Release resources of an entity enumeration 0441 * 0442 * @ent_enum: Entity enumeration to be released 0443 */ 0444 void media_entity_enum_cleanup(struct media_entity_enum *ent_enum); 0445 0446 /** 0447 * media_entity_enum_zero - Clear the entire enum 0448 * 0449 * @ent_enum: Entity enumeration to be cleared 0450 */ 0451 static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum) 0452 { 0453 bitmap_zero(ent_enum->bmap, ent_enum->idx_max); 0454 } 0455 0456 /** 0457 * media_entity_enum_set - Mark a single entity in the enum 0458 * 0459 * @ent_enum: Entity enumeration 0460 * @entity: Entity to be marked 0461 */ 0462 static inline void media_entity_enum_set(struct media_entity_enum *ent_enum, 0463 struct media_entity *entity) 0464 { 0465 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) 0466 return; 0467 0468 __set_bit(entity->internal_idx, ent_enum->bmap); 0469 } 0470 0471 /** 0472 * media_entity_enum_clear - Unmark a single entity in the enum 0473 * 0474 * @ent_enum: Entity enumeration 0475 * @entity: Entity to be unmarked 0476 */ 0477 static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum, 0478 struct media_entity *entity) 0479 { 0480 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) 0481 return; 0482 0483 __clear_bit(entity->internal_idx, ent_enum->bmap); 0484 } 0485 0486 /** 0487 * media_entity_enum_test - Test whether the entity is marked 0488 * 0489 * @ent_enum: Entity enumeration 0490 * @entity: Entity to be tested 0491 * 0492 * Returns %true if the entity was marked. 0493 */ 0494 static inline bool media_entity_enum_test(struct media_entity_enum *ent_enum, 0495 struct media_entity *entity) 0496 { 0497 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) 0498 return true; 0499 0500 return test_bit(entity->internal_idx, ent_enum->bmap); 0501 } 0502 0503 /** 0504 * media_entity_enum_test_and_set - Test whether the entity is marked, 0505 * and mark it 0506 * 0507 * @ent_enum: Entity enumeration 0508 * @entity: Entity to be tested 0509 * 0510 * Returns %true if the entity was marked, and mark it before doing so. 0511 */ 0512 static inline bool 0513 media_entity_enum_test_and_set(struct media_entity_enum *ent_enum, 0514 struct media_entity *entity) 0515 { 0516 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) 0517 return true; 0518 0519 return __test_and_set_bit(entity->internal_idx, ent_enum->bmap); 0520 } 0521 0522 /** 0523 * media_entity_enum_empty - Test whether the entire enum is empty 0524 * 0525 * @ent_enum: Entity enumeration 0526 * 0527 * Return: %true if the entity was empty. 0528 */ 0529 static inline bool media_entity_enum_empty(struct media_entity_enum *ent_enum) 0530 { 0531 return bitmap_empty(ent_enum->bmap, ent_enum->idx_max); 0532 } 0533 0534 /** 0535 * media_entity_enum_intersects - Test whether two enums intersect 0536 * 0537 * @ent_enum1: First entity enumeration 0538 * @ent_enum2: Second entity enumeration 0539 * 0540 * Return: %true if entity enumerations @ent_enum1 and @ent_enum2 intersect, 0541 * otherwise %false. 0542 */ 0543 static inline bool media_entity_enum_intersects( 0544 struct media_entity_enum *ent_enum1, 0545 struct media_entity_enum *ent_enum2) 0546 { 0547 WARN_ON(ent_enum1->idx_max != ent_enum2->idx_max); 0548 0549 return bitmap_intersects(ent_enum1->bmap, ent_enum2->bmap, 0550 min(ent_enum1->idx_max, ent_enum2->idx_max)); 0551 } 0552 0553 /** 0554 * gobj_to_entity - returns the struct &media_entity pointer from the 0555 * @gobj contained on it. 0556 * 0557 * @gobj: Pointer to the struct &media_gobj graph object 0558 */ 0559 #define gobj_to_entity(gobj) \ 0560 container_of(gobj, struct media_entity, graph_obj) 0561 0562 /** 0563 * gobj_to_pad - returns the struct &media_pad pointer from the 0564 * @gobj contained on it. 0565 * 0566 * @gobj: Pointer to the struct &media_gobj graph object 0567 */ 0568 #define gobj_to_pad(gobj) \ 0569 container_of(gobj, struct media_pad, graph_obj) 0570 0571 /** 0572 * gobj_to_link - returns the struct &media_link pointer from the 0573 * @gobj contained on it. 0574 * 0575 * @gobj: Pointer to the struct &media_gobj graph object 0576 */ 0577 #define gobj_to_link(gobj) \ 0578 container_of(gobj, struct media_link, graph_obj) 0579 0580 /** 0581 * gobj_to_intf - returns the struct &media_interface pointer from the 0582 * @gobj contained on it. 0583 * 0584 * @gobj: Pointer to the struct &media_gobj graph object 0585 */ 0586 #define gobj_to_intf(gobj) \ 0587 container_of(gobj, struct media_interface, graph_obj) 0588 0589 /** 0590 * intf_to_devnode - returns the struct media_intf_devnode pointer from the 0591 * @intf contained on it. 0592 * 0593 * @intf: Pointer to struct &media_intf_devnode 0594 */ 0595 #define intf_to_devnode(intf) \ 0596 container_of(intf, struct media_intf_devnode, intf) 0597 0598 /** 0599 * media_gobj_create - Initialize a graph object 0600 * 0601 * @mdev: Pointer to the &media_device that contains the object 0602 * @type: Type of the object 0603 * @gobj: Pointer to the struct &media_gobj graph object 0604 * 0605 * This routine initializes the embedded struct &media_gobj inside a 0606 * media graph object. It is called automatically if ``media_*_create`` 0607 * function calls are used. However, if the object (entity, link, pad, 0608 * interface) is embedded on some other object, this function should be 0609 * called before registering the object at the media controller. 0610 */ 0611 void media_gobj_create(struct media_device *mdev, 0612 enum media_gobj_type type, 0613 struct media_gobj *gobj); 0614 0615 /** 0616 * media_gobj_destroy - Stop using a graph object on a media device 0617 * 0618 * @gobj: Pointer to the struct &media_gobj graph object 0619 * 0620 * This should be called by all routines like media_device_unregister() 0621 * that remove/destroy media graph objects. 0622 */ 0623 void media_gobj_destroy(struct media_gobj *gobj); 0624 0625 /** 0626 * media_entity_pads_init() - Initialize the entity pads 0627 * 0628 * @entity: entity where the pads belong 0629 * @num_pads: total number of sink and source pads 0630 * @pads: Array of @num_pads pads. 0631 * 0632 * The pads array is managed by the entity driver and passed to 0633 * media_entity_pads_init() where its pointer will be stored in the 0634 * &media_entity structure. 0635 * 0636 * If no pads are needed, drivers could either directly fill 0637 * &media_entity->num_pads with 0 and &media_entity->pads with %NULL or call 0638 * this function that will do the same. 0639 * 0640 * As the number of pads is known in advance, the pads array is not allocated 0641 * dynamically but is managed by the entity driver. Most drivers will embed the 0642 * pads array in a driver-specific structure, avoiding dynamic allocation. 0643 * 0644 * Drivers must set the direction of every pad in the pads array before calling 0645 * media_entity_pads_init(). The function will initialize the other pads fields. 0646 */ 0647 int media_entity_pads_init(struct media_entity *entity, u16 num_pads, 0648 struct media_pad *pads); 0649 0650 /** 0651 * media_entity_cleanup() - free resources associated with an entity 0652 * 0653 * @entity: entity where the pads belong 0654 * 0655 * This function must be called during the cleanup phase after unregistering 0656 * the entity (currently, it does nothing). 0657 * 0658 * Calling media_entity_cleanup() on a media_entity whose memory has been 0659 * zeroed but that has not been initialized with media_entity_pad_init() is 0660 * valid and is a no-op. 0661 */ 0662 #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER) 0663 static inline void media_entity_cleanup(struct media_entity *entity) {} 0664 #else 0665 #define media_entity_cleanup(entity) do { } while (false) 0666 #endif 0667 0668 /** 0669 * media_get_pad_index() - retrieves a pad index from an entity 0670 * 0671 * @entity: entity where the pads belong 0672 * @is_sink: true if the pad is a sink, false if it is a source 0673 * @sig_type: type of signal of the pad to be search 0674 * 0675 * This helper function finds the first pad index inside an entity that 0676 * satisfies both @is_sink and @sig_type conditions. 0677 * 0678 * Return: 0679 * 0680 * On success, return the pad number. If the pad was not found or the media 0681 * entity is a NULL pointer, return -EINVAL. 0682 */ 0683 int media_get_pad_index(struct media_entity *entity, bool is_sink, 0684 enum media_pad_signal_type sig_type); 0685 0686 /** 0687 * media_create_pad_link() - creates a link between two entities. 0688 * 0689 * @source: pointer to &media_entity of the source pad. 0690 * @source_pad: number of the source pad in the pads array 0691 * @sink: pointer to &media_entity of the sink pad. 0692 * @sink_pad: number of the sink pad in the pads array. 0693 * @flags: Link flags, as defined in 0694 * :ref:`include/uapi/linux/media.h <media_header>` 0695 * ( seek for ``MEDIA_LNK_FL_*``) 0696 * 0697 * Valid values for flags: 0698 * 0699 * %MEDIA_LNK_FL_ENABLED 0700 * Indicates that the link is enabled and can be used to transfer media data. 0701 * When two or more links target a sink pad, only one of them can be 0702 * enabled at a time. 0703 * 0704 * %MEDIA_LNK_FL_IMMUTABLE 0705 * Indicates that the link enabled state can't be modified at runtime. If 0706 * %MEDIA_LNK_FL_IMMUTABLE is set, then %MEDIA_LNK_FL_ENABLED must also be 0707 * set, since an immutable link is always enabled. 0708 * 0709 * .. note:: 0710 * 0711 * Before calling this function, media_entity_pads_init() and 0712 * media_device_register_entity() should be called previously for both ends. 0713 */ 0714 __must_check int media_create_pad_link(struct media_entity *source, 0715 u16 source_pad, struct media_entity *sink, 0716 u16 sink_pad, u32 flags); 0717 0718 /** 0719 * media_create_pad_links() - creates a link between two entities. 0720 * 0721 * @mdev: Pointer to the media_device that contains the object 0722 * @source_function: Function of the source entities. Used only if @source is 0723 * NULL. 0724 * @source: pointer to &media_entity of the source pad. If NULL, it will use 0725 * all entities that matches the @sink_function. 0726 * @source_pad: number of the source pad in the pads array 0727 * @sink_function: Function of the sink entities. Used only if @sink is NULL. 0728 * @sink: pointer to &media_entity of the sink pad. If NULL, it will use 0729 * all entities that matches the @sink_function. 0730 * @sink_pad: number of the sink pad in the pads array. 0731 * @flags: Link flags, as defined in include/uapi/linux/media.h. 0732 * @allow_both_undefined: if %true, then both @source and @sink can be NULL. 0733 * In such case, it will create a crossbar between all entities that 0734 * matches @source_function to all entities that matches @sink_function. 0735 * If %false, it will return 0 and won't create any link if both @source 0736 * and @sink are NULL. 0737 * 0738 * Valid values for flags: 0739 * 0740 * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be 0741 * used to transfer media data. If multiple links are created and this 0742 * flag is passed as an argument, only the first created link will have 0743 * this flag. 0744 * 0745 * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't 0746 * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then 0747 * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is 0748 * always enabled. 0749 * 0750 * It is common for some devices to have multiple source and/or sink entities 0751 * of the same type that should be linked. While media_create_pad_link() 0752 * creates link by link, this function is meant to allow 1:n, n:1 and even 0753 * cross-bar (n:n) links. 0754 * 0755 * .. note:: 0756 * 0757 * Before calling this function, media_entity_pads_init() and 0758 * media_device_register_entity() should be called previously for the 0759 * entities to be linked. 0760 */ 0761 int media_create_pad_links(const struct media_device *mdev, 0762 const u32 source_function, 0763 struct media_entity *source, 0764 const u16 source_pad, 0765 const u32 sink_function, 0766 struct media_entity *sink, 0767 const u16 sink_pad, 0768 u32 flags, 0769 const bool allow_both_undefined); 0770 0771 void __media_entity_remove_links(struct media_entity *entity); 0772 0773 /** 0774 * media_entity_remove_links() - remove all links associated with an entity 0775 * 0776 * @entity: pointer to &media_entity 0777 * 0778 * .. note:: 0779 * 0780 * This is called automatically when an entity is unregistered via 0781 * media_device_register_entity(). 0782 */ 0783 void media_entity_remove_links(struct media_entity *entity); 0784 0785 /** 0786 * __media_entity_setup_link - Configure a media link without locking 0787 * @link: The link being configured 0788 * @flags: Link configuration flags 0789 * 0790 * The bulk of link setup is handled by the two entities connected through the 0791 * link. This function notifies both entities of the link configuration change. 0792 * 0793 * If the link is immutable or if the current and new configuration are 0794 * identical, return immediately. 0795 * 0796 * The user is expected to hold link->source->parent->mutex. If not, 0797 * media_entity_setup_link() should be used instead. 0798 */ 0799 int __media_entity_setup_link(struct media_link *link, u32 flags); 0800 0801 /** 0802 * media_entity_setup_link() - changes the link flags properties in runtime 0803 * 0804 * @link: pointer to &media_link 0805 * @flags: the requested new link flags 0806 * 0807 * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag 0808 * to enable/disable a link. Links marked with the 0809 * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled. 0810 * 0811 * When a link is enabled or disabled, the media framework calls the 0812 * link_setup operation for the two entities at the source and sink of the 0813 * link, in that order. If the second link_setup call fails, another 0814 * link_setup call is made on the first entity to restore the original link 0815 * flags. 0816 * 0817 * Media device drivers can be notified of link setup operations by setting the 0818 * &media_device.link_notify pointer to a callback function. If provided, the 0819 * notification callback will be called before enabling and after disabling 0820 * links. 0821 * 0822 * Entity drivers must implement the link_setup operation if any of their links 0823 * is non-immutable. The operation must either configure the hardware or store 0824 * the configuration information to be applied later. 0825 * 0826 * Link configuration must not have any side effect on other links. If an 0827 * enabled link at a sink pad prevents another link at the same pad from 0828 * being enabled, the link_setup operation must return %-EBUSY and can't 0829 * implicitly disable the first enabled link. 0830 * 0831 * .. note:: 0832 * 0833 * The valid values of the flags for the link is the same as described 0834 * on media_create_pad_link(), for pad to pad links or the same as described 0835 * on media_create_intf_link(), for interface to entity links. 0836 */ 0837 int media_entity_setup_link(struct media_link *link, u32 flags); 0838 0839 /** 0840 * media_entity_find_link - Find a link between two pads 0841 * @source: Source pad 0842 * @sink: Sink pad 0843 * 0844 * Return: returns a pointer to the link between the two entities. If no 0845 * such link exists, return %NULL. 0846 */ 0847 struct media_link *media_entity_find_link(struct media_pad *source, 0848 struct media_pad *sink); 0849 0850 /** 0851 * media_pad_remote_pad_first - Find the first pad at the remote end of a link 0852 * @pad: Pad at the local end of the link 0853 * 0854 * Search for a remote pad connected to the given pad by iterating over all 0855 * links originating or terminating at that pad until an enabled link is found. 0856 * 0857 * Return: returns a pointer to the pad at the remote end of the first found 0858 * enabled link, or %NULL if no enabled link has been found. 0859 */ 0860 struct media_pad *media_pad_remote_pad_first(const struct media_pad *pad); 0861 0862 /** 0863 * media_pad_remote_pad_unique - Find a remote pad connected to a pad 0864 * @pad: The pad 0865 * 0866 * Search for and return a remote pad connected to @pad through an enabled 0867 * link. If multiple (or no) remote pads are found, an error is returned. 0868 * 0869 * The uniqueness constraint makes this helper function suitable for entities 0870 * that support a single active source at a time on a given pad. 0871 * 0872 * Return: A pointer to the remote pad, or one of the following error pointers 0873 * if an error occurs: 0874 * 0875 * * -ENOTUNIQ - Multiple links are enabled 0876 * * -ENOLINK - No connected pad found 0877 */ 0878 struct media_pad *media_pad_remote_pad_unique(const struct media_pad *pad); 0879 0880 /** 0881 * media_entity_remote_pad_unique - Find a remote pad connected to an entity 0882 * @entity: The entity 0883 * @type: The type of pad to find (MEDIA_PAD_FL_SINK or MEDIA_PAD_FL_SOURCE) 0884 * 0885 * Search for and return a remote pad of @type connected to @entity through an 0886 * enabled link. If multiple (or no) remote pads match these criteria, an error 0887 * is returned. 0888 * 0889 * The uniqueness constraint makes this helper function suitable for entities 0890 * that support a single active source or sink at a time. 0891 * 0892 * Return: A pointer to the remote pad, or one of the following error pointers 0893 * if an error occurs: 0894 * 0895 * * -ENOTUNIQ - Multiple links are enabled 0896 * * -ENOLINK - No connected pad found 0897 */ 0898 struct media_pad * 0899 media_entity_remote_pad_unique(const struct media_entity *entity, 0900 unsigned int type); 0901 0902 /** 0903 * media_entity_remote_source_pad_unique - Find a remote source pad connected to 0904 * an entity 0905 * @entity: The entity 0906 * 0907 * Search for and return a remote source pad connected to @entity through an 0908 * enabled link. If multiple (or no) remote pads match these criteria, an error 0909 * is returned. 0910 * 0911 * The uniqueness constraint makes this helper function suitable for entities 0912 * that support a single active source at a time. 0913 * 0914 * Return: A pointer to the remote pad, or one of the following error pointers 0915 * if an error occurs: 0916 * 0917 * * -ENOTUNIQ - Multiple links are enabled 0918 * * -ENOLINK - No connected pad found 0919 */ 0920 static inline struct media_pad * 0921 media_entity_remote_source_pad_unique(const struct media_entity *entity) 0922 { 0923 return media_entity_remote_pad_unique(entity, MEDIA_PAD_FL_SOURCE); 0924 } 0925 0926 /** 0927 * media_entity_is_streaming - Test if an entity is part of a streaming pipeline 0928 * @entity: The entity 0929 * 0930 * Return: True if the entity is part of a pipeline started with the 0931 * media_pipeline_start() function, false otherwise. 0932 */ 0933 static inline bool media_entity_is_streaming(const struct media_entity *entity) 0934 { 0935 return entity->pipe; 0936 } 0937 0938 /** 0939 * media_entity_get_fwnode_pad - Get pad number from fwnode 0940 * 0941 * @entity: The entity 0942 * @fwnode: Pointer to the fwnode_handle which should be used to find the pad 0943 * @direction_flags: Expected direction of the pad, as defined in 0944 * :ref:`include/uapi/linux/media.h <media_header>` 0945 * (seek for ``MEDIA_PAD_FL_*``) 0946 * 0947 * This function can be used to resolve the media pad number from 0948 * a fwnode. This is useful for devices which use more complex 0949 * mappings of media pads. 0950 * 0951 * If the entity does not implement the get_fwnode_pad() operation 0952 * then this function searches the entity for the first pad that 0953 * matches the @direction_flags. 0954 * 0955 * Return: returns the pad number on success or a negative error code. 0956 */ 0957 int media_entity_get_fwnode_pad(struct media_entity *entity, 0958 struct fwnode_handle *fwnode, 0959 unsigned long direction_flags); 0960 0961 /** 0962 * media_graph_walk_init - Allocate resources used by graph walk. 0963 * 0964 * @graph: Media graph structure that will be used to walk the graph 0965 * @mdev: Pointer to the &media_device that contains the object 0966 * 0967 * The caller is required to hold the media_device graph_mutex during the graph 0968 * walk until the graph state is released. 0969 * 0970 * Returns zero on success or a negative error code otherwise. 0971 */ 0972 __must_check int media_graph_walk_init( 0973 struct media_graph *graph, struct media_device *mdev); 0974 0975 /** 0976 * media_graph_walk_cleanup - Release resources used by graph walk. 0977 * 0978 * @graph: Media graph structure that will be used to walk the graph 0979 */ 0980 void media_graph_walk_cleanup(struct media_graph *graph); 0981 0982 /** 0983 * media_graph_walk_start - Start walking the media graph at a 0984 * given entity 0985 * 0986 * @graph: Media graph structure that will be used to walk the graph 0987 * @entity: Starting entity 0988 * 0989 * Before using this function, media_graph_walk_init() must be 0990 * used to allocate resources used for walking the graph. This 0991 * function initializes the graph traversal structure to walk the 0992 * entities graph starting at the given entity. The traversal 0993 * structure must not be modified by the caller during graph 0994 * traversal. After the graph walk, the resources must be released 0995 * using media_graph_walk_cleanup(). 0996 */ 0997 void media_graph_walk_start(struct media_graph *graph, 0998 struct media_entity *entity); 0999 1000 /** 1001 * media_graph_walk_next - Get the next entity in the graph 1002 * @graph: Media graph structure 1003 * 1004 * Perform a depth-first traversal of the given media entities graph. 1005 * 1006 * The graph structure must have been previously initialized with a call to 1007 * media_graph_walk_start(). 1008 * 1009 * Return: returns the next entity in the graph or %NULL if the whole graph 1010 * have been traversed. 1011 */ 1012 struct media_entity *media_graph_walk_next(struct media_graph *graph); 1013 1014 /** 1015 * media_pipeline_start - Mark a pipeline as streaming 1016 * @entity: Starting entity 1017 * @pipe: Media pipeline to be assigned to all entities in the pipeline. 1018 * 1019 * Mark all entities connected to a given entity through enabled links, either 1020 * directly or indirectly, as streaming. The given pipeline object is assigned 1021 * to every entity in the pipeline and stored in the media_entity pipe field. 1022 * 1023 * Calls to this function can be nested, in which case the same number of 1024 * media_pipeline_stop() calls will be required to stop streaming. The 1025 * pipeline pointer must be identical for all nested calls to 1026 * media_pipeline_start(). 1027 */ 1028 __must_check int media_pipeline_start(struct media_entity *entity, 1029 struct media_pipeline *pipe); 1030 /** 1031 * __media_pipeline_start - Mark a pipeline as streaming 1032 * 1033 * @entity: Starting entity 1034 * @pipe: Media pipeline to be assigned to all entities in the pipeline. 1035 * 1036 * ..note:: This is the non-locking version of media_pipeline_start() 1037 */ 1038 __must_check int __media_pipeline_start(struct media_entity *entity, 1039 struct media_pipeline *pipe); 1040 1041 /** 1042 * media_pipeline_stop - Mark a pipeline as not streaming 1043 * @entity: Starting entity 1044 * 1045 * Mark all entities connected to a given entity through enabled links, either 1046 * directly or indirectly, as not streaming. The media_entity pipe field is 1047 * reset to %NULL. 1048 * 1049 * If multiple calls to media_pipeline_start() have been made, the same 1050 * number of calls to this function are required to mark the pipeline as not 1051 * streaming. 1052 */ 1053 void media_pipeline_stop(struct media_entity *entity); 1054 1055 /** 1056 * __media_pipeline_stop - Mark a pipeline as not streaming 1057 * 1058 * @entity: Starting entity 1059 * 1060 * .. note:: This is the non-locking version of media_pipeline_stop() 1061 */ 1062 void __media_pipeline_stop(struct media_entity *entity); 1063 1064 /** 1065 * media_devnode_create() - creates and initializes a device node interface 1066 * 1067 * @mdev: pointer to struct &media_device 1068 * @type: type of the interface, as given by 1069 * :ref:`include/uapi/linux/media.h <media_header>` 1070 * ( seek for ``MEDIA_INTF_T_*``) macros. 1071 * @flags: Interface flags, as defined in 1072 * :ref:`include/uapi/linux/media.h <media_header>` 1073 * ( seek for ``MEDIA_INTF_FL_*``) 1074 * @major: Device node major number. 1075 * @minor: Device node minor number. 1076 * 1077 * Return: if succeeded, returns a pointer to the newly allocated 1078 * &media_intf_devnode pointer. 1079 * 1080 * .. note:: 1081 * 1082 * Currently, no flags for &media_interface is defined. 1083 */ 1084 struct media_intf_devnode * 1085 __must_check media_devnode_create(struct media_device *mdev, 1086 u32 type, u32 flags, 1087 u32 major, u32 minor); 1088 /** 1089 * media_devnode_remove() - removes a device node interface 1090 * 1091 * @devnode: pointer to &media_intf_devnode to be freed. 1092 * 1093 * When a device node interface is removed, all links to it are automatically 1094 * removed. 1095 */ 1096 void media_devnode_remove(struct media_intf_devnode *devnode); 1097 1098 /** 1099 * media_create_intf_link() - creates a link between an entity and an interface 1100 * 1101 * @entity: pointer to %media_entity 1102 * @intf: pointer to %media_interface 1103 * @flags: Link flags, as defined in 1104 * :ref:`include/uapi/linux/media.h <media_header>` 1105 * ( seek for ``MEDIA_LNK_FL_*``) 1106 * 1107 * 1108 * Valid values for flags: 1109 * 1110 * %MEDIA_LNK_FL_ENABLED 1111 * Indicates that the interface is connected to the entity hardware. 1112 * That's the default value for interfaces. An interface may be disabled if 1113 * the hardware is busy due to the usage of some other interface that it is 1114 * currently controlling the hardware. 1115 * 1116 * A typical example is an hybrid TV device that handle only one type of 1117 * stream on a given time. So, when the digital TV is streaming, 1118 * the V4L2 interfaces won't be enabled, as such device is not able to 1119 * also stream analog TV or radio. 1120 * 1121 * .. note:: 1122 * 1123 * Before calling this function, media_devnode_create() should be called for 1124 * the interface and media_device_register_entity() should be called for the 1125 * interface that will be part of the link. 1126 */ 1127 struct media_link * 1128 __must_check media_create_intf_link(struct media_entity *entity, 1129 struct media_interface *intf, 1130 u32 flags); 1131 /** 1132 * __media_remove_intf_link() - remove a single interface link 1133 * 1134 * @link: pointer to &media_link. 1135 * 1136 * .. note:: This is an unlocked version of media_remove_intf_link() 1137 */ 1138 void __media_remove_intf_link(struct media_link *link); 1139 1140 /** 1141 * media_remove_intf_link() - remove a single interface link 1142 * 1143 * @link: pointer to &media_link. 1144 * 1145 * .. note:: Prefer to use this one, instead of __media_remove_intf_link() 1146 */ 1147 void media_remove_intf_link(struct media_link *link); 1148 1149 /** 1150 * __media_remove_intf_links() - remove all links associated with an interface 1151 * 1152 * @intf: pointer to &media_interface 1153 * 1154 * .. note:: This is an unlocked version of media_remove_intf_links(). 1155 */ 1156 void __media_remove_intf_links(struct media_interface *intf); 1157 1158 /** 1159 * media_remove_intf_links() - remove all links associated with an interface 1160 * 1161 * @intf: pointer to &media_interface 1162 * 1163 * .. note:: 1164 * 1165 * #) This is called automatically when an entity is unregistered via 1166 * media_device_register_entity() and by media_devnode_remove(). 1167 * 1168 * #) Prefer to use this one, instead of __media_remove_intf_links(). 1169 */ 1170 void media_remove_intf_links(struct media_interface *intf); 1171 1172 /** 1173 * media_entity_call - Calls a struct media_entity_operations operation on 1174 * an entity 1175 * 1176 * @entity: entity where the @operation will be called 1177 * @operation: type of the operation. Should be the name of a member of 1178 * struct &media_entity_operations. 1179 * 1180 * This helper function will check if @operation is not %NULL. On such case, 1181 * it will issue a call to @operation\(@entity, @args\). 1182 */ 1183 1184 #define media_entity_call(entity, operation, args...) \ 1185 (((entity)->ops && (entity)->ops->operation) ? \ 1186 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) 1187 1188 /** 1189 * media_create_ancillary_link() - create an ancillary link between two 1190 * instances of &media_entity 1191 * 1192 * @primary: pointer to the primary &media_entity 1193 * @ancillary: pointer to the ancillary &media_entity 1194 * 1195 * Create an ancillary link between two entities, indicating that they 1196 * represent two connected pieces of hardware that form a single logical unit. 1197 * A typical example is a camera lens controller being linked to the sensor that 1198 * it is supporting. 1199 * 1200 * The function sets both MEDIA_LNK_FL_ENABLED and MEDIA_LNK_FL_IMMUTABLE for 1201 * the new link. 1202 */ 1203 struct media_link * 1204 media_create_ancillary_link(struct media_entity *primary, 1205 struct media_entity *ancillary); 1206 1207 /** 1208 * __media_entity_next_link() - Iterate through a &media_entity's links 1209 * 1210 * @entity: pointer to the &media_entity 1211 * @link: pointer to a &media_link to hold the iterated values 1212 * @link_type: one of the MEDIA_LNK_FL_LINK_TYPE flags 1213 * 1214 * Return the next link against an entity matching a specific link type. This 1215 * allows iteration through an entity's links whilst guaranteeing all of the 1216 * returned links are of the given type. 1217 */ 1218 struct media_link *__media_entity_next_link(struct media_entity *entity, 1219 struct media_link *link, 1220 unsigned long link_type); 1221 1222 /** 1223 * for_each_media_entity_data_link() - Iterate through an entity's data links 1224 * 1225 * @entity: pointer to the &media_entity 1226 * @link: pointer to a &media_link to hold the iterated values 1227 * 1228 * Iterate over a &media_entity's data links 1229 */ 1230 #define for_each_media_entity_data_link(entity, link) \ 1231 for (link = __media_entity_next_link(entity, NULL, \ 1232 MEDIA_LNK_FL_DATA_LINK); \ 1233 link; \ 1234 link = __media_entity_next_link(entity, link, \ 1235 MEDIA_LNK_FL_DATA_LINK)) 1236 1237 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |