From 39a956c4147e4f696f729916f677673e9a9dc7ab Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 13 Aug 2015 14:42:42 -0300 Subject: [PATCH] [media] media: add a debug message to warn about gobj creation/removal It helps to check if the media controller is doing the right thing with the object creation and removal. No extra code/data will be produced if DEBUG or CONFIG_DYNAMIC_DEBUG is not enabled. Acked-by: Hans Verkuil Reviewed-by: Javier Martinez Canillas Signed-off-by: Mauro Carvalho Chehab --- drivers/media/media-entity.c | 68 +++++++++++++++++++++++++++++++++++++++++++- include/media/media-entity.h | 7 +++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c index 63fd293..f5b4822 100644 --- a/drivers/media/media-entity.c +++ b/drivers/media/media-entity.c @@ -27,6 +27,69 @@ #include /** + * dev_dbg_obj - Prints in debug mode a change on some object + * + * @event_name: Name of the event to report. Could be __func__ + * @gobj: Pointer to the object + * + * Enabled only if DEBUG or CONFIG_DYNAMIC_DEBUG. Otherwise, it + * won't produce any code. + */ +static inline const char *gobj_type(enum media_gobj_type type) +{ + switch (type) { + case MEDIA_GRAPH_ENTITY: + return "entity"; + case MEDIA_GRAPH_PAD: + return "pad"; + case MEDIA_GRAPH_LINK: + return "link"; + default: + return "unknown"; + } +} + +static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj) +{ +#if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG) + switch (media_type(gobj)) { + case MEDIA_GRAPH_ENTITY: + dev_dbg(gobj->mdev->dev, + "%s: id 0x%08x entity#%d: '%s'\n", + event_name, gobj->id, media_localid(gobj), + gobj_to_entity(gobj)->name); + break; + case MEDIA_GRAPH_LINK: + { + struct media_link *link = gobj_to_link(gobj); + + dev_dbg(gobj->mdev->dev, + "%s: id 0x%08x link#%d: '%s' %s#%d ==> '%s' %s#%d\n", + event_name, gobj->id, media_localid(gobj), + + link->source->entity->name, + gobj_type(media_type(&link->source->graph_obj)), + media_localid(&link->source->graph_obj), + + link->sink->entity->name, + gobj_type(media_type(&link->sink->graph_obj)), + media_localid(&link->sink->graph_obj)); + break; + } + case MEDIA_GRAPH_PAD: + { + struct media_pad *pad = gobj_to_pad(gobj); + + dev_dbg(gobj->mdev->dev, + "%s: id 0x%08x pad#%d: '%s':%d\n", + event_name, gobj->id, media_localid(gobj), + pad->entity->name, pad->index); + } + } +#endif +} + +/** * media_gobj_init - Initialize a graph object * * @mdev: Pointer to the media_device that contains the object @@ -43,6 +106,8 @@ void media_gobj_init(struct media_device *mdev, enum media_gobj_type type, struct media_gobj *gobj) { + gobj->mdev = mdev; + /* Create a per-type unique object ID */ switch (type) { case MEDIA_GRAPH_ENTITY: @@ -55,6 +120,7 @@ void media_gobj_init(struct media_device *mdev, gobj->id = media_gobj_gen_id(type, ++mdev->link_id); break; } + dev_dbg_obj(__func__, gobj); } /** @@ -66,7 +132,7 @@ void media_gobj_init(struct media_device *mdev, */ void media_gobj_remove(struct media_gobj *gobj) { - /* For now, nothing to do */ + dev_dbg_obj(__func__, gobj); } /** diff --git a/include/media/media-entity.h b/include/media/media-entity.h index bf93c90..96a5d3e 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -61,6 +61,7 @@ enum media_gobj_type { * All objects on the media graph should have this struct embedded */ struct media_gobj { + struct media_device *mdev; u32 id; }; @@ -199,6 +200,12 @@ struct media_entity_graph { #define gobj_to_entity(gobj) \ container_of(gobj, struct media_entity, graph_obj) +#define gobj_to_pad(gobj) \ + container_of(gobj, struct media_pad, graph_obj) + +#define gobj_to_link(gobj) \ + container_of(gobj, struct media_link, graph_obj) + void media_gobj_init(struct media_device *mdev, enum media_gobj_type type, struct media_gobj *gobj); -- 2.7.4