Przeglądaj źródła

[media] media: Introduce internal index for media entities

The internal index can be used internally by the framework in order to keep
track of entities for a purpose or another. The internal index is constant
while it's registered to a media device, but the same index may be re-used
once the entity having that index is unregistered.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Sakari Ailus 9 lat temu
rodzic
commit
665faa971d

+ 17 - 0
drivers/media/media-device.c

@@ -22,6 +22,7 @@
 
 
 #include <linux/compat.h>
 #include <linux/compat.h>
 #include <linux/export.h>
 #include <linux/export.h>
+#include <linux/idr.h>
 #include <linux/ioctl.h>
 #include <linux/ioctl.h>
 #include <linux/media.h>
 #include <linux/media.h>
 #include <linux/slab.h>
 #include <linux/slab.h>
@@ -551,6 +552,17 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	entity->num_backlinks = 0;
 	entity->num_backlinks = 0;
 
 
 	spin_lock(&mdev->lock);
 	spin_lock(&mdev->lock);
+
+	entity->internal_idx = ida_simple_get(&mdev->entity_internal_idx, 1, 0,
+					      GFP_KERNEL);
+	if (entity->internal_idx < 0) {
+		spin_unlock(&mdev->lock);
+		return entity->internal_idx;
+	}
+
+	mdev->entity_internal_idx_max =
+		max(mdev->entity_internal_idx_max, entity->internal_idx);
+
 	/* Initialize media_gobj embedded at the entity */
 	/* Initialize media_gobj embedded at the entity */
 	media_gobj_create(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	media_gobj_create(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 
 
@@ -579,6 +591,8 @@ static void __media_device_unregister_entity(struct media_entity *entity)
 	struct media_interface *intf;
 	struct media_interface *intf;
 	unsigned int i;
 	unsigned int i;
 
 
+	ida_simple_remove(&mdev->entity_internal_idx, entity->internal_idx);
+
 	/* Remove all interface links pointing to this entity */
 	/* Remove all interface links pointing to this entity */
 	list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
 	list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
 		list_for_each_entry_safe(link, tmp, &intf->links, list) {
 		list_for_each_entry_safe(link, tmp, &intf->links, list) {
@@ -632,6 +646,7 @@ void media_device_init(struct media_device *mdev)
 	INIT_LIST_HEAD(&mdev->links);
 	INIT_LIST_HEAD(&mdev->links);
 	spin_lock_init(&mdev->lock);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
 	mutex_init(&mdev->graph_mutex);
+	ida_init(&mdev->entity_internal_idx);
 
 
 	dev_dbg(mdev->dev, "Media device initialized\n");
 	dev_dbg(mdev->dev, "Media device initialized\n");
 }
 }
@@ -644,6 +659,8 @@ EXPORT_SYMBOL_GPL(media_device_init);
  */
  */
 void media_device_cleanup(struct media_device *mdev)
 void media_device_cleanup(struct media_device *mdev)
 {
 {
+	ida_destroy(&mdev->entity_internal_idx);
+	mdev->entity_internal_idx_max = 0;
 	mutex_destroy(&mdev->graph_mutex);
 	mutex_destroy(&mdev->graph_mutex);
 }
 }
 EXPORT_SYMBOL_GPL(media_device_cleanup);
 EXPORT_SYMBOL_GPL(media_device_cleanup);

+ 4 - 0
include/media/media-device.h

@@ -261,6 +261,7 @@
  * in the end provide a way to use driver-specific callbacks.
  * in the end provide a way to use driver-specific callbacks.
  */
  */
 
 
+struct ida;
 struct device;
 struct device;
 
 
 /**
 /**
@@ -278,6 +279,7 @@ struct device;
  * @pad_id:	Unique ID used on the last pad registered
  * @pad_id:	Unique ID used on the last pad registered
  * @link_id:	Unique ID used on the last link registered
  * @link_id:	Unique ID used on the last link registered
  * @intf_devnode_id: Unique ID used on the last interface devnode 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
  * @entities:	List of registered entities
  * @interfaces:	List of registered interfaces
  * @interfaces:	List of registered interfaces
  * @pads:	List of registered pads
  * @pads:	List of registered pads
@@ -313,6 +315,8 @@ struct media_device {
 	u32 pad_id;
 	u32 pad_id;
 	u32 link_id;
 	u32 link_id;
 	u32 intf_devnode_id;
 	u32 intf_devnode_id;
+	struct ida entity_internal_idx;
+	int entity_internal_idx_max;
 
 
 	struct list_head entities;
 	struct list_head entities;
 	struct list_head interfaces;
 	struct list_head interfaces;

+ 3 - 0
include/media/media-entity.h

@@ -157,6 +157,8 @@ struct media_entity_operations {
  * @num_pads:	Number of sink and source pads.
  * @num_pads:	Number of sink and source pads.
  * @num_links:	Total number of links, forward and back, enabled and disabled.
  * @num_links:	Total number of links, forward and back, enabled and disabled.
  * @num_backlinks: Number of backlinks
  * @num_backlinks: Number of backlinks
+ * @internal_idx: An unique internal entity specific number. The numbers are
+ *		re-used if entities are unregistered or registered again.
  * @pads:	Pads array with the size defined by @num_pads.
  * @pads:	Pads array with the size defined by @num_pads.
  * @links:	List of data links.
  * @links:	List of data links.
  * @ops:	Entity operations.
  * @ops:	Entity operations.
@@ -183,6 +185,7 @@ struct media_entity {
 	u16 num_pads;
 	u16 num_pads;
 	u16 num_links;
 	u16 num_links;
 	u16 num_backlinks;
 	u16 num_backlinks;
+	int internal_idx;
 
 
 	struct media_pad *pads;
 	struct media_pad *pads;
 	struct list_head links;
 	struct list_head links;