};
#define MEDIA_BITS_PER_TYPE 8
-#define MEDIA_BITS_PER_LOCAL_ID (32 - MEDIA_BITS_PER_TYPE)
-#define MEDIA_LOCAL_ID_MASK GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
+#define MEDIA_BITS_PER_ID (32 - MEDIA_BITS_PER_TYPE)
+#define MEDIA_ID_MASK GENMASK_ULL(MEDIA_BITS_PER_ID - 1, 0)
/* Structs to represent the objects that belong to a media graph */
* @mdev: Pointer to the struct media_device that owns the object
* @id: Non-zero object ID identifier. The ID should be unique
* inside a media_device, as it is composed by
- * MEDIA_BITS_PER_TYPE to store the type plus
- * MEDIA_BITS_PER_LOCAL_ID to store a per-type ID
- * (called as "local ID").
+ * %MEDIA_BITS_PER_TYPE to store the type plus
+ * %MEDIA_BITS_PER_ID to store the ID
* @list: List entry stored in one of the per-type mdev object lists
*
* All objects on the media graph should have this struct embedded
*/
static inline enum media_gobj_type media_type(struct media_gobj *gobj)
{
- return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
+ return gobj->id >> MEDIA_BITS_PER_ID;
}
-static inline u32 media_localid(struct media_gobj *gobj)
+/**
+ * media_id() - return the media object ID
+ *
+ * @gobj: pointer to the media graph object
+ */
+static inline u32 media_id(struct media_gobj *gobj)
{
- return gobj->id & MEDIA_LOCAL_ID_MASK;
+ return gobj->id & MEDIA_ID_MASK;
}
-static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
+/**
+ * media_gobj_gen_id() - encapsulates type and ID on at the object ID
+ *
+ * @type: object type as define at enum &media_gobj_type.
+ * @local_id: next ID, from struct &media_device.@id.
+ */
+static inline u32 media_gobj_gen_id(enum media_gobj_type type, u64 local_id)
{
u32 id;
- id = type << MEDIA_BITS_PER_LOCAL_ID;
- id |= local_id & MEDIA_LOCAL_ID_MASK;
+ id = type << MEDIA_BITS_PER_ID;
+ id |= local_id & MEDIA_ID_MASK;
return id;
}
/**
* media_entity_enum_zero - Clear the entire enum
*
- * @e: Entity enumeration to be cleared
+ * @ent_enum: Entity enumeration to be cleared
*/
static inline void media_entity_enum_zero(struct media_entity_enum *ent_enum)
{
/**
* media_entity_enum_set - Mark a single entity in the enum
*
- * @e: Entity enumeration
+ * @ent_enum: Entity enumeration
* @entity: Entity to be marked
*/
static inline void media_entity_enum_set(struct media_entity_enum *ent_enum,
/**
* media_entity_enum_clear - Unmark a single entity in the enum
*
- * @e: Entity enumeration
+ * @ent_enum: Entity enumeration
* @entity: Entity to be unmarked
*/
static inline void media_entity_enum_clear(struct media_entity_enum *ent_enum,
/**
* media_entity_enum_test - Test whether the entity is marked
*
- * @e: Entity enumeration
+ * @ent_enum: Entity enumeration
* @entity: Entity to be tested
*
* Returns true if the entity was marked.
/**
* media_entity_enum_test - Test whether the entity is marked, and mark it
*
- * @e: Entity enumeration
+ * @ent_enum: Entity enumeration
* @entity: Entity to be tested
*
* Returns true if the entity was marked, and mark it before doing so.
*/
-static inline bool media_entity_enum_test_and_set(
- struct media_entity_enum *ent_enum, struct media_entity *entity)
+static inline bool
+media_entity_enum_test_and_set(struct media_entity_enum *ent_enum,
+ struct media_entity *entity)
{
if (WARN_ON(entity->internal_idx >= ent_enum->idx_max))
return true;
}
/**
- * media_entity_enum_test - Test whether the entire enum is empty
+ * media_entity_enum_empty - Test whether the entire enum is empty
*
- * @e: Entity enumeration
- * @entity: Entity to be tested
+ * @ent_enum: Entity enumeration
*
* Returns true if the entity was marked.
*/
/**
* media_entity_enum_intersects - Test whether two enums intersect
*
- * @e: First entity enumeration
- * @f: Second entity enumeration
+ * @ent_enum1: First entity enumeration
+ * @ent_enum2: Second entity enumeration
*
* Returns true if entity enumerations e and f intersect, otherwise false.
*/
__must_check int media_create_pad_link(struct media_entity *source,
u16 source_pad, struct media_entity *sink,
u16 sink_pad, u32 flags);
+
+/**
+ * media_create_pad_links() - creates a link between two entities.
+ *
+ * @mdev: Pointer to the media_device that contains the object
+ * @source_function: Function of the source entities. Used only if @source is
+ * NULL.
+ * @source: pointer to &media_entity of the source pad. If NULL, it will use
+ * all entities that matches the @sink_function.
+ * @source_pad: number of the source pad in the pads array
+ * @sink_function: Function of the sink entities. Used only if @sink is NULL.
+ * @sink: pointer to &media_entity of the sink pad. If NULL, it will use
+ * all entities that matches the @sink_function.
+ * @sink_pad: number of the sink pad in the pads array.
+ * @flags: Link flags, as defined in include/uapi/linux/media.h.
+ * @allow_both_undefined: if true, then both @source and @sink can be NULL.
+ * In such case, it will create a crossbar between all entities that
+ * matches @source_function to all entities that matches @sink_function.
+ * If false, it will return 0 and won't create any link if both @source
+ * and @sink are NULL.
+ *
+ * Valid values for flags:
+ * A %MEDIA_LNK_FL_ENABLED flag indicates that the link is enabled and can be
+ * used to transfer media data. If multiple links are created and this
+ * flag is passed as an argument, only the first created link will have
+ * this flag.
+ *
+ * A %MEDIA_LNK_FL_IMMUTABLE flag indicates that the link enabled state can't
+ * be modified at runtime. If %MEDIA_LNK_FL_IMMUTABLE is set, then
+ * %MEDIA_LNK_FL_ENABLED must also be set since an immutable link is
+ * always enabled.
+ *
+ * It is common for some devices to have multiple source and/or sink entities
+ * of the same type that should be linked. While media_create_pad_link()
+ * creates link by link, this function is meant to allow 1:n, n:1 and even
+ * cross-bar (n:n) links.
+ *
+ * NOTE: Before calling this function, media_entity_pads_init() and
+ * media_device_register_entity() should be called previously for the entities
+ * to be linked.
+ */
+int media_create_pad_links(const struct media_device *mdev,
+ const u32 source_function,
+ struct media_entity *source,
+ const u16 source_pad,
+ const u32 sink_function,
+ struct media_entity *sink,
+ const u16 sink_pad,
+ u32 flags,
+ const bool allow_both_undefined);
+
void __media_entity_remove_links(struct media_entity *entity);
/**