1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Media entity 4 * 5 * Copyright (C) 2010 Nokia Corporation 6 * 7 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 8 * Sakari Ailus <sakari.ailus@iki.fi> 9 */ 10 11 #ifndef _MEDIA_ENTITY_H 12 #define _MEDIA_ENTITY_H 13 14 #include <linux/bitmap.h> 15 #include <linux/bug.h> 16 #include <linux/container_of.h> 17 #include <linux/fwnode.h> 18 #include <linux/list.h> 19 #include <linux/media.h> 20 #include <linux/minmax.h> 21 #include <linux/types.h> 22 23 /* Enums used internally at the media controller to represent graphs */ 24 25 /** 26 * enum media_gobj_type - type of a graph object 27 * 28 * @MEDIA_GRAPH_ENTITY: Identify a media entity 29 * @MEDIA_GRAPH_PAD: Identify a media pad 30 * @MEDIA_GRAPH_LINK: Identify a media link 31 * @MEDIA_GRAPH_INTF_DEVNODE: Identify a media Kernel API interface via 32 * a device node 33 */ 34 enum media_gobj_type { 35 MEDIA_GRAPH_ENTITY, 36 MEDIA_GRAPH_PAD, 37 MEDIA_GRAPH_LINK, 38 MEDIA_GRAPH_INTF_DEVNODE, 39 }; 40 41 #define MEDIA_BITS_PER_TYPE 8 42 #define MEDIA_BITS_PER_ID (32 - MEDIA_BITS_PER_TYPE) 43 #define MEDIA_ID_MASK GENMASK_ULL(MEDIA_BITS_PER_ID - 1, 0) 44 45 /* Structs to represent the objects that belong to a media graph */ 46 47 /** 48 * struct media_gobj - Define a graph object. 49 * 50 * @mdev: Pointer to the struct &media_device that owns the object 51 * @id: Non-zero object ID identifier. The ID should be unique 52 * inside a media_device, as it is composed by 53 * %MEDIA_BITS_PER_TYPE to store the type plus 54 * %MEDIA_BITS_PER_ID to store the ID 55 * @list: List entry stored in one of the per-type mdev object lists 56 * 57 * All objects on the media graph should have this struct embedded 58 */ 59 struct media_gobj { 60 struct media_device *mdev; 61 u32 id; 62 struct list_head list; 63 }; 64 65 #define MEDIA_ENTITY_ENUM_MAX_DEPTH 16 66 67 /** 68 * struct media_entity_enum - An enumeration of media entities. 69 * 70 * @bmap: Bit map in which each bit represents one entity at struct 71 * media_entity->internal_idx. 72 * @idx_max: Number of bits in bmap 73 */ 74 struct media_entity_enum { 75 unsigned long *bmap; 76 int idx_max; 77 }; 78 79 /** 80 * struct media_graph - Media graph traversal state 81 * 82 * @stack: Graph traversal stack; the stack contains information 83 * on the path the media entities to be walked and the 84 * links through which they were reached. 85 * @stack.entity: pointer to &struct media_entity at the graph. 86 * @stack.link: pointer to &struct list_head. 87 * @ent_enum: Visited entities 88 * @top: The top of the stack 89 */ 90 struct media_graph { 91 struct { 92 struct media_entity *entity; 93 struct list_head *link; 94 } stack[MEDIA_ENTITY_ENUM_MAX_DEPTH]; 95 96 struct media_entity_enum ent_enum; 97 int top; 98 }; 99 100 /** 101 * struct media_pipeline - Media pipeline related information 102 * 103 * @allocated: Media pipeline allocated and freed by the framework 104 * @mdev: The media device the pipeline is part of 105 * @pads: List of media_pipeline_pad 106 * @start_count: Media pipeline start - stop count 107 */ 108 struct media_pipeline { 109 bool allocated; 110 struct media_device *mdev; 111 struct list_head pads; 112 int start_count; 113 }; 114 115 /** 116 * struct media_pipeline_pad - A pad part of a media pipeline 117 * 118 * @list: Entry in the media_pad pads list 119 * @pipe: The media_pipeline that the pad is part of 120 * @pad: The media pad 121 * 122 * This structure associate a pad with a media pipeline. Instances of 123 * media_pipeline_pad are created by media_pipeline_start() when it builds the 124 * pipeline, and stored in the &media_pad.pads list. media_pipeline_stop() 125 * removes the entries from the list and deletes them. 126 */ 127 struct media_pipeline_pad { 128 struct list_head list; 129 struct media_pipeline *pipe; 130 struct media_pad *pad; 131 }; 132 133 /** 134 * struct media_link - A link object part of a media graph. 135 * 136 * @graph_obj: Embedded structure containing the media object common data 137 * @list: Linked list associated with an entity or an interface that 138 * owns the link. 139 * @gobj0: Part of a union. Used to get the pointer for the first 140 * graph_object of the link. 141 * @source: Part of a union. Used only if the first object (gobj0) is 142 * a pad. In that case, it represents the source pad. 143 * @intf: Part of a union. Used only if the first object (gobj0) is 144 * an interface. 145 * @gobj1: Part of a union. Used to get the pointer for the second 146 * graph_object of the link. 147 * @sink: Part of a union. Used only if the second object (gobj1) is 148 * a pad. In that case, it represents the sink pad. 149 * @entity: Part of a union. Used only if the second object (gobj1) is 150 * an entity. 151 * @reverse: Pointer to the link for the reverse direction of a pad to pad 152 * link. 153 * @flags: Link flags, as defined in uapi/media.h (MEDIA_LNK_FL_*) 154 * @is_backlink: Indicate if the link is a backlink. 155 */ 156 struct media_link { 157 struct media_gobj graph_obj; 158 struct list_head list; 159 union { 160 struct media_gobj *gobj0; 161 struct media_pad *source; 162 struct media_interface *intf; 163 }; 164 union { 165 struct media_gobj *gobj1; 166 struct media_pad *sink; 167 struct media_entity *entity; 168 }; 169 struct media_link *reverse; 170 unsigned long flags; 171 bool is_backlink; 172 }; 173 174 /** 175 * enum media_pad_signal_type - type of the signal inside a media pad 176 * 177 * @PAD_SIGNAL_DEFAULT: 178 * Default signal. Use this when all inputs or all outputs are 179 * uniquely identified by the pad number. 180 * @PAD_SIGNAL_ANALOG: 181 * The pad contains an analog signal. It can be Radio Frequency, 182 * Intermediate Frequency, a baseband signal or sub-carriers. 183 * Tuner inputs, IF-PLL demodulators, composite and s-video signals 184 * should use it. 185 * @PAD_SIGNAL_DV: 186 * Contains a digital video signal, with can be a bitstream of samples 187 * taken from an analog TV video source. On such case, it usually 188 * contains the VBI data on it. 189 * @PAD_SIGNAL_AUDIO: 190 * Contains an Intermediate Frequency analog signal from an audio 191 * sub-carrier or an audio bitstream. IF signals are provided by tuners 192 * and consumed by audio AM/FM decoders. Bitstream audio is provided by 193 * an audio decoder. 194 */ 195 enum media_pad_signal_type { 196 PAD_SIGNAL_DEFAULT = 0, 197 PAD_SIGNAL_ANALOG, 198 PAD_SIGNAL_DV, 199 PAD_SIGNAL_AUDIO, 200 }; 201 202 /** 203 * struct media_pad - A media pad graph object. 204 * 205 * @graph_obj: Embedded structure containing the media object common data 206 * @entity: Entity this pad belongs to 207 * @index: Pad index in the entity pads array, numbered from 0 to n 208 * @sig_type: Type of the signal inside a media pad 209 * @flags: Pad flags, as defined in 210 * :ref:`include/uapi/linux/media.h <media_header>` 211 * (seek for ``MEDIA_PAD_FL_*``) 212 * @pipe: Pipeline this pad belongs to. Use media_entity_pipeline() to 213 * access this field. 214 */ 215 struct media_pad { 216 struct media_gobj graph_obj; /* must be first field in struct */ 217 struct media_entity *entity; 218 u16 index; 219 enum media_pad_signal_type sig_type; 220 unsigned long flags; 221 222 /* 223 * The fields below are private, and should only be accessed via 224 * appropriate functions. 225 */ 226 struct media_pipeline *pipe; 227 }; 228 229 /** 230 * struct media_entity_operations - Media entity operations 231 * @get_fwnode_pad: Return the pad number based on a fwnode endpoint or 232 * a negative value on error. This operation can be used 233 * to map a fwnode to a media pad number. Optional. 234 * @link_setup: Notify the entity of link changes. The operation can 235 * return an error, in which case link setup will be 236 * cancelled. Optional. 237 * @link_validate: Return whether a link is valid from the entity point of 238 * view. The media_pipeline_start() function 239 * validates all links by calling this operation. Optional. 240 * @has_pad_interdep: Return whether two pads of the entity are 241 * interdependent. If two pads are interdependent they are 242 * part of the same pipeline and enabling one of the pads 243 * means that the other pad will become "locked" and 244 * doesn't allow configuration changes. pad0 and pad1 are 245 * guaranteed to not both be sinks or sources. Never call 246 * the .has_pad_interdep() operation directly, always use 247 * media_entity_has_pad_interdep(). 248 * Optional: If the operation isn't implemented all pads 249 * will be considered as interdependent. 250 * 251 * .. note:: 252 * 253 * Those these callbacks are called with struct &media_device.graph_mutex 254 * mutex held. 255 */ 256 struct media_entity_operations { 257 int (*get_fwnode_pad)(struct media_entity *entity, 258 struct fwnode_endpoint *endpoint); 259 int (*link_setup)(struct media_entity *entity, 260 const struct media_pad *local, 261 const struct media_pad *remote, u32 flags); 262 int (*link_validate)(struct media_link *link); 263 bool (*has_pad_interdep)(struct media_entity *entity, unsigned int pad0, 264 unsigned int pad1); 265 }; 266 267 /** 268 * enum media_entity_type - Media entity type 269 * 270 * @MEDIA_ENTITY_TYPE_BASE: 271 * The entity isn't embedded in another subsystem structure. 272 * @MEDIA_ENTITY_TYPE_VIDEO_DEVICE: 273 * The entity is embedded in a struct video_device instance. 274 * @MEDIA_ENTITY_TYPE_V4L2_SUBDEV: 275 * The entity is embedded in a struct v4l2_subdev instance. 276 * 277 * Media entity objects are often not instantiated directly, but the media 278 * entity structure is inherited by (through embedding) other subsystem-specific 279 * structures. The media entity type identifies the type of the subclass 280 * structure that implements a media entity instance. 281 * 282 * This allows runtime type identification of media entities and safe casting to 283 * the correct object type. For instance, a media entity structure instance 284 * embedded in a v4l2_subdev structure instance will have the type 285 * %MEDIA_ENTITY_TYPE_V4L2_SUBDEV and can safely be cast to a &v4l2_subdev 286 * structure using the container_of() macro. 287 */ 288 enum media_entity_type { 289 MEDIA_ENTITY_TYPE_BASE, 290 MEDIA_ENTITY_TYPE_VIDEO_DEVICE, 291 MEDIA_ENTITY_TYPE_V4L2_SUBDEV, 292 }; 293 294 /** 295 * struct media_entity - A media entity graph object. 296 * 297 * @graph_obj: Embedded structure containing the media object common data. 298 * @name: Entity name. 299 * @obj_type: Type of the object that implements the media_entity. 300 * @function: Entity main function, as defined in 301 * :ref:`include/uapi/linux/media.h <media_header>` 302 * (seek for ``MEDIA_ENT_F_*``) 303 * @flags: Entity flags, as defined in 304 * :ref:`include/uapi/linux/media.h <media_header>` 305 * (seek for ``MEDIA_ENT_FL_*``) 306 * @num_pads: Number of sink and source pads. 307 * @num_links: Total number of links, forward and back, enabled and disabled. 308 * @num_backlinks: Number of backlinks 309 * @internal_idx: An unique internal entity specific number. The numbers are 310 * re-used if entities are unregistered or registered again. 311 * @pads: Pads array with the size defined by @num_pads. 312 * @links: List of data links. 313 * @ops: Entity operations. 314 * @use_count: Use count for the entity. 315 * @info: Union with devnode information. Kept just for backward 316 * compatibility. 317 * @info.dev: Contains device major and minor info. 318 * @info.dev.major: device node major, if the device is a devnode. 319 * @info.dev.minor: device node minor, if the device is a devnode. 320 * @major: Devnode major number (zero if not applicable). Kept just 321 * for backward compatibility. 322 * @minor: Devnode minor number (zero if not applicable). Kept just 323 * for backward compatibility. 324 * 325 * .. note:: 326 * 327 * The @use_count reference count must never be negative, but is a signed 328 * integer on purpose: a simple ``WARN_ON(<0)`` check can be used to detect 329 * reference count bugs that would make it negative. 330 */ 331 struct media_entity { 332 struct media_gobj graph_obj; /* must be first field in struct */ 333 const char *name; 334 enum media_entity_type obj_type; 335 u32 function; 336 unsigned long flags; 337 338 u16 num_pads; 339 u16 num_links; 340 u16 num_backlinks; 341 int internal_idx; 342 343 struct media_pad *pads; 344 struct list_head links; 345 346 const struct media_entity_operations *ops; 347 348 int use_count; 349 350 union { 351 struct { 352 u32 major; 353 u32 minor; 354 } dev; 355 } info; 356 }; 357 358 /** 359 * media_entity_for_each_pad - Iterate on all pads in an entity 360 * @entity: The entity the pads belong to 361 * @iter: The iterator pad 362 * 363 * Iterate on all pads in a media entity. 364 */ 365 #define media_entity_for_each_pad(entity, iter) \ 366 for (iter = (entity)->pads; \ 367 iter < &(entity)->pads[(entity)->num_pads]; \ 368 ++iter) 369 370 /** 371 * struct media_interface - A media interface graph object. 372 * 373 * @graph_obj: embedded graph object 374 * @links: List of links pointing to graph entities 375 * @type: Type of the interface as defined in 376 * :ref:`include/uapi/linux/media.h <media_header>` 377 * (seek for ``MEDIA_INTF_T_*``) 378 * @flags: Interface flags as defined in 379 * :ref:`include/uapi/linux/media.h <media_header>` 380 * (seek for ``MEDIA_INTF_FL_*``) 381 * 382 * .. note:: 383 * 384 * Currently, no flags for &media_interface is defined. 385 */ 386 struct media_interface { 387 struct media_gobj graph_obj; 388 struct list_head links; 389 u32 type; 390 u32 flags; 391 }; 392 393 /** 394 * struct media_intf_devnode - A media interface via a device node. 395 * 396 * @intf: embedded interface object 397 * @major: Major number of a device node 398 * @minor: Minor number of a device node 399 */ 400 struct media_intf_devnode { 401 struct media_interface intf; 402 403 /* Should match the fields at media_v2_intf_devnode */ 404 u32 major; 405 u32 minor; 406 }; 407 408 /** 409 * media_entity_id() - return the media entity graph object id 410 * 411 * @entity: pointer to &media_entity 412 */ 413 static inline u32 media_entity_id(struct media_entity *entity) 414 { 415 return entity->graph_obj.id; 416 } 417 418 /** 419 * media_type() - return the media object type 420 * 421 * @gobj: Pointer to the struct &media_gobj graph object 422 */ 423 static inline enum media_gobj_type media_type(struct media_gobj *gobj) 424 { 425 return gobj->id >> MEDIA_BITS_PER_ID; 426 } 427 428 /** 429 * media_id() - return the media object ID 430 * 431 * @gobj: Pointer to the struct &media_gobj graph object 432 */ 433 static inline u32 media_id(struct media_gobj *gobj) 434 { 435 return gobj->id & MEDIA_ID_MASK; 436 } 437 438 /** 439 * media_gobj_gen_id() - encapsulates type and ID on at the object ID 440 * 441 * @type: object type as define at enum &media_gobj_type. 442 * @local_id: next ID, from struct &media_device.id. 443 */ 444 static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id) 445 { 446 u32 id; 447 448 id = type << MEDIA_BITS_PER_ID; 449 id |= local_id & MEDIA_ID_MASK; 450 451 return id; 452 } 453 454 /** 455 * is_media_entity_v4l2_video_device() - Check if the entity is a video_device 456 * @entity: pointer to entity 457 * 458 * Return: %true if the entity is an instance of a video_device object and can 459 * safely be cast to a struct video_device using the container_of() macro, or 460 * %false otherwise. 461 */ 462 static inline bool is_media_entity_v4l2_video_device(struct media_entity *entity) 463 { 464 return entity && entity->obj_type == MEDIA_ENTITY_TYPE_VIDEO_DEVICE; 465 } 466 467 /** 468 * is_media_entity_v4l2_subdev() - Check if the entity is a v4l2_subdev 469 * @entity: pointer to entity 470 * 471 * Return: %true if the entity is an instance of a &v4l2_subdev object and can 472 * safely be cast to a struct &v4l2_subdev using the container_of() macro, or 473 * %false otherwise. 474 */ 475 static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity) 476 { 477 return entity && entity->obj_type == MEDIA_ENTITY_TYPE_V4L2_SUBDEV; 478 } 479 480 /** 481 * media_entity_enum_init - Initialise an entity enumeration 482 * 483 * @ent_enum: Entity enumeration to be initialised 484 * @mdev: The related media device 485 * 486 * Return: zero on success or a negative error code. 487 */ 488 __must_check int media_entity_enum_init(struct media_entity_enum *ent_enum, 489 struct media_device *mdev); 490 491 /** 492 * media_entity_enum_cleanup - Release resources of an entity enumeration 493 * 494 * @ent_enum: Entity enumeration to be released 495 */ 496 void media_entity_enum_cleanup(struct media_entity_enum *ent_enum); 497 498 /** 499 * media_entity_enum_zero - Clear the entire enum 500 * 501 * @ent_enum: Entity enumeration to be cleared 502 */ 503 static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum) 504 { 505 bitmap_zero(ent_enum->bmap, ent_enum->idx_max); 506 } 507 508 /** 509 * media_entity_enum_set - Mark a single entity in the enum 510 * 511 * @ent_enum: Entity enumeration 512 * @entity: Entity to be marked 513 */ 514 static inline void media_entity_enum_set(struct media_entity_enum *ent_enum, 515 struct media_entity *entity) 516 { 517 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) 518 return; 519 520 __set_bit(entity->internal_idx, ent_enum->bmap); 521 } 522 523 /** 524 * media_entity_enum_clear - Unmark a single entity in the enum 525 * 526 * @ent_enum: Entity enumeration 527 * @entity: Entity to be unmarked 528 */ 529 static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum, 530 struct media_entity *entity) 531 { 532 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) 533 return; 534 535 __clear_bit(entity->internal_idx, ent_enum->bmap); 536 } 537 538 /** 539 * media_entity_enum_test - Test whether the entity is marked 540 * 541 * @ent_enum: Entity enumeration 542 * @entity: Entity to be tested 543 * 544 * Returns %true if the entity was marked. 545 */ 546 static inline bool media_entity_enum_test(struct media_entity_enum *ent_enum, 547 struct media_entity *entity) 548 { 549 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) 550 return true; 551 552 return test_bit(entity->internal_idx, ent_enum->bmap); 553 } 554 555 /** 556 * media_entity_enum_test_and_set - Test whether the entity is marked, 557 * and mark it 558 * 559 * @ent_enum: Entity enumeration 560 * @entity: Entity to be tested 561 * 562 * Returns %true if the entity was marked, and mark it before doing so. 563 */ 564 static inline bool 565 media_entity_enum_test_and_set(struct media_entity_enum *ent_enum, 566 struct media_entity *entity) 567 { 568 if (WARN_ON(entity->internal_idx >= ent_enum->idx_max)) 569 return true; 570 571 return __test_and_set_bit(entity->internal_idx, ent_enum->bmap); 572 } 573 574 /** 575 * media_entity_enum_empty - Test whether the entire enum is empty 576 * 577 * @ent_enum: Entity enumeration 578 * 579 * Return: %true if the entity was empty. 580 */ 581 static inline bool media_entity_enum_empty(struct media_entity_enum *ent_enum) 582 { 583 return bitmap_empty(ent_enum->bmap, ent_enum->idx_max); 584 } 585 586 /** 587 * media_entity_enum_intersects - Test whether two enums intersect 588 * 589 * @ent_enum1: First entity enumeration 590 * @ent_enum2: Second entity enumeration 591 * 592 * Return: %true if entity enumerations @ent_enum1 and @ent_enum2 intersect, 593 * otherwise %false. 594 */ 595 static inline bool media_entity_enum_intersects( 596 struct media_entity_enum *ent_enum1, 597 struct media_entity_enum *ent_enum2) 598 { 599 WARN_ON(ent_enum1->idx_max != ent_enum2->idx_max); 600 601 return bitmap_intersects(ent_enum1->bmap, ent_enum2->bmap, 602 min(ent_enum1->idx_max, ent_enum2->idx_max)); 603 } 604 605 /** 606 * gobj_to_entity - returns the struct &media_entity pointer from the 607 * @gobj contained on it. 608 * 609 * @gobj: Pointer to the struct &media_gobj graph object 610 */ 611 #define gobj_to_entity(gobj) \ 612 container_of(gobj, struct media_entity, graph_obj) 613 614 /** 615 * gobj_to_pad - returns the struct &media_pad pointer from the 616 * @gobj contained on it. 617 * 618 * @gobj: Pointer to the struct &media_gobj graph object 619 */ 620 #define gobj_to_pad(gobj) \ 621 container_of(gobj, struct media_pad, graph_obj) 622 623 /** 624 * gobj_to_link - returns the struct &media_link pointer from the 625 * @gobj contained on it. 626 * 627 * @gobj: Pointer to the struct &media_gobj graph object 628 */ 629 #define gobj_to_link(gobj) \ 630 container_of(gobj, struct media_link, graph_obj) 631 632 /** 633 * gobj_to_intf - returns the struct &media_interface pointer from the 634 * @gobj contained on it. 635 * 636 * @gobj: Pointer to the struct &media_gobj graph object 637 */ 638 #define gobj_to_intf(gobj) \ 639 container_of(gobj, struct media_interface, graph_obj) 640 641 /** 642 * intf_to_devnode - returns the struct media_intf_devnode pointer from the 643 * @intf contained on it. 644 * 645 * @intf: Pointer to struct &media_intf_devnode 646 */ 647 #define intf_to_devnode(intf) \ 648 container_of(intf, struct media_intf_devnode, intf) 649 650 /** 651 * media_gobj_create - Initialize a graph object 652 * 653 * @mdev: Pointer to the &media_device that contains the object 654 * @type: Type of the object 655 * @gobj: Pointer to the struct &media_gobj graph object 656 * 657 * This routine initializes the embedded struct &media_gobj inside a 658 * media graph object. It is called automatically if ``media_*_create`` 659 * function calls are used. However, if the object (entity, link, pad, 660 * interface) is embedded on some other object, this function should be 661 * called before registering the object at the media controller. 662 */ 663 void media_gobj_create(struct media_device *mdev, 664 enum media_gobj_type type, 665 struct media_gobj *gobj); 666 667 /** 668 * media_gobj_destroy - Stop using a graph object on a media device 669 * 670 * @gobj: Pointer to the struct &media_gobj graph object 671 * 672 * This should be called by all routines like media_device_unregister() 673 * that remove/destroy media graph objects. 674 */ 675 void media_gobj_destroy(struct media_gobj *gobj); 676 677 /** 678 * media_entity_pads_init() - Initialize the entity pads 679 * 680 * @entity: entity where the pads belong 681 * @num_pads: total number of sink and source pads 682 * @pads: Array of @num_pads pads. 683 * 684 * The pads array is managed by the entity driver and passed to 685 * media_entity_pads_init() where its pointer will be stored in the 686 * &media_entity structure. 687 * 688 * If no pads are needed, drivers could either directly fill 689 * &media_entity->num_pads with 0 and &media_entity->pads with %NULL or call 690 * this function that will do the same. 691 * 692 * As the number of pads is known in advance, the pads array is not allocated 693 * dynamically but is managed by the entity driver. Most drivers will embed the 694 * pads array in a driver-specific structure, avoiding dynamic allocation. 695 * 696 * Drivers must set the direction of every pad in the pads array before calling 697 * media_entity_pads_init(). The function will initialize the other pads fields. 698 */ 699 int media_entity_pads_init(struct media_entity *entity, u16 num_pads, 700 struct media_pad *pads); 701 702 /** 703 * media_entity_cleanup() - free resources associated with an entity 704 * 705 * @entity: entity where the pads belong 706 * 707 * This function must be called during the cleanup phase after unregistering 708 * the entity (currently, it does nothing). 709 * 710 * Calling media_entity_cleanup() on a media_entity whose memory has been 711 * zeroed but that has not been initialized with media_entity_pad_init() is 712 * valid and is a no-op. 713 */ 714 #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER) 715 static inline void media_entity_cleanup(struct media_entity *entity) {} 716 #else 717 #define media_entity_cleanup(entity) do { } while (false) 718 #endif 719 720 /** 721 * media_get_pad_index() - retrieves a pad index from an entity 722 * 723 * @entity: entity where the pads belong 724 * @is_sink: true if the pad is a sink, false if it is a source 725 * @sig_type: type of signal of the pad to be search 726 * 727 * This helper function finds the first pad index inside an entity that 728 * satisfies both @is_sink and @sig_type conditions. 729 * 730 * Return: 731 * 732 * On success, return the pad number. If the pad was not found or the media 733 * entity is a NULL pointer, return -EINVAL. 734 */ 735 int media_get_pad_index(struct media_entity *entity, bool is_sink, 736 enum media_pad_signal_type sig_type); 737 738 /** 739 * media_create_pad_link() - creates a link between two entities. 740 * 741 * @source: pointer to &media_entity of the source pad. 742 * @source_pad: number of the source pad in the pads array 743 * @sink: pointer to &media_entity of the sink pad. 744 * @sink_pad: number of the sink pad in the pads array. 745 * @flags: Link flags, as defined in 746 * :ref:`include/uapi/linux/media.h <media_header>` 747 * ( seek for ``MEDIA_LNK_FL_*``) 748 * 749 * Valid values for flags: 750 * 751 * %MEDIA_LNK_FL_ENABLED 752 * Indicates that the link is enabled and can be used to transfer media data. 753 * When two or more links target a sink pad, only one of them can be 754 * enabled at a time. 755 * 756 * %MEDIA_LNK_FL_IMMUTABLE 757 * Indicates that the link enabled state can't be modified at runtime. If 758 * %MEDIA_LNK_FL_IMMUTABLE is set, then %MEDIA_LNK_FL_ENABLED must also be 759 * set, since an immutable link is always enabled. 760 * 761 * .. note:: 762 * 763 * Before calling this function, media_entity_pads_init() and 764 * media_device_register_entity() should be called previously for both ends. 765 */ 766 __must_check int media_create_pad_link(struct media_entity *source, 767 u16 source_pad, struct media_entity *sink, 768 u16 sink_pad, u32 flags); 769 770 /** 771 * media_create_pad_links() - creates a link between two entities. 772 * 773 * @mdev: Pointer to the media_device that contains the object 774 * @source_function: Function of the source entities. Used only if @source is 775 * NULL. 776 * @source: pointer to &media_entity of the source pad. If NULL, it will use 777 * all entities that matches the @sink_function. 778 * @source_pad: number of the source pad in the pads array 779 * @sink_function: Function of the sink entities. Used only if @sink is NULL. 780 * @sink: pointer to &media_entity of the sink pad. If NULL, it will use 781 * all entities that matches the @sink_function. 782 * @sink_pad: number of the sink pad in the pads array. 783 * @flags: Link flags, as defined in include/uapi/linux/media.h. 784 * @allow_both_undefined: if %true, then both @source and @sink can be NULL. 785 * In such case, it will create a crossbar between all entities that 786 * matches @source_function to all entities that matches @sink_function. 787 * If %false, it will return 0 and won't create any link if both @source 788 * and @sink are NULL. 789 * 790 * Valid values for flags: 791 * 792 * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be 793 * used to transfer media data. If multiple links are created and this 794 * flag is passed as an argument, only the first created link will have 795 * this flag. 796 * 797 * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't 798 * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then 799 * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is 800 * always enabled. 801 * 802 * It is common for some devices to have multiple source and/or sink entities 803 * of the same type that should be linked. While media_create_pad_link() 804 * creates link by link, this function is meant to allow 1:n, n:1 and even 805 * cross-bar (n:n) links. 806 * 807 * .. note:: 808 * 809 * Before calling this function, media_entity_pads_init() and 810 * media_device_register_entity() should be called previously for the 811 * entities to be linked. 812 */ 813 int media_create_pad_links(const struct media_device *mdev, 814 const u32 source_function, 815 struct media_entity *source, 816 const u16 source_pad, 817 const u32 sink_function, 818 struct media_entity *sink, 819 const u16 sink_pad, 820 u32 flags, 821 const bool allow_both_undefined); 822 823 void __media_entity_remove_links(struct media_entity *entity); 824 825 /** 826 * media_entity_remove_links() - remove all links associated with an entity 827 * 828 * @entity: pointer to &media_entity 829 * 830 * .. note:: 831 * 832 * This is called automatically when an entity is unregistered via 833 * media_device_register_entity(). 834 */ 835 void media_entity_remove_links(struct media_entity *entity); 836 837 /** 838 * __media_entity_setup_link - Configure a media link without locking 839 * @link: The link being configured 840 * @flags: Link configuration flags 841 * 842 * The bulk of link setup is handled by the two entities connected through the 843 * link. This function notifies both entities of the link configuration change. 844 * 845 * If the link is immutable or if the current and new configuration are 846 * identical, return immediately. 847 * 848 * The user is expected to hold link->source->parent->mutex. If not, 849 * media_entity_setup_link() should be used instead. 850 */ 851 int __media_entity_setup_link(struct media_link *link, u32 flags); 852 853 /** 854 * media_entity_setup_link() - changes the link flags properties in runtime 855 * 856 * @link: pointer to &media_link 857 * @flags: the requested new link flags 858 * 859 * The only configurable property is the %MEDIA_LNK_FL_ENABLED link flag 860 * to enable/disable a link. Links marked with the 861 * %MEDIA_LNK_FL_IMMUTABLE link flag can not be enabled or disabled. 862 * 863 * When a link is enabled or disabled, the media framework calls the 864 * link_setup operation for the two entities at the source and sink of the 865 * link, in that order. If the second link_setup call fails, another 866 * link_setup call is made on the first entity to restore the original link 867 * flags. 868 * 869 * Media device drivers can be notified of link setup operations by setting the 870 * &media_device.link_notify pointer to a callback function. If provided, the 871 * notification callback will be called before enabling and after disabling 872 * links. 873 * 874 * Entity drivers must implement the link_setup operation if any of their links 875 * is non-immutable. The operation must either configure the hardware or store 876 * the configuration information to be applied later. 877 * 878 * Link configuration must not have any side effect on other links. If an 879 * enabled link at a sink pad prevents another link at the same pad from 880 * being enabled, the link_setup operation must return %-EBUSY and can't 881 * implicitly disable the first enabled link. 882 * 883 * .. note:: 884 * 885 * The valid values of the flags for the link is the same as described 886 * on media_create_pad_link(), for pad to pad links or the same as described 887 * on media_create_intf_link(), for interface to entity links. 888 */ 889 int media_entity_setup_link(struct media_link *link, u32 flags); 890 891 /** 892 * media_entity_find_link - Find a link between two pads 893 * @source: Source pad 894 * @sink: Sink pad 895 * 896 * Return: returns a pointer to the link between the two entities. If no 897 * such link exists, return %NULL. 898 */ 899 struct media_link *media_entity_find_link(struct media_pad *source, 900 struct media_pad *sink); 901 902 /** 903 * media_pad_remote_pad_first - Find the first pad at the remote end of a link 904 * @pad: Pad at the local end of the link 905 * 906 * Search for a remote pad connected to the given pad by iterating over all 907 * links originating or terminating at that pad until an enabled link is found. 908 * 909 * Return: returns a pointer to the pad at the remote end of the first found 910 * enabled link, or %NULL if no enabled link has been found. 911 */ 912 struct media_pad *media_pad_remote_pad_first(const struct media_pad *pad); 913 914 /** 915 * media_pad_remote_pad_unique - Find a remote pad connected to a pad 916 * @pad: The pad 917 * 918 * Search for and return a remote pad connected to @pad through an enabled 919 * link. If multiple (or no) remote pads are found, an error is returned. 920 * 921 * The uniqueness constraint makes this helper function suitable for entities 922 * that support a single active source at a time on a given pad. 923 * 924 * Return: A pointer to the remote pad, or one of the following error pointers 925 * if an error occurs: 926 * 927 * * -ENOTUNIQ - Multiple links are enabled 928 * * -ENOLINK - No connected pad found 929 */ 930 struct media_pad *media_pad_remote_pad_unique(const struct media_pad *pad); 931 932 /** 933 * media_entity_remote_pad_unique - Find a remote pad connected to an entity 934 * @entity: The entity 935 * @type: The type of pad to find (MEDIA_PAD_FL_SINK or MEDIA_PAD_FL_SOURCE) 936 * 937 * Search for and return a remote pad of @type connected to @entity through an 938 * enabled link. If multiple (or no) remote pads match these criteria, an error 939 * is returned. 940 * 941 * The uniqueness constraint makes this helper function suitable for entities 942 * that support a single active source or sink at a time. 943 * 944 * Return: A pointer to the remote pad, or one of the following error pointers 945 * if an error occurs: 946 * 947 * * -ENOTUNIQ - Multiple links are enabled 948 * * -ENOLINK - No connected pad found 949 */ 950 struct media_pad * 951 media_entity_remote_pad_unique(const struct media_entity *entity, 952 unsigned int type); 953 954 /** 955 * media_entity_remote_source_pad_unique - Find a remote source pad connected to 956 * an entity 957 * @entity: The entity 958 * 959 * Search for and return a remote source pad connected to @entity through an 960 * enabled link. If multiple (or no) remote pads match these criteria, an error 961 * is returned. 962 * 963 * The uniqueness constraint makes this helper function suitable for entities 964 * that support a single active source at a time. 965 * 966 * Return: A pointer to the remote pad, or one of the following error pointers 967 * if an error occurs: 968 * 969 * * -ENOTUNIQ - Multiple links are enabled 970 * * -ENOLINK - No connected pad found 971 */ 972 static inline struct media_pad * 973 media_entity_remote_source_pad_unique(const struct media_entity *entity) 974 { 975 return media_entity_remote_pad_unique(entity, MEDIA_PAD_FL_SOURCE); 976 } 977 978 /** 979 * media_pad_is_streaming - Test if a pad is part of a streaming pipeline 980 * @pad: The pad 981 * 982 * Return: True if the pad is part of a pipeline started with the 983 * media_pipeline_start() function, false otherwise. 984 */ 985 static inline bool media_pad_is_streaming(const struct media_pad *pad) 986 { 987 return pad->pipe; 988 } 989 990 /** 991 * media_entity_is_streaming - Test if an entity is part of a streaming pipeline 992 * @entity: The entity 993 * 994 * Return: True if the entity is part of a pipeline started with the 995 * media_pipeline_start() function, false otherwise. 996 */ 997 static inline bool media_entity_is_streaming(const struct media_entity *entity) 998 { 999 struct media_pad *pad; 1000 1001 media_entity_for_each_pad(entity, pad) { 1002 if (media_pad_is_streaming(pad)) 1003 return true; 1004 } 1005 1006 return false; 1007 } 1008 1009 /** 1010 * media_entity_pipeline - Get the media pipeline an entity is part of 1011 * @entity: The entity 1012 * 1013 * DEPRECATED: use media_pad_pipeline() instead. 1014 * 1015 * This function returns the media pipeline that an entity has been associated 1016 * with when constructing the pipeline with media_pipeline_start(). The pointer 1017 * remains valid until media_pipeline_stop() is called. 1018 * 1019 * In general, entities can be part of multiple pipelines, when carrying 1020 * multiple streams (either on different pads, or on the same pad using 1021 * multiplexed streams). This function is to be used only for entities that 1022 * do not support multiple pipelines. 1023 * 1024 * Return: The media_pipeline the entity is part of, or NULL if the entity is 1025 * not part of any pipeline. 1026 */ 1027 struct media_pipeline *media_entity_pipeline(struct media_entity *entity); 1028 1029 /** 1030 * media_pad_pipeline - Get the media pipeline a pad is part of 1031 * @pad: The pad 1032 * 1033 * This function returns the media pipeline that a pad has been associated 1034 * with when constructing the pipeline with media_pipeline_start(). The pointer 1035 * remains valid until media_pipeline_stop() is called. 1036 * 1037 * Return: The media_pipeline the pad is part of, or NULL if the pad is 1038 * not part of any pipeline. 1039 */ 1040 struct media_pipeline *media_pad_pipeline(struct media_pad *pad); 1041 1042 /** 1043 * media_entity_get_fwnode_pad - Get pad number from fwnode 1044 * 1045 * @entity: The entity 1046 * @fwnode: Pointer to the fwnode_handle which should be used to find the pad 1047 * @direction_flags: Expected direction of the pad, as defined in 1048 * :ref:`include/uapi/linux/media.h <media_header>` 1049 * (seek for ``MEDIA_PAD_FL_*``) 1050 * 1051 * This function can be used to resolve the media pad number from 1052 * a fwnode. This is useful for devices which use more complex 1053 * mappings of media pads. 1054 * 1055 * If the entity does not implement the get_fwnode_pad() operation 1056 * then this function searches the entity for the first pad that 1057 * matches the @direction_flags. 1058 * 1059 * Return: returns the pad number on success or a negative error code. 1060 */ 1061 int media_entity_get_fwnode_pad(struct media_entity *entity, 1062 struct fwnode_handle *fwnode, 1063 unsigned long direction_flags); 1064 1065 /** 1066 * media_graph_walk_init - Allocate resources used by graph walk. 1067 * 1068 * @graph: Media graph structure that will be used to walk the graph 1069 * @mdev: Pointer to the &media_device that contains the object 1070 * 1071 * The caller is required to hold the media_device graph_mutex during the graph 1072 * walk until the graph state is released. 1073 * 1074 * Returns zero on success or a negative error code otherwise. 1075 */ 1076 __must_check int media_graph_walk_init( 1077 struct media_graph *graph, struct media_device *mdev); 1078 1079 /** 1080 * media_graph_walk_cleanup - Release resources used by graph walk. 1081 * 1082 * @graph: Media graph structure that will be used to walk the graph 1083 */ 1084 void media_graph_walk_cleanup(struct media_graph *graph); 1085 1086 /** 1087 * media_graph_walk_start - Start walking the media graph at a 1088 * given entity 1089 * 1090 * @graph: Media graph structure that will be used to walk the graph 1091 * @entity: Starting entity 1092 * 1093 * Before using this function, media_graph_walk_init() must be 1094 * used to allocate resources used for walking the graph. This 1095 * function initializes the graph traversal structure to walk the 1096 * entities graph starting at the given entity. The traversal 1097 * structure must not be modified by the caller during graph 1098 * traversal. After the graph walk, the resources must be released 1099 * using media_graph_walk_cleanup(). 1100 */ 1101 void media_graph_walk_start(struct media_graph *graph, 1102 struct media_entity *entity); 1103 1104 /** 1105 * media_graph_walk_next - Get the next entity in the graph 1106 * @graph: Media graph structure 1107 * 1108 * Perform a depth-first traversal of the given media entities graph. 1109 * 1110 * The graph structure must have been previously initialized with a call to 1111 * media_graph_walk_start(). 1112 * 1113 * Return: returns the next entity in the graph or %NULL if the whole graph 1114 * have been traversed. 1115 */ 1116 struct media_entity *media_graph_walk_next(struct media_graph *graph); 1117 1118 /** 1119 * media_pipeline_start - Mark a pipeline as streaming 1120 * @pad: Starting pad 1121 * @pipe: Media pipeline to be assigned to all pads in the pipeline. 1122 * 1123 * Mark all pads connected to a given pad through enabled links, either 1124 * directly or indirectly, as streaming. The given pipeline object is assigned 1125 * to every pad in the pipeline and stored in the media_pad pipe field. 1126 * 1127 * Calls to this function can be nested, in which case the same number of 1128 * media_pipeline_stop() calls will be required to stop streaming. The 1129 * pipeline pointer must be identical for all nested calls to 1130 * media_pipeline_start(). 1131 */ 1132 __must_check int media_pipeline_start(struct media_pad *pad, 1133 struct media_pipeline *pipe); 1134 /** 1135 * __media_pipeline_start - Mark a pipeline as streaming 1136 * 1137 * @pad: Starting pad 1138 * @pipe: Media pipeline to be assigned to all pads in the pipeline. 1139 * 1140 * ..note:: This is the non-locking version of media_pipeline_start() 1141 */ 1142 __must_check int __media_pipeline_start(struct media_pad *pad, 1143 struct media_pipeline *pipe); 1144 1145 /** 1146 * media_pipeline_stop - Mark a pipeline as not streaming 1147 * @pad: Starting pad 1148 * 1149 * Mark all pads connected to a given pad through enabled links, either 1150 * directly or indirectly, as not streaming. The media_pad pipe field is 1151 * reset to %NULL. 1152 * 1153 * If multiple calls to media_pipeline_start() have been made, the same 1154 * number of calls to this function are required to mark the pipeline as not 1155 * streaming. 1156 */ 1157 void media_pipeline_stop(struct media_pad *pad); 1158 1159 /** 1160 * __media_pipeline_stop - Mark a pipeline as not streaming 1161 * 1162 * @pad: Starting pad 1163 * 1164 * .. note:: This is the non-locking version of media_pipeline_stop() 1165 */ 1166 void __media_pipeline_stop(struct media_pad *pad); 1167 1168 /** 1169 * media_pipeline_alloc_start - Mark a pipeline as streaming 1170 * @pad: Starting pad 1171 * 1172 * media_pipeline_alloc_start() is similar to media_pipeline_start() but instead 1173 * of working on a given pipeline the function will use an existing pipeline if 1174 * the pad is already part of a pipeline, or allocate a new pipeline. 1175 * 1176 * Calls to media_pipeline_alloc_start() must be matched with 1177 * media_pipeline_stop(). 1178 */ 1179 __must_check int media_pipeline_alloc_start(struct media_pad *pad); 1180 1181 /** 1182 * media_devnode_create() - creates and initializes a device node interface 1183 * 1184 * @mdev: pointer to struct &media_device 1185 * @type: type of the interface, as given by 1186 * :ref:`include/uapi/linux/media.h <media_header>` 1187 * ( seek for ``MEDIA_INTF_T_*``) macros. 1188 * @flags: Interface flags, as defined in 1189 * :ref:`include/uapi/linux/media.h <media_header>` 1190 * ( seek for ``MEDIA_INTF_FL_*``) 1191 * @major: Device node major number. 1192 * @minor: Device node minor number. 1193 * 1194 * Return: if succeeded, returns a pointer to the newly allocated 1195 * &media_intf_devnode pointer. 1196 * 1197 * .. note:: 1198 * 1199 * Currently, no flags for &media_interface is defined. 1200 */ 1201 struct media_intf_devnode * 1202 __must_check media_devnode_create(struct media_device *mdev, 1203 u32 type, u32 flags, 1204 u32 major, u32 minor); 1205 /** 1206 * media_devnode_remove() - removes a device node interface 1207 * 1208 * @devnode: pointer to &media_intf_devnode to be freed. 1209 * 1210 * When a device node interface is removed, all links to it are automatically 1211 * removed. 1212 */ 1213 void media_devnode_remove(struct media_intf_devnode *devnode); 1214 1215 /** 1216 * media_create_intf_link() - creates a link between an entity and an interface 1217 * 1218 * @entity: pointer to %media_entity 1219 * @intf: pointer to %media_interface 1220 * @flags: Link flags, as defined in 1221 * :ref:`include/uapi/linux/media.h <media_header>` 1222 * ( seek for ``MEDIA_LNK_FL_*``) 1223 * 1224 * 1225 * Valid values for flags: 1226 * 1227 * %MEDIA_LNK_FL_ENABLED 1228 * Indicates that the interface is connected to the entity hardware. 1229 * That's the default value for interfaces. An interface may be disabled if 1230 * the hardware is busy due to the usage of some other interface that it is 1231 * currently controlling the hardware. 1232 * 1233 * A typical example is an hybrid TV device that handle only one type of 1234 * stream on a given time. So, when the digital TV is streaming, 1235 * the V4L2 interfaces won't be enabled, as such device is not able to 1236 * also stream analog TV or radio. 1237 * 1238 * .. note:: 1239 * 1240 * Before calling this function, media_devnode_create() should be called for 1241 * the interface and media_device_register_entity() should be called for the 1242 * interface that will be part of the link. 1243 */ 1244 struct media_link * 1245 __must_check media_create_intf_link(struct media_entity *entity, 1246 struct media_interface *intf, 1247 u32 flags); 1248 /** 1249 * __media_remove_intf_link() - remove a single interface link 1250 * 1251 * @link: pointer to &media_link. 1252 * 1253 * .. note:: This is an unlocked version of media_remove_intf_link() 1254 */ 1255 void __media_remove_intf_link(struct media_link *link); 1256 1257 /** 1258 * media_remove_intf_link() - remove a single interface link 1259 * 1260 * @link: pointer to &media_link. 1261 * 1262 * .. note:: Prefer to use this one, instead of __media_remove_intf_link() 1263 */ 1264 void media_remove_intf_link(struct media_link *link); 1265 1266 /** 1267 * __media_remove_intf_links() - remove all links associated with an interface 1268 * 1269 * @intf: pointer to &media_interface 1270 * 1271 * .. note:: This is an unlocked version of media_remove_intf_links(). 1272 */ 1273 void __media_remove_intf_links(struct media_interface *intf); 1274 1275 /** 1276 * media_remove_intf_links() - remove all links associated with an interface 1277 * 1278 * @intf: pointer to &media_interface 1279 * 1280 * .. note:: 1281 * 1282 * #) This is called automatically when an entity is unregistered via 1283 * media_device_register_entity() and by media_devnode_remove(). 1284 * 1285 * #) Prefer to use this one, instead of __media_remove_intf_links(). 1286 */ 1287 void media_remove_intf_links(struct media_interface *intf); 1288 1289 /** 1290 * media_entity_call - Calls a struct media_entity_operations operation on 1291 * an entity 1292 * 1293 * @entity: entity where the @operation will be called 1294 * @operation: type of the operation. Should be the name of a member of 1295 * struct &media_entity_operations. 1296 * 1297 * This helper function will check if @operation is not %NULL. On such case, 1298 * it will issue a call to @operation\(@entity, @args\). 1299 */ 1300 1301 #define media_entity_call(entity, operation, args...) \ 1302 (((entity)->ops && (entity)->ops->operation) ? \ 1303 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD) 1304 1305 /** 1306 * media_create_ancillary_link() - create an ancillary link between two 1307 * instances of &media_entity 1308 * 1309 * @primary: pointer to the primary &media_entity 1310 * @ancillary: pointer to the ancillary &media_entity 1311 * 1312 * Create an ancillary link between two entities, indicating that they 1313 * represent two connected pieces of hardware that form a single logical unit. 1314 * A typical example is a camera lens controller being linked to the sensor that 1315 * it is supporting. 1316 * 1317 * The function sets both MEDIA_LNK_FL_ENABLED and MEDIA_LNK_FL_IMMUTABLE for 1318 * the new link. 1319 */ 1320 struct media_link * 1321 media_create_ancillary_link(struct media_entity *primary, 1322 struct media_entity *ancillary); 1323 1324 /** 1325 * __media_entity_next_link() - Iterate through a &media_entity's links 1326 * 1327 * @entity: pointer to the &media_entity 1328 * @link: pointer to a &media_link to hold the iterated values 1329 * @link_type: one of the MEDIA_LNK_FL_LINK_TYPE flags 1330 * 1331 * Return the next link against an entity matching a specific link type. This 1332 * allows iteration through an entity's links whilst guaranteeing all of the 1333 * returned links are of the given type. 1334 */ 1335 struct media_link *__media_entity_next_link(struct media_entity *entity, 1336 struct media_link *link, 1337 unsigned long link_type); 1338 1339 /** 1340 * for_each_media_entity_data_link() - Iterate through an entity's data links 1341 * 1342 * @entity: pointer to the &media_entity 1343 * @link: pointer to a &media_link to hold the iterated values 1344 * 1345 * Iterate over a &media_entity's data links 1346 */ 1347 #define for_each_media_entity_data_link(entity, link) \ 1348 for (link = __media_entity_next_link(entity, NULL, \ 1349 MEDIA_LNK_FL_DATA_LINK); \ 1350 link; \ 1351 link = __media_entity_next_link(entity, link, \ 1352 MEDIA_LNK_FL_DATA_LINK)) 1353 1354 #endif 1355