Merge tag 'armsoc-tegra' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[linux-2.6-block.git] / include / media / media-entity.h
index 855b47df6ed54d20550409c6934438c19b1fa0f7..fe485d367985650a1c4a88ff86e1c10b71d82ea3 100644 (file)
@@ -47,8 +47,8 @@ enum media_gobj_type {
 };
 
 #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 */
 
@@ -58,9 +58,8 @@ enum media_gobj_type {
  * @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
@@ -299,20 +298,31 @@ static inline u32 media_entity_id(struct media_entity *entity)
  */
 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;
 }
@@ -603,6 +613,57 @@ static inline void media_entity_cleanup(struct media_entity *entity) {};
 __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);
 
 /**