[media] media: Add an API to manage entity enumerations
[cascardo/linux.git] / include / media / media-device.h
index ebc2f3a..da4e12c 100644 (file)
  * in the end provide a way to use driver-specific callbacks.
  */
 
+struct ida;
 struct device;
 
 /**
@@ -278,6 +279,7 @@ struct device;
  * @pad_id:    Unique ID used on the last pad registered
  * @link_id:   Unique ID used on the last link registered
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
+ * @entity_internal_idx: Allocated internal entity indices
  * @entities:  List of registered entities
  * @interfaces:        List of registered interfaces
  * @pads:      List of registered pads
@@ -313,6 +315,8 @@ struct media_device {
        u32 pad_id;
        u32 link_id;
        u32 intf_devnode_id;
+       struct ida entity_internal_idx;
+       int entity_internal_idx_max;
 
        struct list_head entities;
        struct list_head interfaces;
@@ -337,6 +341,47 @@ struct media_device {
 /* media_devnode to media_device */
 #define to_media_device(node) container_of(node, struct media_device, devnode)
 
+/**
+ * media_entity_enum_init - Initialise an entity enumeration
+ *
+ * @e: Entity enumeration to be initialised
+ * @mdev: The related media device
+ *
+ * Returns zero on success or a negative error code.
+ */
+static inline __must_check int media_entity_enum_init(
+       struct media_entity_enum *ent_enum, struct media_device *mdev)
+{
+       return __media_entity_enum_init(ent_enum,
+                                       mdev->entity_internal_idx_max + 1);
+}
+
+/**
+ * media_device_init() - Initializes a media device element
+ *
+ * @mdev:      pointer to struct &media_device
+ *
+ * This function initializes the media device prior to its registration.
+ * The media device initialization and registration is split in two functions
+ * to avoid race conditions and make the media device available to user-space
+ * before the media graph has been completed.
+ *
+ * So drivers need to first initialize the media device, register any entity
+ * within the media device, create pad to pad links and then finally register
+ * the media device by calling media_device_register() as a final step.
+ */
+void media_device_init(struct media_device *mdev);
+
+/**
+ * media_device_cleanup() - Cleanups a media device element
+ *
+ * @mdev:      pointer to struct &media_device
+ *
+ * This function that will destroy the graph_mutex that is
+ * initialized in media_device_init().
+ */
+void media_device_cleanup(struct media_device *mdev);
+
 /**
  * __media_device_register() - Registers a media device element
  *