@@ -20,6 +20,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include <linux/bitmap.h>
#include <linux/compat.h>
#include <linux/export.h>
#include <linux/ioctl.h>
@@ -543,6 +544,8 @@ int __must_check __media_device_register(struct media_device *mdev,
if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
return -EINVAL;
+ bitmap_zero(mdev->entity_low_id, MEDIA_ENTITY_MAX_LOW_ID);
+
INIT_LIST_HEAD(&mdev->entities);
INIT_LIST_HEAD(&mdev->interfaces);
INIT_LIST_HEAD(&mdev->pads);
@@ -628,6 +631,15 @@ int __must_check media_device_register_entity(struct media_device *mdev,
INIT_LIST_HEAD(&entity->links);
spin_lock(&mdev->lock);
+ entity->low_id = find_first_zero_bit(mdev->entity_low_id,
+ MEDIA_ENTITY_MAX_LOW_ID);
+ if (entity->low_id == MEDIA_ENTITY_MAX_LOW_ID) {
+ spin_unlock(&mdev->lock);
+ return -ENOSPC;
+ }
+
+ __set_bit(entity->low_id, mdev->entity_low_id);
+
/* Initialize media_gobj embedded at the entity */
media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
@@ -660,6 +672,8 @@ void media_device_unregister_entity(struct media_entity *entity)
spin_lock(&mdev->lock);
+ __clear_bit(entity->low_id, mdev->entity_low_id);
+
/* Remove interface links with this entity on it */
list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) {
if (media_type(link->gobj1) == MEDIA_GRAPH_ENTITY
@@ -47,6 +47,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_low_id: Allocated low entity IDs
* @entities: List of registered entities
* @interfaces: List of registered interfaces
* @pads: List of registered pads
@@ -82,6 +83,7 @@ struct media_device {
u32 pad_id;
u32 link_id;
u32 intf_devnode_id;
+ DECLARE_BITMAP(entity_low_id, MEDIA_ENTITY_MAX_LOW_ID);
struct list_head entities;
struct list_head interfaces;
@@ -159,6 +159,8 @@ struct media_entity_operations {
* @num_pads: Number of sink and source pads.
* @num_links: Number of existing links, both enabled and disabled.
* @num_backlinks: Number of backlinks
+ * @low_id: An unique low 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.
* @links: Linked list for the data links.
* @ops: Entity operations.
@@ -187,6 +189,7 @@ struct media_entity {
u16 num_pads;
u16 num_links;
u16 num_backlinks;
+ u8 low_id;
struct media_pad *pads;
struct list_head links;
A low ID is a unique number specific to a media entity. The number is guaranteed to be under MEDIA_ENTITY_MAX_LOW_ID. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> --- drivers/media/media-device.c | 14 ++++++++++++++ include/media/media-device.h | 2 ++ include/media/media-entity.h | 3 +++ 3 files changed, 19 insertions(+)