Commit bfab2aac authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] media: use media_gobj inside entities

As entities are graph objects, let's embed media_gobj
on it. That ensures an unique ID for entities that can be
global along the entire media controller.

For now, we'll keep the already existing entity ID. Such
field need to be dropped at some point, but for now, let's
not do this, to avoid needing to review all drivers and
the userspace apps.
Acked-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Tested-by: default avatarJavier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent ec6e4c95
...@@ -379,7 +379,6 @@ int __must_check __media_device_register(struct media_device *mdev, ...@@ -379,7 +379,6 @@ int __must_check __media_device_register(struct media_device *mdev,
if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0)) if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
return -EINVAL; return -EINVAL;
mdev->entity_id = 1;
INIT_LIST_HEAD(&mdev->entities); INIT_LIST_HEAD(&mdev->entities);
spin_lock_init(&mdev->lock); spin_lock_init(&mdev->lock);
mutex_init(&mdev->graph_mutex); mutex_init(&mdev->graph_mutex);
...@@ -433,10 +432,8 @@ int __must_check media_device_register_entity(struct media_device *mdev, ...@@ -433,10 +432,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
entity->parent = mdev; entity->parent = mdev;
spin_lock(&mdev->lock); spin_lock(&mdev->lock);
if (entity->id == 0) /* Initialize media_gobj embedded at the entity */
entity->id = mdev->entity_id++; media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
else
mdev->entity_id = max(entity->id + 1, mdev->entity_id);
list_add_tail(&entity->list, &mdev->entities); list_add_tail(&entity->list, &mdev->entities);
spin_unlock(&mdev->lock); spin_unlock(&mdev->lock);
...@@ -459,6 +456,7 @@ void media_device_unregister_entity(struct media_entity *entity) ...@@ -459,6 +456,7 @@ void media_device_unregister_entity(struct media_entity *entity)
return; return;
spin_lock(&mdev->lock); spin_lock(&mdev->lock);
media_gobj_remove(&entity->graph_obj);
list_del(&entity->list); list_del(&entity->list);
spin_unlock(&mdev->lock); spin_unlock(&mdev->lock);
entity->parent = NULL; entity->parent = NULL;
......
...@@ -43,7 +43,12 @@ void media_gobj_init(struct media_device *mdev, ...@@ -43,7 +43,12 @@ void media_gobj_init(struct media_device *mdev,
enum media_gobj_type type, enum media_gobj_type type,
struct media_gobj *gobj) struct media_gobj *gobj)
{ {
/* For now, nothing to do */ /* Create a per-type unique object ID */
switch (type) {
case MEDIA_GRAPH_ENTITY:
gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
break;
}
} }
/** /**
......
...@@ -41,7 +41,7 @@ struct device; ...@@ -41,7 +41,7 @@ struct device;
* @bus_info: Unique and stable device location identifier * @bus_info: Unique and stable device location identifier
* @hw_revision: Hardware device revision * @hw_revision: Hardware device revision
* @driver_version: Device driver version * @driver_version: Device driver version
* @entity_id: ID of the next entity to be registered * @entity_id: Unique ID used on the last entity registered
* @entities: List of registered entities * @entities: List of registered entities
* @lock: Entities list lock * @lock: Entities list lock
* @graph_mutex: Entities graph operation lock * @graph_mutex: Entities graph operation lock
...@@ -69,6 +69,7 @@ struct media_device { ...@@ -69,6 +69,7 @@ struct media_device {
u32 driver_version; u32 driver_version;
u32 entity_id; u32 entity_id;
struct list_head entities; struct list_head entities;
/* Protects the entities list */ /* Protects the entities list */
......
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
/** /**
* enum media_gobj_type - type of a graph object * enum media_gobj_type - type of a graph object
* *
* @MEDIA_GRAPH_ENTITY: Identify a media entity
*/ */
enum media_gobj_type { enum media_gobj_type {
/* FIXME: add the types here, as we embed media_gobj */ MEDIA_GRAPH_ENTITY,
MEDIA_GRAPH_NONE
}; };
#define MEDIA_BITS_PER_TYPE 8 #define MEDIA_BITS_PER_TYPE 8
...@@ -94,10 +94,9 @@ struct media_entity_operations { ...@@ -94,10 +94,9 @@ struct media_entity_operations {
}; };
struct media_entity { struct media_entity {
struct media_gobj graph_obj;
struct list_head list; struct list_head list;
struct media_device *parent; /* Media device this entity belongs to*/ struct media_device *parent; /* Media device this entity belongs to*/
u32 id; /* Entity ID, unique in the parent media
* device context */
const char *name; /* Entity name */ const char *name; /* Entity name */
u32 type; /* Entity type (MEDIA_ENT_T_*) */ u32 type; /* Entity type (MEDIA_ENT_T_*) */
u32 revision; /* Entity revision, driver specific */ u32 revision; /* Entity revision, driver specific */
...@@ -148,7 +147,7 @@ static inline u32 media_entity_subtype(struct media_entity *entity) ...@@ -148,7 +147,7 @@ static inline u32 media_entity_subtype(struct media_entity *entity)
static inline u32 media_entity_id(struct media_entity *entity) static inline u32 media_entity_id(struct media_entity *entity)
{ {
return entity->id; return entity->graph_obj.id;
} }
static inline enum media_gobj_type media_type(struct media_gobj *gobj) static inline enum media_gobj_type media_type(struct media_gobj *gobj)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment