All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/8] MC preparation patches
@ 2015-08-19 11:01 Mauro Carvalho Chehab
  2015-08-19 11:01   ` Mauro Carvalho Chehab
                   ` (7 more replies)
  0 siblings, 8 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Those are the same patches as sent at PATCH RFCv5, addressing most of
the stuff pointed by Hans.

The only thing I didn't do yet is the removal of entity->parent, in
favor of using, instead, entity->graph_obj.mdev. Such patch will
be done latter on.

As the previous series:

The first 5 patches on this series ensures that all existing object
types (entities, pads and links) will have an unique ID, as agreed
at the MC workshop.

The next two patches add two debug functions, that helps with the
tests of the MC changes. Both are enabled only if DEBUG or dynamic
debug is enabled.

The first one just help to identify when the media_device register,
remove and unregister functions are called. It helps to identify if
those events happen before or after object creation.

The second one is more interesting: it hooks at the object init and
remove functions and dump what's there at the new object when it
got created. This is very useful to test the future patches, as we'll
be able to track any topology changes.

Also, it demonstates the capability of the functions
media_gobj_init() and media_gobj_remove() to track topology
changes. Tracking topology changes is fundamental for the new API,
in order to implement G_TOPOLOGY ioctl. They should contain, in
the future, a callback to warn the several drivers envolved at the
MC topology build about topology changes.

The last patch on this preparation series is just a renaming patch,
that will avoid mess when future patches introduce the
entity->interface links.

They're tested using the cx231xx and au0828 with V4L2 and DVB support.

Those are the new media_gobj_init debug messages when the device is probed:

[ 3357.988183] usb 1-2.4: media_gobj_init: id 0x00000001 entity#1: 'au8522 19-0047'
[ 3357.989505] usb 1-2.4: media_gobj_init: id 0x01000001 pad#1: 'au8522 19-0047':0
[ 3357.990867] usb 1-2.4: media_gobj_init: id 0x01000002 pad#2: 'au8522 19-0047':1
[ 3357.992123] usb 1-2.4: media_gobj_init: id 0x01000003 pad#3: 'au8522 19-0047':2
[ 3357.996008] usb 1-2.4: media_gobj_init: id 0x00000002 entity#2: '(tuner unset)'
[ 3357.997158] usb 1-2.4: media_gobj_init: id 0x01000004 pad#4: '(tuner unset)':0
[ 3358.488779] usb 1-2.4: media_gobj_init: id 0x00000003 entity#3: 'au0828a video'
[ 3358.490177] usb 1-2.4: media_gobj_init: id 0x01000005 pad#5: 'au0828a video':0
[ 3358.491944] usb 1-2.4: media_gobj_init: id 0x00000004 entity#4: 'au0828a vbi'
[ 3358.493382] usb 1-2.4: media_gobj_init: id 0x01000006 pad#6: 'au0828a vbi':0
[ 3358.510977] usb 1-2.4: media_gobj_init: id 0x00000005 entity#5: 'Auvitek AU8522 QAM/8VSB Frontend'
[ 3358.512441] usb 1-2.4: media_gobj_init: id 0x01000007 pad#7: 'Auvitek AU8522 QAM/8VSB Frontend':0
[ 3358.513909] usb 1-2.4: media_gobj_init: id 0x01000008 pad#8: 'Auvitek AU8522 QAM/8VSB Frontend':1
[ 3358.516828] usb 1-2.4: media_gobj_init: id 0x00000006 entity#6: 'dvb-demux'
[ 3358.518226] usb 1-2.4: media_gobj_init: id 0x01000009 pad#9: 'dvb-demux':0
[ 3358.519594] usb 1-2.4: media_gobj_init: id 0x0100000a pad#10: 'dvb-demux':1
[ 3358.522461] usb 1-2.4: media_gobj_init: id 0x00000007 entity#7: 'dvb-dvr'
[ 3358.523914] usb 1-2.4: media_gobj_init: id 0x0100000b pad#11: 'dvb-dvr':0
[ 3358.526625] usb 1-2.4: media_gobj_init: id 0x00000008 entity#8: 'dvb-net'
[ 3358.529307] usb 1-2.4: media_gobj_init: id 0x02000001 link#1: 'Xceive XC5000' pad#4 ==> 'Auvitek AU8522 QAM/8VSB Frontend' pad#7
[ 3358.530715] usb 1-2.4: media_gobj_init: id 0x02000002 link#2: 'Xceive XC5000' pad#4 ==> 'Auvitek AU8522 QAM/8VSB Frontend' pad#7
[ 3358.532116] usb 1-2.4: media_gobj_init: id 0x02000003 link#3: 'Auvitek AU8522 QAM/8VSB Frontend' pad#8 ==> 'dvb-demux' pad#9
[ 3358.533520] usb 1-2.4: media_gobj_init: id 0x02000004 link#4: 'Auvitek AU8522 QAM/8VSB Frontend' pad#8 ==> 'dvb-demux' pad#9
[ 3358.534957] usb 1-2.4: media_gobj_init: id 0x02000005 link#5: 'dvb-demux' pad#10 ==> 'dvb-dvr' pad#11
[ 3358.536278] usb 1-2.4: media_gobj_init: id 0x02000006 link#6: 'dvb-demux' pad#10 ==> 'dvb-dvr' pad#11
[ 3358.610351] usb 1-2.4: media_gobj_init: id 0x02000007 link#7: 'Xceive XC5000' pad#4 ==> 'au8522 19-0047' pad#1
[ 3358.611455] usb 1-2.4: media_gobj_init: id 0x02000008 link#8: 'Xceive XC5000' pad#4 ==> 'au8522 19-0047' pad#1
[ 3358.612539] usb 1-2.4: media_gobj_init: id 0x02000009 link#9: 'au8522 19-0047' pad#2 ==> 'au0828a video' pad#5
[ 3358.613611] usb 1-2.4: media_gobj_init: id 0x0200000a link#10: 'au8522 19-0047' pad#2 ==> 'au0828a video' pad#5
[ 3358.614686] usb 1-2.4: media_gobj_init: id 0x0200000b link#11: 'au8522 19-0047' pad#3 ==> 'au0828a vbi' pad#6
[ 3358.615720] usb 1-2.4: media_gobj_init: id 0x0200000c link#12: 'au8522 19-0047' pad#3 ==> 'au0828a vbi' pad#6

Please notice that I changed the log messages there in order to put
both the global ID and the local ID together. Now, all log messages
will look the same:

    media_gobj_init: id 0x0100000a    pad#10:   'dvb-demux':1
    ===============  =============    ======    ============= 
    Event name	     Global ID        Local ID  Obj-specific data

I think that this way, the logs become clearer and easier to read.
I also added the pad index on the logs (as shown above).

Mauro Carvalho Chehab (8):
  [media] media: create a macro to get entity ID
  [media] media: add a common struct to be embed on media graph objects
  [media] media: use media_gobj inside entities
  [media] media: use media_gobj inside pads
  [media] media: use media_gobj inside links
  [media] media: add messages when media device gets (un)registered
  [media] media: add a debug message to warn about gobj creation/removal
  [media] media: rename the function that create pad links

 Documentation/media-framework.txt                  |   2 +-
 drivers/media/dvb-core/dvbdev.c                    |   8 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   4 +-
 drivers/media/i2c/s5k5baf.c                        |   2 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |   4 +-
 drivers/media/media-device.c                       |  41 +++++--
 drivers/media/media-entity.c                       | 127 ++++++++++++++++++++-
 drivers/media/platform/exynos4-is/media-dev.c      |  16 +--
 drivers/media/platform/omap3isp/isp.c              |  18 +--
 drivers/media/platform/omap3isp/ispccdc.c          |   2 +-
 drivers/media/platform/omap3isp/ispccp2.c          |   2 +-
 drivers/media/platform/omap3isp/ispcsi2.c          |   2 +-
 drivers/media/platform/omap3isp/isppreview.c       |   4 +-
 drivers/media/platform/omap3isp/ispresizer.c       |   4 +-
 drivers/media/platform/s3c-camif/camif-core.c      |   4 +-
 drivers/media/platform/vsp1/vsp1_drv.c             |   4 +-
 drivers/media/platform/vsp1/vsp1_rpf.c             |   2 +-
 drivers/media/platform/vsp1/vsp1_video.c           |   4 +-
 drivers/media/platform/vsp1/vsp1_wpf.c             |   2 +-
 drivers/media/platform/xilinx/xilinx-vipp.c        |   4 +-
 drivers/media/usb/au0828/au0828-core.c             |   6 +-
 drivers/media/usb/cx231xx/cx231xx-cards.c          |   6 +-
 drivers/media/usb/uvc/uvc_entity.c                 |   2 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.c |   2 +-
 drivers/staging/media/davinci_vpfe/dm365_isif.c    |   2 +-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c |   8 +-
 .../staging/media/davinci_vpfe/vpfe_mc_capture.c   |  10 +-
 drivers/staging/media/omap4iss/iss.c               |  12 +-
 drivers/staging/media/omap4iss/iss_csi2.c          |   2 +-
 drivers/staging/media/omap4iss/iss_ipipeif.c       |   2 +-
 drivers/staging/media/omap4iss/iss_resizer.c       |   2 +-
 include/media/media-device.h                       |   7 +-
 include/media/media-entity.h                       |  84 +++++++++++++-
 33 files changed, 311 insertions(+), 90 deletions(-)

-- 
2.4.3


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH v6 1/8] [media] media: create a macro to get entity ID
  2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
@ 2015-08-19 11:01   ` Mauro Carvalho Chehab
  2015-08-19 11:01 ` [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart, linux-sh

Instead of accessing directly entity.id, let's create a macro,
as this field will be moved into a common struct later on.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index c55ab5029323..e429605ca2c3 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct media_device *mdev, u32 id)
 	spin_lock(&mdev->lock);
 
 	media_device_for_each_entity(entity, mdev) {
-		if ((entity->id = id && !next) ||
-		    (entity->id > id && next)) {
+		if (((media_entity_id(entity) = id) && !next) ||
+		    ((media_entity_id(entity) > id) && next)) {
 			spin_unlock(&mdev->lock);
 			return entity;
 		}
@@ -104,7 +104,7 @@ static long media_device_enum_entities(struct media_device *mdev,
 	if (ent = NULL)
 		return -EINVAL;
 
-	u_ent.id = ent->id;
+	u_ent.id = media_entity_id(ent);
 	if (ent->name)
 		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
 	u_ent.type = ent->type;
@@ -122,7 +122,7 @@ static long media_device_enum_entities(struct media_device *mdev,
 static void media_device_kpad_to_upad(const struct media_pad *kpad,
 				      struct media_pad_desc *upad)
 {
-	upad->entity = kpad->entity->id;
+	upad->entity = media_entity_id(kpad->entity);
 	upad->index = kpad->index;
 	upad->flags = kpad->flags;
 }
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 949e5f92cbdc..cb0ac4e0dfa5 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 	graph->stack[graph->top].entity = NULL;
 	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
 
-	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
+	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
 		return;
 
-	__set_bit(entity->id, graph->entities);
+	__set_bit(media_entity_id(entity), graph->entities);
 	stack_push(graph, entity);
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
@@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 
 		/* Get the entity in the other end of the link . */
 		next = media_entity_other(entity, link);
-		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
+		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
 			return NULL;
 
 		/* Has the entity already been visited? */
-		if (__test_and_set_bit(next->id, graph->entities)) {
+		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
 			link_top(graph)++;
 			continue;
 		}
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 17f08973f835..debe4e539df6 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
 			break;
 
 		/* Ensure the branch has no loop. */
-		if (entities & (1 << entity->subdev.entity.id))
+		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
 			return -EPIPE;
 
-		entities |= 1 << entity->subdev.entity.id;
+		entities |= 1 << media_entity_id(&entity->subdev.entity);
 
 		/* UDS can't be chained. */
 		if (entity->type = VSP1_ENTITY_UDS) {
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 8b21a4d920d9..0a66fc225559 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct media_entity *entity)
 	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
 }
 
+static inline u32 media_entity_id(struct media_entity *entity)
+{
+	return entity->id;
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 1/8] [media] media: create a macro to get entity ID
@ 2015-08-19 11:01   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Laurent Pinchart, linux-sh

Instead of accessing directly entity.id, let's create a macro,
as this field will be moved into a common struct later on.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index c55ab5029323..e429605ca2c3 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct media_device *mdev, u32 id)
 	spin_lock(&mdev->lock);
 
 	media_device_for_each_entity(entity, mdev) {
-		if ((entity->id == id && !next) ||
-		    (entity->id > id && next)) {
+		if (((media_entity_id(entity) == id) && !next) ||
+		    ((media_entity_id(entity) > id) && next)) {
 			spin_unlock(&mdev->lock);
 			return entity;
 		}
@@ -104,7 +104,7 @@ static long media_device_enum_entities(struct media_device *mdev,
 	if (ent == NULL)
 		return -EINVAL;
 
-	u_ent.id = ent->id;
+	u_ent.id = media_entity_id(ent);
 	if (ent->name)
 		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
 	u_ent.type = ent->type;
@@ -122,7 +122,7 @@ static long media_device_enum_entities(struct media_device *mdev,
 static void media_device_kpad_to_upad(const struct media_pad *kpad,
 				      struct media_pad_desc *upad)
 {
-	upad->entity = kpad->entity->id;
+	upad->entity = media_entity_id(kpad->entity);
 	upad->index = kpad->index;
 	upad->flags = kpad->flags;
 }
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 949e5f92cbdc..cb0ac4e0dfa5 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct media_entity_graph *graph,
 	graph->stack[graph->top].entity = NULL;
 	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
 
-	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
+	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
 		return;
 
-	__set_bit(entity->id, graph->entities);
+	__set_bit(media_entity_id(entity), graph->entities);
 	stack_push(graph, entity);
 }
 EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
@@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph *graph)
 
 		/* Get the entity in the other end of the link . */
 		next = media_entity_other(entity, link);
-		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
+		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
 			return NULL;
 
 		/* Has the entity already been visited? */
-		if (__test_and_set_bit(next->id, graph->entities)) {
+		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
 			link_top(graph)++;
 			continue;
 		}
diff --git a/drivers/media/platform/vsp1/vsp1_video.c b/drivers/media/platform/vsp1/vsp1_video.c
index 17f08973f835..debe4e539df6 100644
--- a/drivers/media/platform/vsp1/vsp1_video.c
+++ b/drivers/media/platform/vsp1/vsp1_video.c
@@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct vsp1_pipeline *pipe,
 			break;
 
 		/* Ensure the branch has no loop. */
-		if (entities & (1 << entity->subdev.entity.id))
+		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
 			return -EPIPE;
 
-		entities |= 1 << entity->subdev.entity.id;
+		entities |= 1 << media_entity_id(&entity->subdev.entity);
 
 		/* UDS can't be chained. */
 		if (entity->type == VSP1_ENTITY_UDS) {
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 8b21a4d920d9..0a66fc225559 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct media_entity *entity)
 	return entity->type & MEDIA_ENT_SUBTYPE_MASK;
 }
 
+static inline u32 media_entity_id(struct media_entity *entity)
+{
+	return entity->id;
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects
  2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
  2015-08-19 11:01   ` Mauro Carvalho Chehab
@ 2015-08-19 11:01 ` Mauro Carvalho Chehab
  2015-08-19 11:09   ` Hans Verkuil
  2015-08-21  1:02   ` Laurent Pinchart
  2015-08-19 11:01 ` [PATCH v6 3/8] [media] media: use media_gobj inside entities Mauro Carvalho Chehab
                   ` (5 subsequent siblings)
  7 siblings, 2 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Due to the MC API proposed changes, we'll need to have an unique
object ID for all graph objects, and have some shared fields
that will be common on all media graph objects.

Right now, the only common object is the object ID, but other
fields will be added later on.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index cb0ac4e0dfa5..4834172bf6f8 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -27,6 +27,38 @@
 #include <media/media-device.h>
 
 /**
+ *  media_gobj_init - Initialize a graph object
+ *
+ * @mdev:	Pointer to the media_device that contains the object
+ * @type:	Type of the object
+ * @gobj:	Pointer to the object
+ *
+ * This routine initializes the embedded struct media_gobj inside a
+ * media graph object. It is called automatically if media_*_create()
+ * calls are used. However, if the object (entity, link, pad, interface)
+ * is embedded on some other object, this function should be called before
+ * registering the object at the media controller.
+ */
+void media_gobj_init(struct media_device *mdev,
+			   enum media_gobj_type type,
+			   struct media_gobj *gobj)
+{
+	/* For now, nothing to do */
+}
+
+/**
+ *  media_gobj_remove - Stop using a graph object on a media device
+ *
+ * @graph_obj:	Pointer to the object
+ *
+ * This should be called at media_device_unregister_*() routines
+ */
+void media_gobj_remove(struct media_gobj *gobj)
+{
+	/* For now, nothing to do */
+}
+
+/**
  * media_entity_init - Initialize a media entity
  *
  * @num_pads: Total number of sink and source pads.
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 0a66fc225559..c1cd4fba051d 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -28,6 +28,39 @@
 #include <linux/list.h>
 #include <linux/media.h>
 
+/* Enums used internally at the media controller to represent graphs */
+
+/**
+ * enum media_gobj_type - type of a graph element
+ *
+ */
+enum media_gobj_type {
+	 /* FIXME: add the types here, as we embed media_gobj */
+	MEDIA_GRAPH_NONE
+};
+
+#define MEDIA_BITS_PER_TYPE		8
+#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
+#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
+
+/* Structs to represent the objects that belong to a media graph */
+
+/**
+ * struct media_gobj - Define a graph object.
+ *
+ * @id:		Non-zero object ID identifier. The ID should be unique
+ *		inside a media_device, as it is composed by
+ *		MEDIA_BITS_PER_TYPE to store the type plus
+ *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
+ *		(called as "local ID").
+ *
+ * All elements on the media graph should have this struct embedded
+ */
+struct media_gobj {
+	u32			id;
+};
+
+
 struct media_pipeline {
 };
 
@@ -118,6 +151,26 @@ static inline u32 media_entity_id(struct media_entity *entity)
 	return entity->id;
 }
 
+static inline enum media_gobj_type media_type(struct media_gobj *gobj)
+{
+	return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
+}
+
+static inline u32 media_localid(struct media_gobj *gobj)
+{
+	return gobj->id & MEDIA_LOCAL_ID_MASK;
+}
+
+static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
+{
+	u32 id;
+
+	id = type << MEDIA_BITS_PER_LOCAL_ID;
+	id |= local_id & MEDIA_LOCAL_ID_MASK;
+
+	return id;
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
@@ -131,6 +184,14 @@ struct media_entity_graph {
 	int top;
 };
 
+#define gobj_to_entity(gobj) \
+		container_of(gobj, struct media_entity, graph_obj)
+
+void media_gobj_init(struct media_device *mdev,
+		    enum media_gobj_type type,
+		    struct media_gobj *gobj);
+void media_gobj_remove(struct media_gobj *gobj);
+
 int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 3/8] [media] media: use media_gobj inside entities
  2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
  2015-08-19 11:01   ` Mauro Carvalho Chehab
  2015-08-19 11:01 ` [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
@ 2015-08-19 11:01 ` Mauro Carvalho Chehab
  2015-08-21  1:10   ` Laurent Pinchart
  2015-08-19 11:01 ` [PATCH v6 4/8] [media] media: use media_gobj inside pads Mauro Carvalho Chehab
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

As entities are graph elements, 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.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index e429605ca2c3..81d6a130efef 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -379,7 +379,6 @@ int __must_check __media_device_register(struct media_device *mdev,
 	if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
 		return -EINVAL;
 
-	mdev->entity_id = 1;
 	INIT_LIST_HEAD(&mdev->entities);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
@@ -433,10 +432,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	entity->parent = mdev;
 
 	spin_lock(&mdev->lock);
-	if (entity->id == 0)
-		entity->id = mdev->entity_id++;
-	else
-		mdev->entity_id = max(entity->id + 1, mdev->entity_id);
+	/* Initialize media_gobj embedded at the entity */
+	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	list_add_tail(&entity->list, &mdev->entities);
 	spin_unlock(&mdev->lock);
 
@@ -459,6 +456,7 @@ void media_device_unregister_entity(struct media_entity *entity)
 		return;
 
 	spin_lock(&mdev->lock);
+	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
 	entity->parent = NULL;
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 4834172bf6f8..888cb88e19bf 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -43,7 +43,12 @@ void media_gobj_init(struct media_device *mdev,
 			   enum media_gobj_type type,
 			   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;
+	}
 }
 
 /**
diff --git a/include/media/media-device.h b/include/media/media-device.h
index a44f18fdf321..f6deef6e5820 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -41,7 +41,7 @@ struct device;
  * @bus_info:	Unique and stable device location identifier
  * @hw_revision: Hardware device revision
  * @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
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -69,6 +69,7 @@ struct media_device {
 	u32 driver_version;
 
 	u32 entity_id;
+
 	struct list_head entities;
 
 	/* Protects the entities list */
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index c1cd4fba051d..9ca366334bcf 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -33,10 +33,10 @@
 /**
  * enum media_gobj_type - type of a graph element
  *
+ * @MEDIA_GRAPH_ENTITY:		Identify a media entity
  */
 enum media_gobj_type {
-	 /* FIXME: add the types here, as we embed media_gobj */
-	MEDIA_GRAPH_NONE
+	MEDIA_GRAPH_ENTITY,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -94,10 +94,9 @@ struct media_entity_operations {
 };
 
 struct media_entity {
+	struct media_gobj graph_obj;
 	struct list_head list;
 	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 */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
@@ -148,7 +147,7 @@ static inline u32 media_entity_subtype(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)
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 4/8] [media] media: use media_gobj inside pads
  2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
                   ` (2 preceding siblings ...)
  2015-08-19 11:01 ` [PATCH v6 3/8] [media] media: use media_gobj inside entities Mauro Carvalho Chehab
@ 2015-08-19 11:01 ` Mauro Carvalho Chehab
  2015-08-19 11:01 ` [PATCH v6 5/8] [media] media: use media_gobj inside links Mauro Carvalho Chehab
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

PADs also need unique object IDs that won't conflict with
the entity object IDs.

The pad objects are currently created via media_entity_init()
and, once created, never change.

While this will likely change in the future in order to
support dynamic changes, for now we'll keep PADs as arrays
and initialize the media_gobj embedded structs when
registering the entity.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 81d6a130efef..3bdda16584fe 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -427,6 +427,8 @@ EXPORT_SYMBOL_GPL(media_device_unregister);
 int __must_check media_device_register_entity(struct media_device *mdev,
 					      struct media_entity *entity)
 {
+	int i;
+
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->parent != NULL);
 	entity->parent = mdev;
@@ -435,6 +437,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	/* Initialize media_gobj embedded at the entity */
 	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	list_add_tail(&entity->list, &mdev->entities);
+
+	/* Initialize objects at the pads */
+	for (i = 0; i < entity->num_pads; i++)
+		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
+			       &entity->pads[i].graph_obj);
+
 	spin_unlock(&mdev->lock);
 
 	return 0;
@@ -450,12 +458,15 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
  */
 void media_device_unregister_entity(struct media_entity *entity)
 {
+	int i;
 	struct media_device *mdev = entity->parent;
 
 	if (mdev == NULL)
 		return;
 
 	spin_lock(&mdev->lock);
+	for (i = 0; i < entity->num_pads; i++)
+		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 888cb88e19bf..377c6655c5d0 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -48,6 +48,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_ENTITY:
 		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
 		break;
+	case MEDIA_GRAPH_PAD:
+		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
+		break;
 	}
 }
 
diff --git a/include/media/media-device.h b/include/media/media-device.h
index f6deef6e5820..9493721f630e 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -42,6 +42,7 @@ struct device;
  * @hw_revision: Hardware device revision
  * @driver_version: Device driver version
  * @entity_id:	Unique ID used on the last entity registered
+ * @pad_id:	Unique ID used on the last pad registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -69,6 +70,7 @@ struct media_device {
 	u32 driver_version;
 
 	u32 entity_id;
+	u32 pad_id;
 
 	struct list_head entities;
 
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 9ca366334bcf..39c9ca8f2e7a 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -34,9 +34,11 @@
  * enum media_gobj_type - type of a graph element
  *
  * @MEDIA_GRAPH_ENTITY:		Identify a media entity
+ * @MEDIA_GRAPH_PAD:		Identify a media pad
  */
 enum media_gobj_type {
 	MEDIA_GRAPH_ENTITY,
+	MEDIA_GRAPH_PAD,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -72,6 +74,7 @@ struct media_link {
 };
 
 struct media_pad {
+	struct media_gobj graph_obj;
 	struct media_entity *entity;	/* Entity this pad belongs to */
 	u16 index;			/* Pad index in the entity pads array */
 	unsigned long flags;		/* Pad flags (MEDIA_PAD_FL_*) */
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 5/8] [media] media: use media_gobj inside links
  2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
                   ` (3 preceding siblings ...)
  2015-08-19 11:01 ` [PATCH v6 4/8] [media] media: use media_gobj inside pads Mauro Carvalho Chehab
@ 2015-08-19 11:01 ` Mauro Carvalho Chehab
  2015-08-19 11:11   ` Hans Verkuil
  2015-08-19 11:01 ` [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered Mauro Carvalho Chehab
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

Just like entities and pads, links also need to have unique
Object IDs along a given media controller.

So, let's add a media_gobj inside it and initialize
the object then a new link is created.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 3bdda16584fe..065f6f08da37 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -438,6 +438,13 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
 	list_add_tail(&entity->list, &mdev->entities);
 
+	/*
+	 * Initialize objects at the links
+	 * in the case where links got created before entity register
+	 */
+	for (i = 0; i < entity->num_links; i++)
+		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
+				&entity->links[i].graph_obj);
 	/* Initialize objects at the pads */
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
@@ -465,6 +472,8 @@ void media_device_unregister_entity(struct media_entity *entity)
 		return;
 
 	spin_lock(&mdev->lock);
+	for (i = 0; i < entity->num_links; i++)
+		media_gobj_remove(&entity->links[i].graph_obj);
 	for (i = 0; i < entity->num_pads; i++)
 		media_gobj_remove(&entity->pads[i].graph_obj);
 	media_gobj_remove(&entity->graph_obj);
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 377c6655c5d0..36d725ec5f3d 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -51,6 +51,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
 		break;
+	case MEDIA_GRAPH_LINK:
+		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
+		break;
 	}
 }
 
@@ -491,6 +494,9 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 	link->sink = &sink->pads[sink_pad];
 	link->flags = flags;
 
+	/* Initialize graph object embedded at the new link */
+	media_gobj_init(source->parent, MEDIA_GRAPH_LINK, &link->graph_obj);
+
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
 	 */
@@ -504,6 +510,9 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 	backlink->sink = &sink->pads[sink_pad];
 	backlink->flags = flags;
 
+	/* Initialize graph object embedded at the new link */
+	media_gobj_init(sink->parent, MEDIA_GRAPH_LINK, &backlink->graph_obj);
+
 	link->reverse = backlink;
 	backlink->reverse = link;
 
diff --git a/include/media/media-device.h b/include/media/media-device.h
index 9493721f630e..05414e351f8e 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -43,6 +43,7 @@ struct device;
  * @driver_version: Device driver version
  * @entity_id:	Unique ID used on the last entity registered
  * @pad_id:	Unique ID used on the last pad registered
+ * @link_id:	Unique ID used on the last link registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -71,6 +72,7 @@ struct media_device {
 
 	u32 entity_id;
 	u32 pad_id;
+	u32 link_id;
 
 	struct list_head entities;
 
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 39c9ca8f2e7a..749b46c91217 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -35,10 +35,12 @@
  *
  * @MEDIA_GRAPH_ENTITY:		Identify a media entity
  * @MEDIA_GRAPH_PAD:		Identify a media pad
+ * @MEDIA_GRAPH_LINK:		Identify a media link
  */
 enum media_gobj_type {
 	MEDIA_GRAPH_ENTITY,
 	MEDIA_GRAPH_PAD,
+	MEDIA_GRAPH_LINK,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -67,6 +69,7 @@ struct media_pipeline {
 };
 
 struct media_link {
+	struct media_gobj graph_obj;
 	struct media_pad *source;	/* Source pad */
 	struct media_pad *sink;		/* Sink pad  */
 	struct media_link *reverse;	/* Link in the reverse direction */
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered
  2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
                   ` (4 preceding siblings ...)
  2015-08-19 11:01 ` [PATCH v6 5/8] [media] media: use media_gobj inside links Mauro Carvalho Chehab
@ 2015-08-19 11:01 ` Mauro Carvalho Chehab
  2015-08-19 11:11   ` Hans Verkuil
  2015-08-21  1:35   ` Laurent Pinchart
  2015-08-19 11:01 ` [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal Mauro Carvalho Chehab
  2015-08-19 11:01   ` Mauro Carvalho Chehab
  7 siblings, 2 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

We can only free the media device after being sure that no
graph object is used.

In order to help tracking it, let's add debug messages
that will print when the media controller gets registered
or unregistered.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 065f6f08da37..0f3844470147 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -359,6 +359,7 @@ static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
 
 static void media_device_release(struct media_devnode *mdev)
 {
+	dev_dbg(mdev->parent, "Media device released\n");
 }
 
 /**
@@ -397,6 +398,8 @@ int __must_check __media_device_register(struct media_device *mdev,
 		return ret;
 	}
 
+	dev_dbg(mdev->dev, "Media device registered\n");
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(__media_device_register);
@@ -416,6 +419,8 @@ void media_device_unregister(struct media_device *mdev)
 
 	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
 	media_devnode_unregister(&mdev->devnode);
+
+	dev_dbg(mdev->dev, "Media device unregistered\n");
 }
 EXPORT_SYMBOL_GPL(media_device_unregister);
 
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
                   ` (5 preceding siblings ...)
  2015-08-19 11:01 ` [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered Mauro Carvalho Chehab
@ 2015-08-19 11:01 ` Mauro Carvalho Chehab
  2015-08-19 11:12   ` Hans Verkuil
  2015-08-21  1:32   ` Laurent Pinchart
  2015-08-19 11:01   ` Mauro Carvalho Chehab
  7 siblings, 2 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 36d725ec5f3d..6d515e149d7f 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -27,6 +27,69 @@
 #include <media/media-device.h>
 
 /**
+ *  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 749b46c91217..bdd5e565ae76 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -61,6 +61,7 @@ enum media_gobj_type {
  * All elements on the media graph should have this struct embedded
  */
 struct media_gobj {
+	struct media_device	*mdev;
 	u32			id;
 };
 
@@ -192,6 +193,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.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 8/8] [media] media: rename the function that create pad links
  2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
  2015-08-19 11:01   ` Mauro Carvalho Chehab
  2015-08-19 11:01 ` [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
@ 2015-08-19 11:01   ` Mauro Carvalho Chehab
  2015-08-19 11:01 ` [PATCH v6 4/8] [media] media: use media_gobj inside pads Mauro Carvalho Chehab
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: linux-arm-kernel

Now that a link can be either between two different graph
objects, we'll need to add more functions to create links.
So, rename the existing one that create links only between
two pads as media_create_pad_link().

No functional changes.

This patch was created via this shell script:
	for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 6903b2503577..b424de6c3bb3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -199,7 +199,7 @@ pre-allocated and grows dynamically as needed.
 
 Drivers create links by calling
 
-	media_entity_create_link(struct media_entity *source, u16 source_pad,
+	media_create_pad_link(struct media_entity *source, u16 source_pad,
 				 struct media_entity *sink,   u16 sink_pad,
 				 u32 flags);
 
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 2fdcbb5f000a..65f59f2124b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -412,16 +412,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	if (tuner && fe)
-		media_entity_create_link(tuner, 0, fe, 0, 0);
+		media_create_pad_link(tuner, 0, fe, 0, 0);
 
 	if (fe && demux)
-		media_entity_create_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
-		media_entity_create_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && ca)
-		media_entity_create_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 6d167428727d..c81bfbfea32f 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1482,11 +1482,11 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
 		return ret;
 	}
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 30a9ca62e034..d3bff30bcb6f 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1756,7 +1756,7 @@ static int s5k5baf_registered(struct v4l2_subdev *sd)
 		v4l2_err(sd, "failed to register subdev %s\n",
 			 state->cis_sd.name);
 	else
-		ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS,
+		ret = media_create_pad_link(&state->cis_sd.entity, PAD_CIS,
 					       &state->sd.entity, PAD_CIS,
 					       MEDIA_LNK_FL_IMMUTABLE |
 					       MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 308613ea0aed..5aa49eb393a9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2495,7 +2495,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 			return rval;
 		}
 
-		rval = media_entity_create_link(&this->sd.entity,
+		rval = media_create_pad_link(&this->sd.entity,
 						this->source_pad,
 						&last->sd.entity,
 						last->sink_pad,
@@ -2503,7 +2503,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 						MEDIA_LNK_FL_IMMUTABLE);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_create_link failed\n");
+				"media_create_pad_link failed\n");
 			return rval;
 		}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d515e149d7f..35e52cd1fc5a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -542,7 +542,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 }
 
 int
-media_entity_create_link(struct media_entity *source, u16 source_pad,
+media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
 {
 	struct media_link *link;
@@ -586,7 +586,7 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_create_link);
+EXPORT_SYMBOL_GPL(media_create_pad_link);
 
 void __media_entity_remove_links(struct media_entity *entity)
 {
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 4f5586a4cbff..3ba76940eef5 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -729,7 +729,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 		flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
 
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					      FIMC_SD_PAD_SINK_CAM, flags);
 		if (ret)
 			return ret;
@@ -749,7 +749,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 			continue;
 
 		sink = &fmd->fimc_lite[i]->subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					       FLITE_SD_PAD_SINK, 0);
 		if (ret)
 			return ret;
@@ -781,13 +781,13 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
 		source = &fimc->subdev.entity;
 		sink = &fimc->ve.vdev.entity;
 		/* FIMC-LITE's subdev and video node */
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA,
 					       sink, 0, 0);
 		if (ret)
 			break;
 		/* Link from FIMC-LITE to IS-ISP subdev */
 		sink = &fmd->fimc_is->isp.subdev.entity;
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP,
 					       sink, 0, 0);
 		if (ret)
 			break;
@@ -811,7 +811,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 
 		/* Link from FIMC-IS-ISP subdev to FIMC */
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
+		ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
 					       sink, FIMC_SD_PAD_SINK_FIFO, 0);
 		if (ret)
 			return ret;
@@ -824,7 +824,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 	if (sink->num_pads = 0)
 		return 0;
 
-	return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
+	return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
 					sink, 0, 0);
 }
 
@@ -873,7 +873,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 				return -EINVAL;
 
 			pad = sensor->entity.num_pads - 1;
-			ret = media_entity_create_link(&sensor->entity, pad,
+			ret = media_create_pad_link(&sensor->entity, pad,
 					      &csis->entity, CSIS_PAD_SINK,
 					      MEDIA_LNK_FL_IMMUTABLE |
 					      MEDIA_LNK_FL_ENABLED);
@@ -927,7 +927,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 		source = &fmd->fimc[i]->vid_cap.subdev.entity;
 		sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
 
-		ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+		ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE,
 					      sink, 0, flags);
 		if (ret)
 			break;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 56e683b19a73..d6b2922ed55c 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1862,7 +1862,7 @@ static int isp_link_entity(
 		return -EINVAL;
 	}
 
-	return media_entity_create_link(entity, i, input, pad, flags);
+	return media_create_pad_link(entity, i, input, pad, flags);
 }
 
 static int isp_register_entities(struct isp_device *isp)
@@ -2001,51 +2001,51 @@ static int isp_initialize_modules(struct isp_device *isp)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_aewb.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_af.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_hist.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index 3b10304b580b..3fe425f254bb 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2667,7 +2667,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 		goto error_video;
 
 	/* Connect the CCDC subdev to the video node. */
-	ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
 			&ccdc->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index e1b5f5bea541..b215eb5049d6 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1100,7 +1100,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 		goto error_video;
 
 	/* Connect the video node to the ccp2 subdev. */
-	ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
+	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
 				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 6fff92f0813a..fcefc1e74881 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1265,7 +1265,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index b440c6342ca4..ad38d20c7770 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2312,12 +2312,12 @@ static int preview_init_entities(struct isp_prev_device *prev)
 		goto error_video_out;
 
 	/* Connect the video nodes to the previewer subdev. */
-	ret = media_entity_create_link(&prev->video_in.video.entity, 0,
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
 			&prev->subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
 			&prev->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 3deb1ec4a973..b48ad4d4b834 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1756,12 +1756,12 @@ static int resizer_init_entities(struct isp_res_device *res)
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	/* Connect the video nodes to the resizer subdev. */
-	ret = media_entity_create_link(&res->video_in.video.entity, 0,
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
 			&res->subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
 			&res->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332f0418..3e33c60be004 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -263,7 +263,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 {
 	int i, ret;
 
-	ret = media_entity_create_link(&camif->sensor.sd->entity, 0,
+	ret = media_create_pad_link(&camif->sensor.sd->entity, 0,
 				&camif->subdev.entity, CAMIF_SD_PAD_SINK,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
@@ -271,7 +271,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 		return ret;
 
 	for (i = 1; i < CAMIF_SD_PADS_NUM && !ret; i++) {
-		ret = media_entity_create_link(&camif->subdev.entity, i,
+		ret = media_create_pad_link(&camif->subdev.entity, i,
 				&camif->vp[i - 1].vdev.entity, 0,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 4e61886384e3..9cd94a76a9ed 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -101,7 +101,7 @@ static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
-			ret = media_entity_create_link(&source->subdev.entity,
+			ret = media_create_pad_link(&source->subdev.entity,
 						       source->source_pad,
 						       entity, pad, flags);
 			if (ret < 0)
@@ -262,7 +262,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	}
 
 	if (vsp1->pdata.features & VSP1_HAS_LIF) {
-		ret = media_entity_create_link(
+		ret = media_create_pad_link(
 			&vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
 			&vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
 		if (ret < 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529a3108..b60a528a8fe8 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -278,7 +278,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
 	rpf->entity.video = video;
 
 	/* Connect the video device to the RPF. */
-	ret = media_entity_create_link(&rpf->video.video.entity, 0,
+	ret = media_create_pad_link(&rpf->video.video.entity, 0,
 				       &rpf->entity.subdev.entity,
 				       RWPF_PAD_SINK,
 				       MEDIA_LNK_FL_ENABLED |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2f1573..d39aa4b8aea1 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -284,7 +284,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
 	if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
 		flags |= MEDIA_LNK_FL_IMMUTABLE;
 
-	ret = media_entity_create_link(&wpf->entity.subdev.entity,
+	ret = media_create_pad_link(&wpf->entity.subdev.entity,
 				       RWPF_PAD_SOURCE,
 				       &wpf->video.video.entity, 0, flags);
 	if (ret < 0)
diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
index 7b7cb9c28d2c..79d4be7ce9a5 100644
--- a/drivers/media/platform/xilinx/xilinx-vipp.c
+++ b/drivers/media/platform/xilinx/xilinx-vipp.c
@@ -156,7 +156,7 @@ static int xvip_graph_build_one(struct xvip_composite_device *xdev,
 			local->name, local_pad->index,
 			remote->name, remote_pad->index);
 
-		ret = media_entity_create_link(local, local_pad->index,
+		ret = media_create_pad_link(local, local_pad->index,
 					       remote, remote_pad->index,
 					       link_flags);
 		if (ret < 0) {
@@ -270,7 +270,7 @@ static int xvip_graph_build_dma(struct xvip_composite_device *xdev)
 			source->name, source_pad->index,
 			sink->name, sink_pad->index);
 
-		ret = media_entity_create_link(source, source_pad->index,
+		ret = media_create_pad_link(source, source_pad->index,
 					       sink, sink_pad->index,
 					       link_flags);
 		if (ret < 0) {
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 0378a2c99ebb..a55eb524ea21 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -260,13 +260,13 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
 	if (dev->vdev.entity.links)
-		media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 	if (dev->vbi_dev.entity.links)
-		media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4a117a58c39a..3b5c9ae39ad3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,11 +1264,11 @@ static void cx231xx_create_media_graph(struct cx231xx *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 245445491516..429e428ccd93 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -56,7 +56,7 @@ static int uvc_mc_register_entity(struct uvc_video_chain *chain,
 			continue;
 
 		remote_pad = remote->num_pads - 1;
-		ret = media_entity_create_link(source, remote_pad,
+		ret = media_create_pad_link(source, remote_pad,
 					       sink, i, flags);
 		if (ret < 0)
 			return ret;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index 8fb676186898..d96bdaaae50e 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -971,7 +971,7 @@ vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->video_in.vpfe_dev = vpfe_dev;
 
 	flags = 0;
-	ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
+	ret = media_create_pad_link(&ipipeif->video_in.video_dev.entity, 0,
 					&ipipeif->subdev.entity, 0, flags);
 	if (ret < 0)
 		goto fail;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index b1f01adfa7c8..df77288b0ec0 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1817,7 +1817,7 @@ int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
 	isif->video_out.vpfe_dev = vpfe_dev;
 	flags = 0;
 	/* connect isif to video node */
-	ret = media_entity_create_link(&isif->subdev.entity, 1,
+	ret = media_create_pad_link(&isif->subdev.entity, 1,
 				       &isif->video_out.video_dev.entity,
 				       0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 692789aa22f4..ae942de3a23d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1831,27 +1831,27 @@ int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
 	resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
 
 	/* create link between Resizer Crop----> Resizer A*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 1,
 				&resizer->resizer_a.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer Crop----> Resizer B*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 2,
 				&resizer->resizer_b.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer A ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_a.subdev.entity, 1,
 		&resizer->resizer_a.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer B ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_b.subdev.entity, 1,
 		&resizer->resizer_b.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 57426199ad7a..08c8a5f967d3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -445,32 +445,32 @@ static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
 		/* if entity has no pads (ex: amplifier),
 		   cant establish link */
 		if (vpfe_dev->sd[i]->entity.num_pads) {
-			ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
+			ret = media_create_pad_link(&vpfe_dev->sd[i]->entity,
 				0, &vpfe_dev->vpfe_isif.subdev.entity,
 				0, flags);
 			if (ret < 0)
 				goto out_resizer_register;
 		}
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipeif.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipe.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
 			1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 			&vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 9bfb725b9986..f32ab7b98ae2 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1259,7 +1259,7 @@ static int iss_register_entities(struct iss_device *iss)
 			goto done;
 		}
 
-		ret = media_entity_create_link(&sensor->entity, 0, input, pad,
+		ret = media_create_pad_link(&sensor->entity, 0, input, pad,
 					       flags);
 		if (ret < 0)
 			goto done;
@@ -1317,31 +1317,31 @@ static int iss_initialize_modules(struct iss_device *iss)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2b.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index e936cfc218cb..6b4dcbfa9425 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1291,7 +1291,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index be5f80d7b5dc..44c432ef2ac5 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -762,7 +762,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 		return ret;
 
 	/* Connect the IPIPEIF subdev to the video node. */
-	ret = media_entity_create_link(&ipipeif->subdev.entity,
+	ret = media_create_pad_link(&ipipeif->subdev.entity,
 				       IPIPEIF_PAD_SOURCE_ISIF_SF,
 				       &ipipeif->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 91e724085dba..b659e465cb56 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -806,7 +806,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 		return ret;
 
 	/* Connect the RESIZER subdev to the video node. */
-	ret = media_entity_create_link(&resizer->subdev.entity,
+	ret = media_create_pad_link(&resizer->subdev.entity,
 				       RESIZER_PAD_SOURCE_MEM,
 				       &resizer->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index bdd5e565ae76..3b653e9321f2 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -208,7 +208,7 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_entity_create_link(struct media_entity *source, u16 source_pad,
+int media_create_pad_link(struct media_entity *source, u16 source_pad,
 		struct media_entity *sink, u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 8/8] [media] media: rename the function that create pad links
@ 2015-08-19 11:01   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Jonathan Corbet,
	Kyungmin Park, Andrzej Hajda, Sakari Ailus, Sylwester Nawrocki,
	Kukjin Kim, Krzysztof Kozlowski, Laurent Pinchart, Hyun Kwon,
	Michal Simek, Sören Brinkmann, Greg Kroah-Hartman,
	Hans Verkuil, Rafael Lourenço de Lima Chehab, Shuah Khan,
	Matthias Schwarzott, Antti Palosaari, Olli Salonen,
	Tommi Rantala, Prabhakar Lad, Tapasweni Pathak, Haneen Mohammed,
	Navya Sri Nizamkari, Boris BREZILLON, anuvazhayil,
	Mahati Chamarthy, Jiayi Ye, Wolfram Sang, Heena Sirwani,
	linux-doc, linux-arm-kernel, linux-samsung-soc, linux-sh, devel

Now that a link can be either between two different graph
objects, we'll need to add more functions to create links.
So, rename the existing one that create links only between
two pads as media_create_pad_link().

No functional changes.

This patch was created via this shell script:
	for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 6903b2503577..b424de6c3bb3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -199,7 +199,7 @@ pre-allocated and grows dynamically as needed.
 
 Drivers create links by calling
 
-	media_entity_create_link(struct media_entity *source, u16 source_pad,
+	media_create_pad_link(struct media_entity *source, u16 source_pad,
 				 struct media_entity *sink,   u16 sink_pad,
 				 u32 flags);
 
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 2fdcbb5f000a..65f59f2124b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -412,16 +412,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	if (tuner && fe)
-		media_entity_create_link(tuner, 0, fe, 0, 0);
+		media_create_pad_link(tuner, 0, fe, 0, 0);
 
 	if (fe && demux)
-		media_entity_create_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
-		media_entity_create_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && ca)
-		media_entity_create_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 6d167428727d..c81bfbfea32f 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1482,11 +1482,11 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
 		return ret;
 	}
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 30a9ca62e034..d3bff30bcb6f 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1756,7 +1756,7 @@ static int s5k5baf_registered(struct v4l2_subdev *sd)
 		v4l2_err(sd, "failed to register subdev %s\n",
 			 state->cis_sd.name);
 	else
-		ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS,
+		ret = media_create_pad_link(&state->cis_sd.entity, PAD_CIS,
 					       &state->sd.entity, PAD_CIS,
 					       MEDIA_LNK_FL_IMMUTABLE |
 					       MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 308613ea0aed..5aa49eb393a9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2495,7 +2495,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 			return rval;
 		}
 
-		rval = media_entity_create_link(&this->sd.entity,
+		rval = media_create_pad_link(&this->sd.entity,
 						this->source_pad,
 						&last->sd.entity,
 						last->sink_pad,
@@ -2503,7 +2503,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 						MEDIA_LNK_FL_IMMUTABLE);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_create_link failed\n");
+				"media_create_pad_link failed\n");
 			return rval;
 		}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d515e149d7f..35e52cd1fc5a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -542,7 +542,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 }
 
 int
-media_entity_create_link(struct media_entity *source, u16 source_pad,
+media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
 {
 	struct media_link *link;
@@ -586,7 +586,7 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_create_link);
+EXPORT_SYMBOL_GPL(media_create_pad_link);
 
 void __media_entity_remove_links(struct media_entity *entity)
 {
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 4f5586a4cbff..3ba76940eef5 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -729,7 +729,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 		flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
 
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					      FIMC_SD_PAD_SINK_CAM, flags);
 		if (ret)
 			return ret;
@@ -749,7 +749,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 			continue;
 
 		sink = &fmd->fimc_lite[i]->subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					       FLITE_SD_PAD_SINK, 0);
 		if (ret)
 			return ret;
@@ -781,13 +781,13 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
 		source = &fimc->subdev.entity;
 		sink = &fimc->ve.vdev.entity;
 		/* FIMC-LITE's subdev and video node */
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA,
 					       sink, 0, 0);
 		if (ret)
 			break;
 		/* Link from FIMC-LITE to IS-ISP subdev */
 		sink = &fmd->fimc_is->isp.subdev.entity;
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP,
 					       sink, 0, 0);
 		if (ret)
 			break;
@@ -811,7 +811,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 
 		/* Link from FIMC-IS-ISP subdev to FIMC */
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
+		ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
 					       sink, FIMC_SD_PAD_SINK_FIFO, 0);
 		if (ret)
 			return ret;
@@ -824,7 +824,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 	if (sink->num_pads == 0)
 		return 0;
 
-	return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
+	return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
 					sink, 0, 0);
 }
 
@@ -873,7 +873,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 				return -EINVAL;
 
 			pad = sensor->entity.num_pads - 1;
-			ret = media_entity_create_link(&sensor->entity, pad,
+			ret = media_create_pad_link(&sensor->entity, pad,
 					      &csis->entity, CSIS_PAD_SINK,
 					      MEDIA_LNK_FL_IMMUTABLE |
 					      MEDIA_LNK_FL_ENABLED);
@@ -927,7 +927,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 		source = &fmd->fimc[i]->vid_cap.subdev.entity;
 		sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
 
-		ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+		ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE,
 					      sink, 0, flags);
 		if (ret)
 			break;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 56e683b19a73..d6b2922ed55c 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1862,7 +1862,7 @@ static int isp_link_entity(
 		return -EINVAL;
 	}
 
-	return media_entity_create_link(entity, i, input, pad, flags);
+	return media_create_pad_link(entity, i, input, pad, flags);
 }
 
 static int isp_register_entities(struct isp_device *isp)
@@ -2001,51 +2001,51 @@ static int isp_initialize_modules(struct isp_device *isp)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_aewb.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_af.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_hist.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index 3b10304b580b..3fe425f254bb 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2667,7 +2667,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 		goto error_video;
 
 	/* Connect the CCDC subdev to the video node. */
-	ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
 			&ccdc->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index e1b5f5bea541..b215eb5049d6 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1100,7 +1100,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 		goto error_video;
 
 	/* Connect the video node to the ccp2 subdev. */
-	ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
+	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
 				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 6fff92f0813a..fcefc1e74881 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1265,7 +1265,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index b440c6342ca4..ad38d20c7770 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2312,12 +2312,12 @@ static int preview_init_entities(struct isp_prev_device *prev)
 		goto error_video_out;
 
 	/* Connect the video nodes to the previewer subdev. */
-	ret = media_entity_create_link(&prev->video_in.video.entity, 0,
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
 			&prev->subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
 			&prev->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 3deb1ec4a973..b48ad4d4b834 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1756,12 +1756,12 @@ static int resizer_init_entities(struct isp_res_device *res)
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	/* Connect the video nodes to the resizer subdev. */
-	ret = media_entity_create_link(&res->video_in.video.entity, 0,
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
 			&res->subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
 			&res->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332f0418..3e33c60be004 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -263,7 +263,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 {
 	int i, ret;
 
-	ret = media_entity_create_link(&camif->sensor.sd->entity, 0,
+	ret = media_create_pad_link(&camif->sensor.sd->entity, 0,
 				&camif->subdev.entity, CAMIF_SD_PAD_SINK,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
@@ -271,7 +271,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 		return ret;
 
 	for (i = 1; i < CAMIF_SD_PADS_NUM && !ret; i++) {
-		ret = media_entity_create_link(&camif->subdev.entity, i,
+		ret = media_create_pad_link(&camif->subdev.entity, i,
 				&camif->vp[i - 1].vdev.entity, 0,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 4e61886384e3..9cd94a76a9ed 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -101,7 +101,7 @@ static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
-			ret = media_entity_create_link(&source->subdev.entity,
+			ret = media_create_pad_link(&source->subdev.entity,
 						       source->source_pad,
 						       entity, pad, flags);
 			if (ret < 0)
@@ -262,7 +262,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	}
 
 	if (vsp1->pdata.features & VSP1_HAS_LIF) {
-		ret = media_entity_create_link(
+		ret = media_create_pad_link(
 			&vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
 			&vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
 		if (ret < 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529a3108..b60a528a8fe8 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -278,7 +278,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
 	rpf->entity.video = video;
 
 	/* Connect the video device to the RPF. */
-	ret = media_entity_create_link(&rpf->video.video.entity, 0,
+	ret = media_create_pad_link(&rpf->video.video.entity, 0,
 				       &rpf->entity.subdev.entity,
 				       RWPF_PAD_SINK,
 				       MEDIA_LNK_FL_ENABLED |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2f1573..d39aa4b8aea1 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -284,7 +284,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
 	if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
 		flags |= MEDIA_LNK_FL_IMMUTABLE;
 
-	ret = media_entity_create_link(&wpf->entity.subdev.entity,
+	ret = media_create_pad_link(&wpf->entity.subdev.entity,
 				       RWPF_PAD_SOURCE,
 				       &wpf->video.video.entity, 0, flags);
 	if (ret < 0)
diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
index 7b7cb9c28d2c..79d4be7ce9a5 100644
--- a/drivers/media/platform/xilinx/xilinx-vipp.c
+++ b/drivers/media/platform/xilinx/xilinx-vipp.c
@@ -156,7 +156,7 @@ static int xvip_graph_build_one(struct xvip_composite_device *xdev,
 			local->name, local_pad->index,
 			remote->name, remote_pad->index);
 
-		ret = media_entity_create_link(local, local_pad->index,
+		ret = media_create_pad_link(local, local_pad->index,
 					       remote, remote_pad->index,
 					       link_flags);
 		if (ret < 0) {
@@ -270,7 +270,7 @@ static int xvip_graph_build_dma(struct xvip_composite_device *xdev)
 			source->name, source_pad->index,
 			sink->name, sink_pad->index);
 
-		ret = media_entity_create_link(source, source_pad->index,
+		ret = media_create_pad_link(source, source_pad->index,
 					       sink, sink_pad->index,
 					       link_flags);
 		if (ret < 0) {
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 0378a2c99ebb..a55eb524ea21 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -260,13 +260,13 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
 	if (dev->vdev.entity.links)
-		media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 	if (dev->vbi_dev.entity.links)
-		media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4a117a58c39a..3b5c9ae39ad3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,11 +1264,11 @@ static void cx231xx_create_media_graph(struct cx231xx *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 245445491516..429e428ccd93 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -56,7 +56,7 @@ static int uvc_mc_register_entity(struct uvc_video_chain *chain,
 			continue;
 
 		remote_pad = remote->num_pads - 1;
-		ret = media_entity_create_link(source, remote_pad,
+		ret = media_create_pad_link(source, remote_pad,
 					       sink, i, flags);
 		if (ret < 0)
 			return ret;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index 8fb676186898..d96bdaaae50e 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -971,7 +971,7 @@ vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->video_in.vpfe_dev = vpfe_dev;
 
 	flags = 0;
-	ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
+	ret = media_create_pad_link(&ipipeif->video_in.video_dev.entity, 0,
 					&ipipeif->subdev.entity, 0, flags);
 	if (ret < 0)
 		goto fail;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index b1f01adfa7c8..df77288b0ec0 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1817,7 +1817,7 @@ int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
 	isif->video_out.vpfe_dev = vpfe_dev;
 	flags = 0;
 	/* connect isif to video node */
-	ret = media_entity_create_link(&isif->subdev.entity, 1,
+	ret = media_create_pad_link(&isif->subdev.entity, 1,
 				       &isif->video_out.video_dev.entity,
 				       0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 692789aa22f4..ae942de3a23d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1831,27 +1831,27 @@ int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
 	resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
 
 	/* create link between Resizer Crop----> Resizer A*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 1,
 				&resizer->resizer_a.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer Crop----> Resizer B*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 2,
 				&resizer->resizer_b.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer A ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_a.subdev.entity, 1,
 		&resizer->resizer_a.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer B ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_b.subdev.entity, 1,
 		&resizer->resizer_b.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 57426199ad7a..08c8a5f967d3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -445,32 +445,32 @@ static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
 		/* if entity has no pads (ex: amplifier),
 		   cant establish link */
 		if (vpfe_dev->sd[i]->entity.num_pads) {
-			ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
+			ret = media_create_pad_link(&vpfe_dev->sd[i]->entity,
 				0, &vpfe_dev->vpfe_isif.subdev.entity,
 				0, flags);
 			if (ret < 0)
 				goto out_resizer_register;
 		}
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipeif.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipe.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
 			1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 			&vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 9bfb725b9986..f32ab7b98ae2 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1259,7 +1259,7 @@ static int iss_register_entities(struct iss_device *iss)
 			goto done;
 		}
 
-		ret = media_entity_create_link(&sensor->entity, 0, input, pad,
+		ret = media_create_pad_link(&sensor->entity, 0, input, pad,
 					       flags);
 		if (ret < 0)
 			goto done;
@@ -1317,31 +1317,31 @@ static int iss_initialize_modules(struct iss_device *iss)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2b.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index e936cfc218cb..6b4dcbfa9425 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1291,7 +1291,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index be5f80d7b5dc..44c432ef2ac5 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -762,7 +762,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 		return ret;
 
 	/* Connect the IPIPEIF subdev to the video node. */
-	ret = media_entity_create_link(&ipipeif->subdev.entity,
+	ret = media_create_pad_link(&ipipeif->subdev.entity,
 				       IPIPEIF_PAD_SOURCE_ISIF_SF,
 				       &ipipeif->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 91e724085dba..b659e465cb56 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -806,7 +806,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 		return ret;
 
 	/* Connect the RESIZER subdev to the video node. */
-	ret = media_entity_create_link(&resizer->subdev.entity,
+	ret = media_create_pad_link(&resizer->subdev.entity,
 				       RESIZER_PAD_SOURCE_MEM,
 				       &resizer->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index bdd5e565ae76..3b653e9321f2 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -208,7 +208,7 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_entity_create_link(struct media_entity *source, u16 source_pad,
+int media_create_pad_link(struct media_entity *source, u16 source_pad,
 		struct media_entity *sink, u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 8/8] [media] media: rename the function that create pad links
@ 2015-08-19 11:01   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: Linux Media Mailing List
  Cc: Mauro Carvalho Chehab, Mauro Carvalho Chehab, Jonathan Corbet,
	Kyungmin Park, Andrzej Hajda, Sakari Ailus, Sylwester Nawrocki,
	Kukjin Kim, Krzysztof Kozlowski, Laurent Pinchart, Hyun Kwon,
	Michal Simek, Sören Brinkmann, Greg Kroah-Hartman,
	Hans Verkuil, Rafael Lourenço de Lima Chehab, Shuah Khan,
	Matthias Schwarzott, Antti Palosaari, Olli Salonen

Now that a link can be either between two different graph
objects, we'll need to add more functions to create links.
So, rename the existing one that create links only between
two pads as media_create_pad_link().

No functional changes.

This patch was created via this shell script:
	for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 6903b2503577..b424de6c3bb3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -199,7 +199,7 @@ pre-allocated and grows dynamically as needed.
 
 Drivers create links by calling
 
-	media_entity_create_link(struct media_entity *source, u16 source_pad,
+	media_create_pad_link(struct media_entity *source, u16 source_pad,
 				 struct media_entity *sink,   u16 sink_pad,
 				 u32 flags);
 
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 2fdcbb5f000a..65f59f2124b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -412,16 +412,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	if (tuner && fe)
-		media_entity_create_link(tuner, 0, fe, 0, 0);
+		media_create_pad_link(tuner, 0, fe, 0, 0);
 
 	if (fe && demux)
-		media_entity_create_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
-		media_entity_create_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && ca)
-		media_entity_create_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 6d167428727d..c81bfbfea32f 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1482,11 +1482,11 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
 		return ret;
 	}
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 30a9ca62e034..d3bff30bcb6f 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1756,7 +1756,7 @@ static int s5k5baf_registered(struct v4l2_subdev *sd)
 		v4l2_err(sd, "failed to register subdev %s\n",
 			 state->cis_sd.name);
 	else
-		ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS,
+		ret = media_create_pad_link(&state->cis_sd.entity, PAD_CIS,
 					       &state->sd.entity, PAD_CIS,
 					       MEDIA_LNK_FL_IMMUTABLE |
 					       MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 308613ea0aed..5aa49eb393a9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2495,7 +2495,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 			return rval;
 		}
 
-		rval = media_entity_create_link(&this->sd.entity,
+		rval = media_create_pad_link(&this->sd.entity,
 						this->source_pad,
 						&last->sd.entity,
 						last->sink_pad,
@@ -2503,7 +2503,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 						MEDIA_LNK_FL_IMMUTABLE);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_create_link failed\n");
+				"media_create_pad_link failed\n");
 			return rval;
 		}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d515e149d7f..35e52cd1fc5a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -542,7 +542,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 }
 
 int
-media_entity_create_link(struct media_entity *source, u16 source_pad,
+media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
 {
 	struct media_link *link;
@@ -586,7 +586,7 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_create_link);
+EXPORT_SYMBOL_GPL(media_create_pad_link);
 
 void __media_entity_remove_links(struct media_entity *entity)
 {
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 4f5586a4cbff..3ba76940eef5 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -729,7 +729,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 		flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
 
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					      FIMC_SD_PAD_SINK_CAM, flags);
 		if (ret)
 			return ret;
@@ -749,7 +749,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 			continue;
 
 		sink = &fmd->fimc_lite[i]->subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					       FLITE_SD_PAD_SINK, 0);
 		if (ret)
 			return ret;
@@ -781,13 +781,13 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
 		source = &fimc->subdev.entity;
 		sink = &fimc->ve.vdev.entity;
 		/* FIMC-LITE's subdev and video node */
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA,
 					       sink, 0, 0);
 		if (ret)
 			break;
 		/* Link from FIMC-LITE to IS-ISP subdev */
 		sink = &fmd->fimc_is->isp.subdev.entity;
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP,
 					       sink, 0, 0);
 		if (ret)
 			break;
@@ -811,7 +811,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 
 		/* Link from FIMC-IS-ISP subdev to FIMC */
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
+		ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
 					       sink, FIMC_SD_PAD_SINK_FIFO, 0);
 		if (ret)
 			return ret;
@@ -824,7 +824,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 	if (sink->num_pads == 0)
 		return 0;
 
-	return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
+	return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
 					sink, 0, 0);
 }
 
@@ -873,7 +873,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 				return -EINVAL;
 
 			pad = sensor->entity.num_pads - 1;
-			ret = media_entity_create_link(&sensor->entity, pad,
+			ret = media_create_pad_link(&sensor->entity, pad,
 					      &csis->entity, CSIS_PAD_SINK,
 					      MEDIA_LNK_FL_IMMUTABLE |
 					      MEDIA_LNK_FL_ENABLED);
@@ -927,7 +927,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 		source = &fmd->fimc[i]->vid_cap.subdev.entity;
 		sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
 
-		ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+		ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE,
 					      sink, 0, flags);
 		if (ret)
 			break;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 56e683b19a73..d6b2922ed55c 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1862,7 +1862,7 @@ static int isp_link_entity(
 		return -EINVAL;
 	}
 
-	return media_entity_create_link(entity, i, input, pad, flags);
+	return media_create_pad_link(entity, i, input, pad, flags);
 }
 
 static int isp_register_entities(struct isp_device *isp)
@@ -2001,51 +2001,51 @@ static int isp_initialize_modules(struct isp_device *isp)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_aewb.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_af.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_hist.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index 3b10304b580b..3fe425f254bb 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2667,7 +2667,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 		goto error_video;
 
 	/* Connect the CCDC subdev to the video node. */
-	ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
 			&ccdc->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index e1b5f5bea541..b215eb5049d6 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1100,7 +1100,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 		goto error_video;
 
 	/* Connect the video node to the ccp2 subdev. */
-	ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
+	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
 				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 6fff92f0813a..fcefc1e74881 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1265,7 +1265,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index b440c6342ca4..ad38d20c7770 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2312,12 +2312,12 @@ static int preview_init_entities(struct isp_prev_device *prev)
 		goto error_video_out;
 
 	/* Connect the video nodes to the previewer subdev. */
-	ret = media_entity_create_link(&prev->video_in.video.entity, 0,
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
 			&prev->subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
 			&prev->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 3deb1ec4a973..b48ad4d4b834 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1756,12 +1756,12 @@ static int resizer_init_entities(struct isp_res_device *res)
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	/* Connect the video nodes to the resizer subdev. */
-	ret = media_entity_create_link(&res->video_in.video.entity, 0,
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
 			&res->subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
 			&res->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332f0418..3e33c60be004 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -263,7 +263,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 {
 	int i, ret;
 
-	ret = media_entity_create_link(&camif->sensor.sd->entity, 0,
+	ret = media_create_pad_link(&camif->sensor.sd->entity, 0,
 				&camif->subdev.entity, CAMIF_SD_PAD_SINK,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
@@ -271,7 +271,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 		return ret;
 
 	for (i = 1; i < CAMIF_SD_PADS_NUM && !ret; i++) {
-		ret = media_entity_create_link(&camif->subdev.entity, i,
+		ret = media_create_pad_link(&camif->subdev.entity, i,
 				&camif->vp[i - 1].vdev.entity, 0,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 4e61886384e3..9cd94a76a9ed 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -101,7 +101,7 @@ static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
-			ret = media_entity_create_link(&source->subdev.entity,
+			ret = media_create_pad_link(&source->subdev.entity,
 						       source->source_pad,
 						       entity, pad, flags);
 			if (ret < 0)
@@ -262,7 +262,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	}
 
 	if (vsp1->pdata.features & VSP1_HAS_LIF) {
-		ret = media_entity_create_link(
+		ret = media_create_pad_link(
 			&vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
 			&vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
 		if (ret < 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529a3108..b60a528a8fe8 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -278,7 +278,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
 	rpf->entity.video = video;
 
 	/* Connect the video device to the RPF. */
-	ret = media_entity_create_link(&rpf->video.video.entity, 0,
+	ret = media_create_pad_link(&rpf->video.video.entity, 0,
 				       &rpf->entity.subdev.entity,
 				       RWPF_PAD_SINK,
 				       MEDIA_LNK_FL_ENABLED |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2f1573..d39aa4b8aea1 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -284,7 +284,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
 	if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
 		flags |= MEDIA_LNK_FL_IMMUTABLE;
 
-	ret = media_entity_create_link(&wpf->entity.subdev.entity,
+	ret = media_create_pad_link(&wpf->entity.subdev.entity,
 				       RWPF_PAD_SOURCE,
 				       &wpf->video.video.entity, 0, flags);
 	if (ret < 0)
diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
index 7b7cb9c28d2c..79d4be7ce9a5 100644
--- a/drivers/media/platform/xilinx/xilinx-vipp.c
+++ b/drivers/media/platform/xilinx/xilinx-vipp.c
@@ -156,7 +156,7 @@ static int xvip_graph_build_one(struct xvip_composite_device *xdev,
 			local->name, local_pad->index,
 			remote->name, remote_pad->index);
 
-		ret = media_entity_create_link(local, local_pad->index,
+		ret = media_create_pad_link(local, local_pad->index,
 					       remote, remote_pad->index,
 					       link_flags);
 		if (ret < 0) {
@@ -270,7 +270,7 @@ static int xvip_graph_build_dma(struct xvip_composite_device *xdev)
 			source->name, source_pad->index,
 			sink->name, sink_pad->index);
 
-		ret = media_entity_create_link(source, source_pad->index,
+		ret = media_create_pad_link(source, source_pad->index,
 					       sink, sink_pad->index,
 					       link_flags);
 		if (ret < 0) {
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 0378a2c99ebb..a55eb524ea21 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -260,13 +260,13 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
 	if (dev->vdev.entity.links)
-		media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 	if (dev->vbi_dev.entity.links)
-		media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4a117a58c39a..3b5c9ae39ad3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,11 +1264,11 @@ static void cx231xx_create_media_graph(struct cx231xx *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 245445491516..429e428ccd93 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -56,7 +56,7 @@ static int uvc_mc_register_entity(struct uvc_video_chain *chain,
 			continue;
 
 		remote_pad = remote->num_pads - 1;
-		ret = media_entity_create_link(source, remote_pad,
+		ret = media_create_pad_link(source, remote_pad,
 					       sink, i, flags);
 		if (ret < 0)
 			return ret;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index 8fb676186898..d96bdaaae50e 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -971,7 +971,7 @@ vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->video_in.vpfe_dev = vpfe_dev;
 
 	flags = 0;
-	ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
+	ret = media_create_pad_link(&ipipeif->video_in.video_dev.entity, 0,
 					&ipipeif->subdev.entity, 0, flags);
 	if (ret < 0)
 		goto fail;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index b1f01adfa7c8..df77288b0ec0 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1817,7 +1817,7 @@ int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
 	isif->video_out.vpfe_dev = vpfe_dev;
 	flags = 0;
 	/* connect isif to video node */
-	ret = media_entity_create_link(&isif->subdev.entity, 1,
+	ret = media_create_pad_link(&isif->subdev.entity, 1,
 				       &isif->video_out.video_dev.entity,
 				       0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 692789aa22f4..ae942de3a23d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1831,27 +1831,27 @@ int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
 	resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
 
 	/* create link between Resizer Crop----> Resizer A*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 1,
 				&resizer->resizer_a.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer Crop----> Resizer B*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 2,
 				&resizer->resizer_b.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer A ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_a.subdev.entity, 1,
 		&resizer->resizer_a.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer B ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_b.subdev.entity, 1,
 		&resizer->resizer_b.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 57426199ad7a..08c8a5f967d3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -445,32 +445,32 @@ static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
 		/* if entity has no pads (ex: amplifier),
 		   cant establish link */
 		if (vpfe_dev->sd[i]->entity.num_pads) {
-			ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
+			ret = media_create_pad_link(&vpfe_dev->sd[i]->entity,
 				0, &vpfe_dev->vpfe_isif.subdev.entity,
 				0, flags);
 			if (ret < 0)
 				goto out_resizer_register;
 		}
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipeif.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipe.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
 			1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 			&vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 9bfb725b9986..f32ab7b98ae2 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1259,7 +1259,7 @@ static int iss_register_entities(struct iss_device *iss)
 			goto done;
 		}
 
-		ret = media_entity_create_link(&sensor->entity, 0, input, pad,
+		ret = media_create_pad_link(&sensor->entity, 0, input, pad,
 					       flags);
 		if (ret < 0)
 			goto done;
@@ -1317,31 +1317,31 @@ static int iss_initialize_modules(struct iss_device *iss)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2b.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index e936cfc218cb..6b4dcbfa9425 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1291,7 +1291,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index be5f80d7b5dc..44c432ef2ac5 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -762,7 +762,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 		return ret;
 
 	/* Connect the IPIPEIF subdev to the video node. */
-	ret = media_entity_create_link(&ipipeif->subdev.entity,
+	ret = media_create_pad_link(&ipipeif->subdev.entity,
 				       IPIPEIF_PAD_SOURCE_ISIF_SF,
 				       &ipipeif->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 91e724085dba..b659e465cb56 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -806,7 +806,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 		return ret;
 
 	/* Connect the RESIZER subdev to the video node. */
-	ret = media_entity_create_link(&resizer->subdev.entity,
+	ret = media_create_pad_link(&resizer->subdev.entity,
 				       RESIZER_PAD_SOURCE_MEM,
 				       &resizer->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index bdd5e565ae76..3b653e9321f2 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -208,7 +208,7 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_entity_create_link(struct media_entity *source, u16 source_pad,
+int media_create_pad_link(struct media_entity *source, u16 source_pad,
 		struct media_entity *sink, u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
-- 
2.4.3


^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH v6 8/8] [media] media: rename the function that create pad links
@ 2015-08-19 11:01   ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-19 11:01 UTC (permalink / raw)
  To: linux-arm-kernel

Now that a link can be either between two different graph
objects, we'll need to add more functions to create links.
So, rename the existing one that create links only between
two pads as media_create_pad_link().

No functional changes.

This patch was created via this shell script:
	for i in $(find drivers/media -name '*.[ch]' -type f) $(find drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g <$i >a && mv a $i; done

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 6903b2503577..b424de6c3bb3 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -199,7 +199,7 @@ pre-allocated and grows dynamically as needed.
 
 Drivers create links by calling
 
-	media_entity_create_link(struct media_entity *source, u16 source_pad,
+	media_create_pad_link(struct media_entity *source, u16 source_pad,
 				 struct media_entity *sink,   u16 sink_pad,
 				 u32 flags);
 
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index 2fdcbb5f000a..65f59f2124b4 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -412,16 +412,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	if (tuner && fe)
-		media_entity_create_link(tuner, 0, fe, 0, 0);
+		media_create_pad_link(tuner, 0, fe, 0, 0);
 
 	if (fe && demux)
-		media_entity_create_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
-		media_entity_create_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && ca)
-		media_entity_create_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 6d167428727d..c81bfbfea32f 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1482,11 +1482,11 @@ static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
 		return ret;
 	}
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
-	ret = media_entity_create_link(&state->sensor_sd.entity,
+	ret = media_create_pad_link(&state->sensor_sd.entity,
 			S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
 			MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 30a9ca62e034..d3bff30bcb6f 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -1756,7 +1756,7 @@ static int s5k5baf_registered(struct v4l2_subdev *sd)
 		v4l2_err(sd, "failed to register subdev %s\n",
 			 state->cis_sd.name);
 	else
-		ret = media_entity_create_link(&state->cis_sd.entity, PAD_CIS,
+		ret = media_create_pad_link(&state->cis_sd.entity, PAD_CIS,
 					       &state->sd.entity, PAD_CIS,
 					       MEDIA_LNK_FL_IMMUTABLE |
 					       MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 308613ea0aed..5aa49eb393a9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2495,7 +2495,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 			return rval;
 		}
 
-		rval = media_entity_create_link(&this->sd.entity,
+		rval = media_create_pad_link(&this->sd.entity,
 						this->source_pad,
 						&last->sd.entity,
 						last->sink_pad,
@@ -2503,7 +2503,7 @@ static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
 						MEDIA_LNK_FL_IMMUTABLE);
 		if (rval) {
 			dev_err(&client->dev,
-				"media_entity_create_link failed\n");
+				"media_create_pad_link failed\n");
 			return rval;
 		}
 
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index 6d515e149d7f..35e52cd1fc5a 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -542,7 +542,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 }
 
 int
-media_entity_create_link(struct media_entity *source, u16 source_pad,
+media_create_pad_link(struct media_entity *source, u16 source_pad,
 			 struct media_entity *sink, u16 sink_pad, u32 flags)
 {
 	struct media_link *link;
@@ -586,7 +586,7 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(media_entity_create_link);
+EXPORT_SYMBOL_GPL(media_create_pad_link);
 
 void __media_entity_remove_links(struct media_entity *entity)
 {
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 4f5586a4cbff..3ba76940eef5 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -729,7 +729,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 		flags = ((1 << i) & link_mask) ? MEDIA_LNK_FL_ENABLED : 0;
 
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					      FIMC_SD_PAD_SINK_CAM, flags);
 		if (ret)
 			return ret;
@@ -749,7 +749,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
 			continue;
 
 		sink = &fmd->fimc_lite[i]->subdev.entity;
-		ret = media_entity_create_link(source, pad, sink,
+		ret = media_create_pad_link(source, pad, sink,
 					       FLITE_SD_PAD_SINK, 0);
 		if (ret)
 			return ret;
@@ -781,13 +781,13 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
 		source = &fimc->subdev.entity;
 		sink = &fimc->ve.vdev.entity;
 		/* FIMC-LITE's subdev and video node */
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_DMA,
 					       sink, 0, 0);
 		if (ret)
 			break;
 		/* Link from FIMC-LITE to IS-ISP subdev */
 		sink = &fmd->fimc_is->isp.subdev.entity;
-		ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_ISP,
+		ret = media_create_pad_link(source, FLITE_SD_PAD_SOURCE_ISP,
 					       sink, 0, 0);
 		if (ret)
 			break;
@@ -811,7 +811,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 
 		/* Link from FIMC-IS-ISP subdev to FIMC */
 		sink = &fmd->fimc[i]->vid_cap.subdev.entity;
-		ret = media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
+		ret = media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_FIFO,
 					       sink, FIMC_SD_PAD_SINK_FIFO, 0);
 		if (ret)
 			return ret;
@@ -824,7 +824,7 @@ static int __fimc_md_create_fimc_is_links(struct fimc_md *fmd)
 	if (sink->num_pads == 0)
 		return 0;
 
-	return media_entity_create_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
+	return media_create_pad_link(source, FIMC_ISP_SD_PAD_SRC_DMA,
 					sink, 0, 0);
 }
 
@@ -873,7 +873,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 				return -EINVAL;
 
 			pad = sensor->entity.num_pads - 1;
-			ret = media_entity_create_link(&sensor->entity, pad,
+			ret = media_create_pad_link(&sensor->entity, pad,
 					      &csis->entity, CSIS_PAD_SINK,
 					      MEDIA_LNK_FL_IMMUTABLE |
 					      MEDIA_LNK_FL_ENABLED);
@@ -927,7 +927,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
 		source = &fmd->fimc[i]->vid_cap.subdev.entity;
 		sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
 
-		ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
+		ret = media_create_pad_link(source, FIMC_SD_PAD_SOURCE,
 					      sink, 0, flags);
 		if (ret)
 			break;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 56e683b19a73..d6b2922ed55c 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1862,7 +1862,7 @@ static int isp_link_entity(
 		return -EINVAL;
 	}
 
-	return media_entity_create_link(entity, i, input, pad, flags);
+	return media_create_pad_link(entity, i, input, pad, flags);
 }
 
 static int isp_register_entities(struct isp_device *isp)
@@ -2001,51 +2001,51 @@ static int isp_initialize_modules(struct isp_device *isp)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
 			&isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_aewb.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_af.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
 			&isp->isp_hist.subdev.entity, 0,
 			MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index 3b10304b580b..3fe425f254bb 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -2667,7 +2667,7 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
 		goto error_video;
 
 	/* Connect the CCDC subdev to the video node. */
-	ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
+	ret = media_create_pad_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
 			&ccdc->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index e1b5f5bea541..b215eb5049d6 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1100,7 +1100,7 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
 		goto error_video;
 
 	/* Connect the video node to the ccp2 subdev. */
-	ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
+	ret = media_create_pad_link(&ccp2->video_in.video.entity, 0,
 				       &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 6fff92f0813a..fcefc1e74881 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -1265,7 +1265,7 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index b440c6342ca4..ad38d20c7770 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -2312,12 +2312,12 @@ static int preview_init_entities(struct isp_prev_device *prev)
 		goto error_video_out;
 
 	/* Connect the video nodes to the previewer subdev. */
-	ret = media_entity_create_link(&prev->video_in.video.entity, 0,
+	ret = media_create_pad_link(&prev->video_in.video.entity, 0,
 			&prev->subdev.entity, PREV_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
+	ret = media_create_pad_link(&prev->subdev.entity, PREV_PAD_SOURCE,
 			&prev->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/omap3isp/ispresizer.c b/drivers/media/platform/omap3isp/ispresizer.c
index 3deb1ec4a973..b48ad4d4b834 100644
--- a/drivers/media/platform/omap3isp/ispresizer.c
+++ b/drivers/media/platform/omap3isp/ispresizer.c
@@ -1756,12 +1756,12 @@ static int resizer_init_entities(struct isp_res_device *res)
 	res->video_out.video.entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	/* Connect the video nodes to the resizer subdev. */
-	ret = media_entity_create_link(&res->video_in.video.entity, 0,
+	ret = media_create_pad_link(&res->video_in.video.entity, 0,
 			&res->subdev.entity, RESZ_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
+	ret = media_create_pad_link(&res->subdev.entity, RESZ_PAD_SOURCE,
 			&res->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index f47b332f0418..3e33c60be004 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -263,7 +263,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 {
 	int i, ret;
 
-	ret = media_entity_create_link(&camif->sensor.sd->entity, 0,
+	ret = media_create_pad_link(&camif->sensor.sd->entity, 0,
 				&camif->subdev.entity, CAMIF_SD_PAD_SINK,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
@@ -271,7 +271,7 @@ static int camif_create_media_links(struct camif_dev *camif)
 		return ret;
 
 	for (i = 1; i < CAMIF_SD_PADS_NUM && !ret; i++) {
-		ret = media_entity_create_link(&camif->subdev.entity, i,
+		ret = media_create_pad_link(&camif->subdev.entity, i,
 				&camif->vp[i - 1].vdev.entity, 0,
 				MEDIA_LNK_FL_IMMUTABLE |
 				MEDIA_LNK_FL_ENABLED);
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 4e61886384e3..9cd94a76a9ed 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -101,7 +101,7 @@ static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
 			if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
 				continue;
 
-			ret = media_entity_create_link(&source->subdev.entity,
+			ret = media_create_pad_link(&source->subdev.entity,
 						       source->source_pad,
 						       entity, pad, flags);
 			if (ret < 0)
@@ -262,7 +262,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
 	}
 
 	if (vsp1->pdata.features & VSP1_HAS_LIF) {
-		ret = media_entity_create_link(
+		ret = media_create_pad_link(
 			&vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
 			&vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
 		if (ret < 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index 3294529a3108..b60a528a8fe8 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -278,7 +278,7 @@ struct vsp1_rwpf *vsp1_rpf_create(struct vsp1_device *vsp1, unsigned int index)
 	rpf->entity.video = video;
 
 	/* Connect the video device to the RPF. */
-	ret = media_entity_create_link(&rpf->video.video.entity, 0,
+	ret = media_create_pad_link(&rpf->video.video.entity, 0,
 				       &rpf->entity.subdev.entity,
 				       RWPF_PAD_SINK,
 				       MEDIA_LNK_FL_ENABLED |
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 1d2b3a2f1573..d39aa4b8aea1 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -284,7 +284,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
 	if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
 		flags |= MEDIA_LNK_FL_IMMUTABLE;
 
-	ret = media_entity_create_link(&wpf->entity.subdev.entity,
+	ret = media_create_pad_link(&wpf->entity.subdev.entity,
 				       RWPF_PAD_SOURCE,
 				       &wpf->video.video.entity, 0, flags);
 	if (ret < 0)
diff --git a/drivers/media/platform/xilinx/xilinx-vipp.c b/drivers/media/platform/xilinx/xilinx-vipp.c
index 7b7cb9c28d2c..79d4be7ce9a5 100644
--- a/drivers/media/platform/xilinx/xilinx-vipp.c
+++ b/drivers/media/platform/xilinx/xilinx-vipp.c
@@ -156,7 +156,7 @@ static int xvip_graph_build_one(struct xvip_composite_device *xdev,
 			local->name, local_pad->index,
 			remote->name, remote_pad->index);
 
-		ret = media_entity_create_link(local, local_pad->index,
+		ret = media_create_pad_link(local, local_pad->index,
 					       remote, remote_pad->index,
 					       link_flags);
 		if (ret < 0) {
@@ -270,7 +270,7 @@ static int xvip_graph_build_dma(struct xvip_composite_device *xdev)
 			source->name, source_pad->index,
 			sink->name, sink_pad->index);
 
-		ret = media_entity_create_link(source, source_pad->index,
+		ret = media_create_pad_link(source, source_pad->index,
 					       sink, sink_pad->index,
 					       link_flags);
 		if (ret < 0) {
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 0378a2c99ebb..a55eb524ea21 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -260,13 +260,13 @@ static void au0828_create_media_graph(struct au0828_dev *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
 	if (dev->vdev.entity.links)
-		media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+		media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 	if (dev->vbi_dev.entity.links)
-		media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+		media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 4a117a58c39a..3b5c9ae39ad3 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1264,11 +1264,11 @@ static void cx231xx_create_media_graph(struct cx231xx *dev)
 		return;
 
 	if (tuner)
-		media_entity_create_link(tuner, 0, decoder, 0,
+		media_create_pad_link(tuner, 0, decoder, 0,
 					 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 1, &dev->vdev.entity, 0,
+	media_create_pad_link(decoder, 1, &dev->vdev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
-	media_entity_create_link(decoder, 2, &dev->vbi_dev.entity, 0,
+	media_create_pad_link(decoder, 2, &dev->vbi_dev.entity, 0,
 				 MEDIA_LNK_FL_ENABLED);
 #endif
 }
diff --git a/drivers/media/usb/uvc/uvc_entity.c b/drivers/media/usb/uvc/uvc_entity.c
index 245445491516..429e428ccd93 100644
--- a/drivers/media/usb/uvc/uvc_entity.c
+++ b/drivers/media/usb/uvc/uvc_entity.c
@@ -56,7 +56,7 @@ static int uvc_mc_register_entity(struct uvc_video_chain *chain,
 			continue;
 
 		remote_pad = remote->num_pads - 1;
-		ret = media_entity_create_link(source, remote_pad,
+		ret = media_create_pad_link(source, remote_pad,
 					       sink, i, flags);
 		if (ret < 0)
 			return ret;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index 8fb676186898..d96bdaaae50e 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -971,7 +971,7 @@ vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
 	ipipeif->video_in.vpfe_dev = vpfe_dev;
 
 	flags = 0;
-	ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
+	ret = media_create_pad_link(&ipipeif->video_in.video_dev.entity, 0,
 					&ipipeif->subdev.entity, 0, flags);
 	if (ret < 0)
 		goto fail;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index b1f01adfa7c8..df77288b0ec0 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1817,7 +1817,7 @@ int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
 	isif->video_out.vpfe_dev = vpfe_dev;
 	flags = 0;
 	/* connect isif to video node */
-	ret = media_entity_create_link(&isif->subdev.entity, 1,
+	ret = media_create_pad_link(&isif->subdev.entity, 1,
 				       &isif->video_out.video_dev.entity,
 				       0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 692789aa22f4..ae942de3a23d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1831,27 +1831,27 @@ int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
 	resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
 
 	/* create link between Resizer Crop----> Resizer A*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 1,
 				&resizer->resizer_a.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer Crop----> Resizer B*/
-	ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
+	ret = media_create_pad_link(&resizer->crop_resizer.subdev.entity, 2,
 				&resizer->resizer_b.subdev.entity,
 				0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer A ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_a.subdev.entity, 1,
 		&resizer->resizer_a.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
 
 	/* create link between Resizer B ----> video out */
-	ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
+	ret = media_create_pad_link(&resizer->resizer_b.subdev.entity, 1,
 		&resizer->resizer_b.video_out.video_dev.entity, 0, flags);
 	if (ret < 0)
 		goto out_create_link;
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index 57426199ad7a..08c8a5f967d3 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -445,32 +445,32 @@ static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
 		/* if entity has no pads (ex: amplifier),
 		   cant establish link */
 		if (vpfe_dev->sd[i]->entity.num_pads) {
-			ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
+			ret = media_create_pad_link(&vpfe_dev->sd[i]->entity,
 				0, &vpfe_dev->vpfe_isif.subdev.entity,
 				0, flags);
 			if (ret < 0)
 				goto out_resizer_register;
 		}
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipeif.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 				       &vpfe_dev->vpfe_ipipe.subdev.entity,
 				       0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
 			1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
 		goto out_resizer_register;
 
-	ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
+	ret = media_create_pad_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
 			&vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
 			0, flags);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 9bfb725b9986..f32ab7b98ae2 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1259,7 +1259,7 @@ static int iss_register_entities(struct iss_device *iss)
 			goto done;
 		}
 
-		ret = media_entity_create_link(&sensor->entity, 0, input, pad,
+		ret = media_create_pad_link(&sensor->entity, 0, input, pad,
 					       flags);
 		if (ret < 0)
 			goto done;
@@ -1317,31 +1317,31 @@ static int iss_initialize_modules(struct iss_device *iss)
 	}
 
 	/* Connect the submodules. */
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2a.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->csi2b.subdev.entity, CSI2_PAD_SOURCE,
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipeif.subdev.entity, IPIPEIF_PAD_SOURCE_VP,
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SINK, 0);
 	if (ret < 0)
 		goto error_link;
 
-	ret = media_entity_create_link(
+	ret = media_create_pad_link(
 			&iss->ipipe.subdev.entity, IPIPE_PAD_SOURCE_VP,
 			&iss->resizer.subdev.entity, RESIZER_PAD_SINK, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index e936cfc218cb..6b4dcbfa9425 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1291,7 +1291,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
 		goto error_video;
 
 	/* Connect the CSI2 subdev to the video node. */
-	ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
+	ret = media_create_pad_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
 				       &csi2->video_out.video.entity, 0, 0);
 	if (ret < 0)
 		goto error_link;
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index be5f80d7b5dc..44c432ef2ac5 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -762,7 +762,7 @@ static int ipipeif_init_entities(struct iss_ipipeif_device *ipipeif)
 		return ret;
 
 	/* Connect the IPIPEIF subdev to the video node. */
-	ret = media_entity_create_link(&ipipeif->subdev.entity,
+	ret = media_create_pad_link(&ipipeif->subdev.entity,
 				       IPIPEIF_PAD_SOURCE_ISIF_SF,
 				       &ipipeif->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 91e724085dba..b659e465cb56 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -806,7 +806,7 @@ static int resizer_init_entities(struct iss_resizer_device *resizer)
 		return ret;
 
 	/* Connect the RESIZER subdev to the video node. */
-	ret = media_entity_create_link(&resizer->subdev.entity,
+	ret = media_create_pad_link(&resizer->subdev.entity,
 				       RESIZER_PAD_SOURCE_MEM,
 				       &resizer->video_out.video.entity, 0, 0);
 	if (ret < 0)
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index bdd5e565ae76..3b653e9321f2 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -208,7 +208,7 @@ int media_entity_init(struct media_entity *entity, u16 num_pads,
 		struct media_pad *pads);
 void media_entity_cleanup(struct media_entity *entity);
 
-int media_entity_create_link(struct media_entity *source, u16 source_pad,
+int media_create_pad_link(struct media_entity *source, u16 source_pad,
 		struct media_entity *sink, u16 sink_pad, u32 flags);
 void __media_entity_remove_links(struct media_entity *entity);
 void media_entity_remove_links(struct media_entity *entity);
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects
  2015-08-19 11:01 ` [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
@ 2015-08-19 11:09   ` Hans Verkuil
  2015-08-21  1:02   ` Laurent Pinchart
  1 sibling, 0 replies; 48+ messages in thread
From: Hans Verkuil @ 2015-08-19 11:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/19/15 13:01, Mauro Carvalho Chehab wrote:
> Due to the MC API proposed changes, we'll need to have an unique
> object ID for all graph objects, and have some shared fields
> that will be common on all media graph objects.
> 
> Right now, the only common object is the object ID, but other
> fields will be added later on.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Thanks!

	Hans

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 5/8] [media] media: use media_gobj inside links
  2015-08-19 11:01 ` [PATCH v6 5/8] [media] media: use media_gobj inside links Mauro Carvalho Chehab
@ 2015-08-19 11:11   ` Hans Verkuil
  0 siblings, 0 replies; 48+ messages in thread
From: Hans Verkuil @ 2015-08-19 11:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/19/15 13:01, Mauro Carvalho Chehab wrote:
> Just like entities and pads, links also need to have unique
> Object IDs along a given media controller.
> 
> So, let's add a media_gobj inside it and initialize
> the object then a new link is created.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Hmm, my earlier Ack was lost. Here it is again:

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 3bdda16584fe..065f6f08da37 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -438,6 +438,13 @@ int __must_check media_device_register_entity(struct media_device *mdev,
>  	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
>  	list_add_tail(&entity->list, &mdev->entities);
>  
> +	/*
> +	 * Initialize objects at the links
> +	 * in the case where links got created before entity register
> +	 */
> +	for (i = 0; i < entity->num_links; i++)
> +		media_gobj_init(mdev, MEDIA_GRAPH_LINK,
> +				&entity->links[i].graph_obj);
>  	/* Initialize objects at the pads */
>  	for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
> @@ -465,6 +472,8 @@ void media_device_unregister_entity(struct media_entity *entity)
>  		return;
>  
>  	spin_lock(&mdev->lock);
> +	for (i = 0; i < entity->num_links; i++)
> +		media_gobj_remove(&entity->links[i].graph_obj);
>  	for (i = 0; i < entity->num_pads; i++)
>  		media_gobj_remove(&entity->pads[i].graph_obj);
>  	media_gobj_remove(&entity->graph_obj);
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 377c6655c5d0..36d725ec5f3d 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -51,6 +51,9 @@ void media_gobj_init(struct media_device *mdev,
>  	case MEDIA_GRAPH_PAD:
>  		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
>  		break;
> +	case MEDIA_GRAPH_LINK:
> +		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
> +		break;
>  	}
>  }
>  
> @@ -491,6 +494,9 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
>  	link->sink = &sink->pads[sink_pad];
>  	link->flags = flags;
>  
> +	/* Initialize graph object embedded at the new link */
> +	media_gobj_init(source->parent, MEDIA_GRAPH_LINK, &link->graph_obj);
> +
>  	/* Create the backlink. Backlinks are used to help graph traversal and
>  	 * are not reported to userspace.
>  	 */
> @@ -504,6 +510,9 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
>  	backlink->sink = &sink->pads[sink_pad];
>  	backlink->flags = flags;
>  
> +	/* Initialize graph object embedded at the new link */
> +	media_gobj_init(sink->parent, MEDIA_GRAPH_LINK, &backlink->graph_obj);
> +
>  	link->reverse = backlink;
>  	backlink->reverse = link;
>  
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index 9493721f630e..05414e351f8e 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -43,6 +43,7 @@ struct device;
>   * @driver_version: Device driver version
>   * @entity_id:	Unique ID used on the last entity registered
>   * @pad_id:	Unique ID used on the last pad registered
> + * @link_id:	Unique ID used on the last link registered
>   * @entities:	List of registered entities
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
> @@ -71,6 +72,7 @@ struct media_device {
>  
>  	u32 entity_id;
>  	u32 pad_id;
> +	u32 link_id;
>  
>  	struct list_head entities;
>  
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 39c9ca8f2e7a..749b46c91217 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -35,10 +35,12 @@
>   *
>   * @MEDIA_GRAPH_ENTITY:		Identify a media entity
>   * @MEDIA_GRAPH_PAD:		Identify a media pad
> + * @MEDIA_GRAPH_LINK:		Identify a media link
>   */
>  enum media_gobj_type {
>  	MEDIA_GRAPH_ENTITY,
>  	MEDIA_GRAPH_PAD,
> +	MEDIA_GRAPH_LINK,
>  };
>  
>  #define MEDIA_BITS_PER_TYPE		8
> @@ -67,6 +69,7 @@ struct media_pipeline {
>  };
>  
>  struct media_link {
> +	struct media_gobj graph_obj;
>  	struct media_pad *source;	/* Source pad */
>  	struct media_pad *sink;		/* Sink pad  */
>  	struct media_link *reverse;	/* Link in the reverse direction */
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered
  2015-08-19 11:01 ` [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered Mauro Carvalho Chehab
@ 2015-08-19 11:11   ` Hans Verkuil
  2015-08-21  1:35   ` Laurent Pinchart
  1 sibling, 0 replies; 48+ messages in thread
From: Hans Verkuil @ 2015-08-19 11:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/19/15 13:01, Mauro Carvalho Chehab wrote:
> We can only free the media device after being sure that no
> graph object is used.
> 
> In order to help tracking it, let's add debug messages
> that will print when the media controller gets registered
> or unregistered.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Thanks,

	Hans

> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 065f6f08da37..0f3844470147 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -359,6 +359,7 @@ static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
>  
>  static void media_device_release(struct media_devnode *mdev)
>  {
> +	dev_dbg(mdev->parent, "Media device released\n");
>  }
>  
>  /**
> @@ -397,6 +398,8 @@ int __must_check __media_device_register(struct media_device *mdev,
>  		return ret;
>  	}
>  
> +	dev_dbg(mdev->dev, "Media device registered\n");
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(__media_device_register);
> @@ -416,6 +419,8 @@ void media_device_unregister(struct media_device *mdev)
>  
>  	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
>  	media_devnode_unregister(&mdev->devnode);
> +
> +	dev_dbg(mdev->dev, "Media device unregistered\n");
>  }
>  EXPORT_SYMBOL_GPL(media_device_unregister);
>  
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-19 11:01 ` [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal Mauro Carvalho Chehab
@ 2015-08-19 11:12   ` Hans Verkuil
  2015-08-21  1:32   ` Laurent Pinchart
  1 sibling, 0 replies; 48+ messages in thread
From: Hans Verkuil @ 2015-08-19 11:12 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

On 08/19/15 13:01, Mauro Carvalho Chehab wrote:
> 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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

Acked-by: Hans Verkuil <hans.verkuil@cisco.com>

Thanks!

	Hans

> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 36d725ec5f3d..6d515e149d7f 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -27,6 +27,69 @@
>  #include <media/media-device.h>
>  
>  /**
> + *  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 749b46c91217..bdd5e565ae76 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -61,6 +61,7 @@ enum media_gobj_type {
>   * All elements on the media graph should have this struct embedded
>   */
>  struct media_gobj {
> +	struct media_device	*mdev;
>  	u32			id;
>  };
>  
> @@ -192,6 +193,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);
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
  2015-08-19 11:01   ` Mauro Carvalho Chehab
@ 2015-08-21  0:40     ` Laurent Pinchart
  -1 siblings, 0 replies; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21  0:40 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Hi Mauro,

Thank you for the patch.

On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> Instead of accessing directly entity.id, let's create a macro,
> as this field will be moved into a common struct later on.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index c55ab5029323..e429605ca2c3 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct
> media_device *mdev, u32 id) spin_lock(&mdev->lock);
> 
>  	media_device_for_each_entity(entity, mdev) {
> -		if ((entity->id = id && !next) ||
> -		    (entity->id > id && next)) {
> +		if (((media_entity_id(entity) = id) && !next) ||
> +		    ((media_entity_id(entity) > id) && next)) {
>  			spin_unlock(&mdev->lock);
>  			return entity;
>  		}
> @@ -104,7 +104,7 @@ static long media_device_enum_entities(struct
> media_device *mdev, if (ent = NULL)
>  		return -EINVAL;
> 
> -	u_ent.id = ent->id;
> +	u_ent.id = media_entity_id(ent);
>  	if (ent->name)
>  		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
>  	u_ent.type = ent->type;
> @@ -122,7 +122,7 @@ static long media_device_enum_entities(struct
> media_device *mdev, static void media_device_kpad_to_upad(const struct
> media_pad *kpad, struct media_pad_desc *upad)
>  {
> -	upad->entity = kpad->entity->id;
> +	upad->entity = media_entity_id(kpad->entity);
>  	upad->index = kpad->index;
>  	upad->flags = kpad->flags;
>  }
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 949e5f92cbdc..cb0ac4e0dfa5 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct
> media_entity_graph *graph, graph->stack[graph->top].entity = NULL;
>  	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
> 
> -	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> +	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
>  		return;
> 
> -	__set_bit(entity->id, graph->entities);
> +	__set_bit(media_entity_id(entity), graph->entities);
>  	stack_push(graph, entity);
>  }
>  EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> @@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph
> *graph)
> 
>  		/* Get the entity in the other end of the link . */
>  		next = media_entity_other(entity, link);
> -		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> +		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
>  			return NULL;
> 
>  		/* Has the entity already been visited? */
> -		if (__test_and_set_bit(next->id, graph->entities)) {
> +		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
>  			link_top(graph)++;
>  			continue;
>  		}
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> b/drivers/media/platform/vsp1/vsp1_video.c index 17f08973f835..debe4e539df6
> 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> vsp1_pipeline *pipe, break;
> 
>  		/* Ensure the branch has no loop. */
> -		if (entities & (1 << entity->subdev.entity.id))
> +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
>  			return -EPIPE;
> 
> -		entities |= 1 << entity->subdev.entity.id;
> +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> 
>  		/* UDS can't be chained. */
>  		if (entity->type = VSP1_ENTITY_UDS) {

I would move the modification of the vsp1 driver to Javier's patch that 
modifies the OMAP3 and OMAP4 drivers. Alternatively you could squash them into 
this patch, but I believe having a first patch that adds the inline function 
and a second patch that modifies all drivers to use it would be better.

> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 8b21a4d920d9..0a66fc225559 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct
> media_entity *entity) return entity->type & MEDIA_ENT_SUBTYPE_MASK;
>  }
> 
> +static inline u32 media_entity_id(struct media_entity *entity)
> +{
> +	return entity->id;
> +}
> +
>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>  #define MEDIA_ENTITY_ENUM_MAX_ID	64

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
@ 2015-08-21  0:40     ` Laurent Pinchart
  0 siblings, 0 replies; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21  0:40 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Hi Mauro,

Thank you for the patch.

On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> Instead of accessing directly entity.id, let's create a macro,
> as this field will be moved into a common struct later on.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index c55ab5029323..e429605ca2c3 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct
> media_device *mdev, u32 id) spin_lock(&mdev->lock);
> 
>  	media_device_for_each_entity(entity, mdev) {
> -		if ((entity->id == id && !next) ||
> -		    (entity->id > id && next)) {
> +		if (((media_entity_id(entity) == id) && !next) ||
> +		    ((media_entity_id(entity) > id) && next)) {
>  			spin_unlock(&mdev->lock);
>  			return entity;
>  		}
> @@ -104,7 +104,7 @@ static long media_device_enum_entities(struct
> media_device *mdev, if (ent == NULL)
>  		return -EINVAL;
> 
> -	u_ent.id = ent->id;
> +	u_ent.id = media_entity_id(ent);
>  	if (ent->name)
>  		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
>  	u_ent.type = ent->type;
> @@ -122,7 +122,7 @@ static long media_device_enum_entities(struct
> media_device *mdev, static void media_device_kpad_to_upad(const struct
> media_pad *kpad, struct media_pad_desc *upad)
>  {
> -	upad->entity = kpad->entity->id;
> +	upad->entity = media_entity_id(kpad->entity);
>  	upad->index = kpad->index;
>  	upad->flags = kpad->flags;
>  }
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 949e5f92cbdc..cb0ac4e0dfa5 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct
> media_entity_graph *graph, graph->stack[graph->top].entity = NULL;
>  	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
> 
> -	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> +	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
>  		return;
> 
> -	__set_bit(entity->id, graph->entities);
> +	__set_bit(media_entity_id(entity), graph->entities);
>  	stack_push(graph, entity);
>  }
>  EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> @@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph
> *graph)
> 
>  		/* Get the entity in the other end of the link . */
>  		next = media_entity_other(entity, link);
> -		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> +		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
>  			return NULL;
> 
>  		/* Has the entity already been visited? */
> -		if (__test_and_set_bit(next->id, graph->entities)) {
> +		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
>  			link_top(graph)++;
>  			continue;
>  		}
> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> b/drivers/media/platform/vsp1/vsp1_video.c index 17f08973f835..debe4e539df6
> 100644
> --- a/drivers/media/platform/vsp1/vsp1_video.c
> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> vsp1_pipeline *pipe, break;
> 
>  		/* Ensure the branch has no loop. */
> -		if (entities & (1 << entity->subdev.entity.id))
> +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
>  			return -EPIPE;
> 
> -		entities |= 1 << entity->subdev.entity.id;
> +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> 
>  		/* UDS can't be chained. */
>  		if (entity->type == VSP1_ENTITY_UDS) {

I would move the modification of the vsp1 driver to Javier's patch that 
modifies the OMAP3 and OMAP4 drivers. Alternatively you could squash them into 
this patch, but I believe having a first patch that adds the inline function 
and a second patch that modifies all drivers to use it would be better.

> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 8b21a4d920d9..0a66fc225559 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct
> media_entity *entity) return entity->type & MEDIA_ENT_SUBTYPE_MASK;
>  }
> 
> +static inline u32 media_entity_id(struct media_entity *entity)
> +{
> +	return entity->id;
> +}
> +
>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>  #define MEDIA_ENTITY_ENUM_MAX_ID	64

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects
  2015-08-19 11:01 ` [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
  2015-08-19 11:09   ` Hans Verkuil
@ 2015-08-21  1:02   ` Laurent Pinchart
  2015-08-21  8:07     ` Hans Verkuil
  2015-08-21  9:57     ` Mauro Carvalho Chehab
  1 sibling, 2 replies; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21  1:02 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

On Wednesday 19 August 2015 08:01:49 Mauro Carvalho Chehab wrote:
> Due to the MC API proposed changes, we'll need to have an unique
> object ID for all graph objects, and have some shared fields
> that will be common on all media graph objects.
> 
> Right now, the only common object is the object ID, but other
> fields will be added later on.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index cb0ac4e0dfa5..4834172bf6f8 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -27,6 +27,38 @@
>  #include <media/media-device.h>
> 
>  /**
> + *  media_gobj_init - Initialize a graph object
> + *
> + * @mdev:	Pointer to the media_device that contains the object
> + * @type:	Type of the object
> + * @gobj:	Pointer to the object
> + *
> + * This routine initializes the embedded struct media_gobj inside a
> + * media graph object. It is called automatically if media_*_create()
> + * calls are used. However, if the object (entity, link, pad, interface)
> + * is embedded on some other object, this function should be called before
> + * registering the object at the media controller.

Allowing both dynamic allocation and embedding will create a more complex API 
with more opportunities for drivers to get it wrong. I'd like to try and 
standardize the expected behaviour.

> + */
> +void media_gobj_init(struct media_device *mdev,
> +			   enum media_gobj_type type,
> +			   struct media_gobj *gobj)
> +{
> +	/* For now, nothing to do */
> +}
> +
> +/**
> + *  media_gobj_remove - Stop using a graph object on a media device

Is this function supposed to be the counterpart of media_gobj_init ? If so it 
should be called media_gobj_cleanup instead.

> + *
> + * @graph_obj:	Pointer to the object

The parameter is called gobj. Could you compile the kerneldoc to ensure that 
such typos get caught ?

> + *
> + * This should be called at media_device_unregister_*() routines
> + */
> +void media_gobj_remove(struct media_gobj *gobj)
> +{
> +	/* For now, nothing to do */
> +}
> +
> +/**
>   * media_entity_init - Initialize a media entity
>   *
>   * @num_pads: Total number of sink and source pads.
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index 0a66fc225559..c1cd4fba051d 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -28,6 +28,39 @@
>  #include <linux/list.h>
>  #include <linux/media.h>
> 
> +/* Enums used internally at the media controller to represent graphs */
> +
> +/**
> + * enum media_gobj_type - type of a graph element

Let's try to standardize the vocabulary, should it be called graph object or 
graph element ? In the first case let's document it as graph object. In the 
second case it would be more consistent to refer to it as enum 
media_gelem_type (and struct media_gelem below).

> + *
> + */
> +enum media_gobj_type {
> +	 /* FIXME: add the types here, as we embed media_gobj */
> +	MEDIA_GRAPH_NONE
> +};
> +
> +#define MEDIA_BITS_PER_TYPE		8
> +#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
> +#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
> +
> +/* Structs to represent the objects that belong to a media graph */
> +
> +/**
> + * struct media_gobj - Define a graph object.
> + *
> + * @id:		Non-zero object ID identifier. The ID should be unique
> + *		inside a media_device, as it is composed by
> + *		MEDIA_BITS_PER_TYPE to store the type plus
> + *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
> + *		(called as "local ID").

I'd very much prefer using a single ID range and adding a type field. Abusing 
bits of the ID field to store the type will just makes IDs impractical to use. 
Let's do it properly.

> + * All elements on the media graph should have this struct embedded

All elements (objects) or only the ones that need an ID ? Or maybe we'll 
define graph element (object) as an element (object) that has an ID, making 
some "elements" not elements.

> + */
> +struct media_gobj {
> +	u32			id;
> +};
> +
> +
>  struct media_pipeline {
>  };
> 
> @@ -118,6 +151,26 @@ static inline u32 media_entity_id(struct media_entity
> *entity) return entity->id;
>  }
> 
> +static inline enum media_gobj_type media_type(struct media_gobj *gobj)
> +{
> +	return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
> +}
> +
> +static inline u32 media_localid(struct media_gobj *gobj)
> +{
> +	return gobj->id & MEDIA_LOCAL_ID_MASK;
> +}
> +
> +static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32
> local_id)
> +{
> +	u32 id;
> +
> +	id = type << MEDIA_BITS_PER_LOCAL_ID;
> +	id |= local_id & MEDIA_LOCAL_ID_MASK;
> +
> +	return id;
> +}
> +
>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>  #define MEDIA_ENTITY_ENUM_MAX_ID	64
> 
> @@ -131,6 +184,14 @@ struct media_entity_graph {
>  	int top;
>  };
> 
> +#define gobj_to_entity(gobj) \
> +		container_of(gobj, struct media_entity, graph_obj)

For consistency reason would this be called media_gobj_to_entity ? I would 
also turn it into an inline function to ensure type checking.

> +
> +void media_gobj_init(struct media_device *mdev,
> +		    enum media_gobj_type type,
> +		    struct media_gobj *gobj);
> +void media_gobj_remove(struct media_gobj *gobj);
> +
>  int media_entity_init(struct media_entity *entity, u16 num_pads,
>  		struct media_pad *pads);
>  void media_entity_cleanup(struct media_entity *entity);

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 3/8] [media] media: use media_gobj inside entities
  2015-08-19 11:01 ` [PATCH v6 3/8] [media] media: use media_gobj inside entities Mauro Carvalho Chehab
@ 2015-08-21  1:10   ` Laurent Pinchart
  2015-08-21 10:09     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21  1:10 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

On Wednesday 19 August 2015 08:01:50 Mauro Carvalho Chehab wrote:
> As entities are graph elements, 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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index e429605ca2c3..81d6a130efef 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -379,7 +379,6 @@ int __must_check __media_device_register(struct
> media_device *mdev, if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
>  		return -EINVAL;
> 
> -	mdev->entity_id = 1;
>  	INIT_LIST_HEAD(&mdev->entities);
>  	spin_lock_init(&mdev->lock);
>  	mutex_init(&mdev->graph_mutex);
> @@ -433,10 +432,8 @@ int __must_check media_device_register_entity(struct
> media_device *mdev, entity->parent = mdev;
> 
>  	spin_lock(&mdev->lock);
> -	if (entity->id == 0)
> -		entity->id = mdev->entity_id++;
> -	else
> -		mdev->entity_id = max(entity->id + 1, mdev->entity_id);
> +	/* Initialize media_gobj embedded at the entity */
> +	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);

Graph object initialization should be moved to media_entity_init() to keep 
initialization separate from registration.

>  	list_add_tail(&entity->list, &mdev->entities);
>  	spin_unlock(&mdev->lock);
> 
> @@ -459,6 +456,7 @@ void media_device_unregister_entity(struct media_entity
> *entity) return;
> 
>  	spin_lock(&mdev->lock);
> +	media_gobj_remove(&entity->graph_obj);
>  	list_del(&entity->list);
>  	spin_unlock(&mdev->lock);
>  	entity->parent = NULL;
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 4834172bf6f8..888cb88e19bf 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -43,7 +43,12 @@ void media_gobj_init(struct media_device *mdev,
>  			   enum media_gobj_type type,
>  			   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;
> +	}
>  }
> 
>  /**
> diff --git a/include/media/media-device.h b/include/media/media-device.h
> index a44f18fdf321..f6deef6e5820 100644
> --- a/include/media/media-device.h
> +++ b/include/media/media-device.h
> @@ -41,7 +41,7 @@ struct device;
>   * @bus_info:	Unique and stable device location identifier
>   * @hw_revision: Hardware device revision
>   * @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
>   * @lock:	Entities list lock
>   * @graph_mutex: Entities graph operation lock
> @@ -69,6 +69,7 @@ struct media_device {
>  	u32 driver_version;
> 
>  	u32 entity_id;
> +
>  	struct list_head entities;
> 
>  	/* Protects the entities list */
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index c1cd4fba051d..9ca366334bcf 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -33,10 +33,10 @@
>  /**
>   * enum media_gobj_type - type of a graph element
>   *
> + * @MEDIA_GRAPH_ENTITY:		Identify a media entity

I think we should explicitly define here what an entity is.

>   */
>  enum media_gobj_type {
> -	 /* FIXME: add the types here, as we embed media_gobj */
> -	MEDIA_GRAPH_NONE
> +	MEDIA_GRAPH_ENTITY,
>  };
> 
>  #define MEDIA_BITS_PER_TYPE		8
> @@ -94,10 +94,9 @@ struct media_entity_operations {
>  };
> 
>  struct media_entity {
> +	struct media_gobj graph_obj;
>  	struct list_head list;
>  	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 */
>  	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
>  	u32 revision;			/* Entity revision, driver specific */
> @@ -148,7 +147,7 @@ static inline u32 media_entity_subtype(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)

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-19 11:01 ` [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal Mauro Carvalho Chehab
  2015-08-19 11:12   ` Hans Verkuil
@ 2015-08-21  1:32   ` Laurent Pinchart
  2015-08-21 10:19     ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21  1:32 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

On Wednesday 19 August 2015 08:01:54 Mauro Carvalho Chehab wrote:
> 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.

CONFIG_DYNAMIC_DEBUG is often enabled.

You're more or less adding function call tracing in this patch, isn't that 
something that ftrace is supposed to do ?

> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> index 36d725ec5f3d..6d515e149d7f 100644
> --- a/drivers/media/media-entity.c
> +++ b/drivers/media/media-entity.c
> @@ -27,6 +27,69 @@
>  #include <media/media-device.h>
> 
>  /**
> + *  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 749b46c91217..bdd5e565ae76 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -61,6 +61,7 @@ enum media_gobj_type {
>   * All elements on the media graph should have this struct embedded
>   */
>  struct media_gobj {
> +	struct media_device	*mdev;

I'd move this to the patch that introduces media_gobj.

>  	u32			id;
>  };
> 
> @@ -192,6 +193,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)
> +

And I'd call these media_gobj_* as commented on patch 2/8.

>  void media_gobj_init(struct media_device *mdev,
>  		    enum media_gobj_type type,
>  		    struct media_gobj *gobj);

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered
  2015-08-19 11:01 ` [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered Mauro Carvalho Chehab
  2015-08-19 11:11   ` Hans Verkuil
@ 2015-08-21  1:35   ` Laurent Pinchart
  2015-08-21 10:25     ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21  1:35 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

On Wednesday 19 August 2015 08:01:53 Mauro Carvalho Chehab wrote:
> We can only free the media device after being sure that no
> graph object is used.

media_device_release() is currently broken as it should call back to the 
driver that has allocated the media_device() structure. I think we should fix 
that before adding more code on top of the problem.

> In order to help tracking it, let's add debug messages
> that will print when the media controller gets registered
> or unregistered.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index 065f6f08da37..0f3844470147 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -359,6 +359,7 @@ static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
> 
>  static void media_device_release(struct media_devnode *mdev)
>  {
> +	dev_dbg(mdev->parent, "Media device released\n");

As commented on patch 7/8, ftrace is a better candidate for function tracing.

>  }
> 
>  /**
> @@ -397,6 +398,8 @@ int __must_check __media_device_register(struct
> media_device *mdev, return ret;
>  	}
> 
> +	dev_dbg(mdev->dev, "Media device registered\n");
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(__media_device_register);
> @@ -416,6 +419,8 @@ void media_device_unregister(struct media_device *mdev)
> 
>  	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
>  	media_devnode_unregister(&mdev->devnode);
> +
> +	dev_dbg(mdev->dev, "Media device unregistered\n");
>  }
>  EXPORT_SYMBOL_GPL(media_device_unregister);

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects
  2015-08-21  1:02   ` Laurent Pinchart
@ 2015-08-21  8:07     ` Hans Verkuil
  2015-09-07 21:49       ` Laurent Pinchart
  2015-08-21  9:57     ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 48+ messages in thread
From: Hans Verkuil @ 2015-08-21  8:07 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab

On 08/21/2015 03:02 AM, Laurent Pinchart wrote:
> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Wednesday 19 August 2015 08:01:49 Mauro Carvalho Chehab wrote:
>> +/* Enums used internally at the media controller to represent graphs */
>> +
>> +/**
>> + * enum media_gobj_type - type of a graph element
> 
> Let's try to standardize the vocabulary, should it be called graph object or 
> graph element ? In the first case let's document it as graph object. In the 
> second case it would be more consistent to refer to it as enum 
> media_gelem_type (and struct media_gelem below).

For what it is worth, I prefer the term graph object.

> 
>> + *
>> + */
>> +enum media_gobj_type {
>> +	 /* FIXME: add the types here, as we embed media_gobj */
>> +	MEDIA_GRAPH_NONE
>> +};
>> +
>> +#define MEDIA_BITS_PER_TYPE		8
>> +#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
>> +#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
>> +
>> +/* Structs to represent the objects that belong to a media graph */
>> +
>> +/**
>> + * struct media_gobj - Define a graph object.
>> + *
>> + * @id:		Non-zero object ID identifier. The ID should be unique
>> + *		inside a media_device, as it is composed by
>> + *		MEDIA_BITS_PER_TYPE to store the type plus
>> + *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
>> + *		(called as "local ID").
> 
> I'd very much prefer using a single ID range and adding a type field. Abusing 
> bits of the ID field to store the type will just makes IDs impractical to use. 
> Let's do it properly.

Why is that impractical? I think it is more practical. Why waste memory on something
that is easy to encode in the ID?

I'm not necessarily opposed to splitting this up (Mauro's initial patch series used
a separate type field if I remember correctly), but it's not clear to me what the
benefits are. Keeping it in a single u32 makes describing links also very easy since
you just give it the two objects that are linked and it is immediately clear which
object types are linked: no need to either store the types in the link struct or
look up each object to find the type.

> 
>> + * All elements on the media graph should have this struct embedded
> 
> All elements (objects) or only the ones that need an ID ? Or maybe we'll 
> define graph element (object) as an element (object) that has an ID, making 
> some "elements" not elements.

Yes, all objects have an ID. I see no reason to special-case this.

You wrote this at 3 am, so you were probably sleep-deprived when you wrote the
second sentence as I can't wrap my head around that one :-)

> 
>> + */
>> +struct media_gobj {
>> +	u32			id;
>> +};
>> +
>> +
>>  struct media_pipeline {
>>  };
>>
>> @@ -118,6 +151,26 @@ static inline u32 media_entity_id(struct media_entity
>> *entity) return entity->id;
>>  }
>>
>> +static inline enum media_gobj_type media_type(struct media_gobj *gobj)
>> +{
>> +	return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
>> +}
>> +
>> +static inline u32 media_localid(struct media_gobj *gobj)
>> +{
>> +	return gobj->id & MEDIA_LOCAL_ID_MASK;
>> +}
>> +
>> +static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32
>> local_id)
>> +{
>> +	u32 id;
>> +
>> +	id = type << MEDIA_BITS_PER_LOCAL_ID;
>> +	id |= local_id & MEDIA_LOCAL_ID_MASK;
>> +
>> +	return id;
>> +}
>> +
>>  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
>>  #define MEDIA_ENTITY_ENUM_MAX_ID	64
>>
>> @@ -131,6 +184,14 @@ struct media_entity_graph {
>>  	int top;
>>  };
>>
>> +#define gobj_to_entity(gobj) \
>> +		container_of(gobj, struct media_entity, graph_obj)
> 
> For consistency reason would this be called media_gobj_to_entity ? I would 
> also turn it into an inline function to ensure type checking.

Good one. I agree.

> 
>> +
>> +void media_gobj_init(struct media_device *mdev,
>> +		    enum media_gobj_type type,
>> +		    struct media_gobj *gobj);
>> +void media_gobj_remove(struct media_gobj *gobj);
>> +
>>  int media_entity_init(struct media_entity *entity, u16 num_pads,
>>  		struct media_pad *pads);
>>  void media_entity_cleanup(struct media_entity *entity);
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
  2015-08-21  0:40     ` Laurent Pinchart
@ 2015-08-21  8:42       ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21  8:42 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Em Fri, 21 Aug 2015 03:40:48 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> > Instead of accessing directly entity.id, let's create a macro,
> > as this field will be moved into a common struct later on.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index c55ab5029323..e429605ca2c3 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct
> > media_device *mdev, u32 id) spin_lock(&mdev->lock);
> > 
> >  	media_device_for_each_entity(entity, mdev) {
> > -		if ((entity->id = id && !next) ||
> > -		    (entity->id > id && next)) {
> > +		if (((media_entity_id(entity) = id) && !next) ||
> > +		    ((media_entity_id(entity) > id) && next)) {
> >  			spin_unlock(&mdev->lock);
> >  			return entity;
> >  		}
> > @@ -104,7 +104,7 @@ static long media_device_enum_entities(struct
> > media_device *mdev, if (ent = NULL)
> >  		return -EINVAL;
> > 
> > -	u_ent.id = ent->id;
> > +	u_ent.id = media_entity_id(ent);
> >  	if (ent->name)
> >  		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
> >  	u_ent.type = ent->type;
> > @@ -122,7 +122,7 @@ static long media_device_enum_entities(struct
> > media_device *mdev, static void media_device_kpad_to_upad(const struct
> > media_pad *kpad, struct media_pad_desc *upad)
> >  {
> > -	upad->entity = kpad->entity->id;
> > +	upad->entity = media_entity_id(kpad->entity);
> >  	upad->index = kpad->index;
> >  	upad->flags = kpad->flags;
> >  }
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index 949e5f92cbdc..cb0ac4e0dfa5 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct
> > media_entity_graph *graph, graph->stack[graph->top].entity = NULL;
> >  	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
> > 
> > -	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> > +	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
> >  		return;
> > 
> > -	__set_bit(entity->id, graph->entities);
> > +	__set_bit(media_entity_id(entity), graph->entities);
> >  	stack_push(graph, entity);
> >  }
> >  EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> > @@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph
> > *graph)
> > 
> >  		/* Get the entity in the other end of the link . */
> >  		next = media_entity_other(entity, link);
> > -		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> > +		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
> >  			return NULL;
> > 
> >  		/* Has the entity already been visited? */
> > -		if (__test_and_set_bit(next->id, graph->entities)) {
> > +		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
> >  			link_top(graph)++;
> >  			continue;
> >  		}
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > b/drivers/media/platform/vsp1/vsp1_video.c index 17f08973f835..debe4e539df6
> > 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> > vsp1_pipeline *pipe, break;
> > 
> >  		/* Ensure the branch has no loop. */
> > -		if (entities & (1 << entity->subdev.entity.id))
> > +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
> >  			return -EPIPE;
> > 
> > -		entities |= 1 << entity->subdev.entity.id;
> > +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> > 
> >  		/* UDS can't be chained. */
> >  		if (entity->type = VSP1_ENTITY_UDS) {
> 
> I would move the modification of the vsp1 driver to Javier's patch that 
> modifies the OMAP3 and OMAP4 drivers. Alternatively you could squash them into 
> this patch, but I believe having a first patch that adds the inline function 
> and a second patch that modifies all drivers to use it would be better.

Squashing will lose Javier's authorship. I guess the better is have a 
first patch with the inline, then my paches and Javier's ones, and 
latter on the patch removing entity->id. 

I'll do that on the next patch series.

> 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 8b21a4d920d9..0a66fc225559 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct
> > media_entity *entity) return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> >  }
> > 
> > +static inline u32 media_entity_id(struct media_entity *entity)
> > +{
> > +	return entity->id;
> > +}
> > +
> >  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
> >  #define MEDIA_ENTITY_ENUM_MAX_ID	64
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
@ 2015-08-21  8:42       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21  8:42 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Em Fri, 21 Aug 2015 03:40:48 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> > Instead of accessing directly entity.id, let's create a macro,
> > as this field will be moved into a common struct later on.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index c55ab5029323..e429605ca2c3 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -77,8 +77,8 @@ static struct media_entity *find_entity(struct
> > media_device *mdev, u32 id) spin_lock(&mdev->lock);
> > 
> >  	media_device_for_each_entity(entity, mdev) {
> > -		if ((entity->id == id && !next) ||
> > -		    (entity->id > id && next)) {
> > +		if (((media_entity_id(entity) == id) && !next) ||
> > +		    ((media_entity_id(entity) > id) && next)) {
> >  			spin_unlock(&mdev->lock);
> >  			return entity;
> >  		}
> > @@ -104,7 +104,7 @@ static long media_device_enum_entities(struct
> > media_device *mdev, if (ent == NULL)
> >  		return -EINVAL;
> > 
> > -	u_ent.id = ent->id;
> > +	u_ent.id = media_entity_id(ent);
> >  	if (ent->name)
> >  		strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
> >  	u_ent.type = ent->type;
> > @@ -122,7 +122,7 @@ static long media_device_enum_entities(struct
> > media_device *mdev, static void media_device_kpad_to_upad(const struct
> > media_pad *kpad, struct media_pad_desc *upad)
> >  {
> > -	upad->entity = kpad->entity->id;
> > +	upad->entity = media_entity_id(kpad->entity);
> >  	upad->index = kpad->index;
> >  	upad->flags = kpad->flags;
> >  }
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index 949e5f92cbdc..cb0ac4e0dfa5 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -140,10 +140,10 @@ void media_entity_graph_walk_start(struct
> > media_entity_graph *graph, graph->stack[graph->top].entity = NULL;
> >  	bitmap_zero(graph->entities, MEDIA_ENTITY_ENUM_MAX_ID);
> > 
> > -	if (WARN_ON(entity->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> > +	if (WARN_ON(media_entity_id(entity) >= MEDIA_ENTITY_ENUM_MAX_ID))
> >  		return;
> > 
> > -	__set_bit(entity->id, graph->entities);
> > +	__set_bit(media_entity_id(entity), graph->entities);
> >  	stack_push(graph, entity);
> >  }
> >  EXPORT_SYMBOL_GPL(media_entity_graph_walk_start);
> > @@ -184,11 +184,11 @@ media_entity_graph_walk_next(struct media_entity_graph
> > *graph)
> > 
> >  		/* Get the entity in the other end of the link . */
> >  		next = media_entity_other(entity, link);
> > -		if (WARN_ON(next->id >= MEDIA_ENTITY_ENUM_MAX_ID))
> > +		if (WARN_ON(media_entity_id(next) >= MEDIA_ENTITY_ENUM_MAX_ID))
> >  			return NULL;
> > 
> >  		/* Has the entity already been visited? */
> > -		if (__test_and_set_bit(next->id, graph->entities)) {
> > +		if (__test_and_set_bit(media_entity_id(next), graph->entities)) {
> >  			link_top(graph)++;
> >  			continue;
> >  		}
> > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > b/drivers/media/platform/vsp1/vsp1_video.c index 17f08973f835..debe4e539df6
> > 100644
> > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> > vsp1_pipeline *pipe, break;
> > 
> >  		/* Ensure the branch has no loop. */
> > -		if (entities & (1 << entity->subdev.entity.id))
> > +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
> >  			return -EPIPE;
> > 
> > -		entities |= 1 << entity->subdev.entity.id;
> > +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> > 
> >  		/* UDS can't be chained. */
> >  		if (entity->type == VSP1_ENTITY_UDS) {
> 
> I would move the modification of the vsp1 driver to Javier's patch that 
> modifies the OMAP3 and OMAP4 drivers. Alternatively you could squash them into 
> this patch, but I believe having a first patch that adds the inline function 
> and a second patch that modifies all drivers to use it would be better.

Squashing will lose Javier's authorship. I guess the better is have a 
first patch with the inline, then my paches and Javier's ones, and 
latter on the patch removing entity->id. 

I'll do that on the next patch series.

> 
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 8b21a4d920d9..0a66fc225559 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct
> > media_entity *entity) return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> >  }
> > 
> > +static inline u32 media_entity_id(struct media_entity *entity)
> > +{
> > +	return entity->id;
> > +}
> > +
> >  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
> >  #define MEDIA_ENTITY_ENUM_MAX_ID	64
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects
  2015-08-21  1:02   ` Laurent Pinchart
  2015-08-21  8:07     ` Hans Verkuil
@ 2015-08-21  9:57     ` Mauro Carvalho Chehab
  1 sibling, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21  9:57 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Fri, 21 Aug 2015 04:02:57 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Wednesday 19 August 2015 08:01:49 Mauro Carvalho Chehab wrote:
> > Due to the MC API proposed changes, we'll need to have an unique
> > object ID for all graph objects, and have some shared fields
> > that will be common on all media graph objects.
> > 
> > Right now, the only common object is the object ID, but other
> > fields will be added later on.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index cb0ac4e0dfa5..4834172bf6f8 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -27,6 +27,38 @@
> >  #include <media/media-device.h>
> > 
> >  /**
> > + *  media_gobj_init - Initialize a graph object
> > + *
> > + * @mdev:	Pointer to the media_device that contains the object
> > + * @type:	Type of the object
> > + * @gobj:	Pointer to the object
> > + *
> > + * This routine initializes the embedded struct media_gobj inside a
> > + * media graph object. It is called automatically if media_*_create()
> > + * calls are used. However, if the object (entity, link, pad, interface)
> > + * is embedded on some other object, this function should be called before
> > + * registering the object at the media controller.

Actually, the comment here is a little bit outdated, from the time I was
adding a kref inside the graph_obj. That's by the way one of the problems
with patches that suffer lots of transforms: comments may need to be
adjusted to reflect what changed, but tracking such changes is harder.

The comment above should be, instead:

 * This routine initializes the embedded struct media_gobj inside a
 * media graph object. It is called automatically at media_*_create()
 * and at media_entity_register().

> Allowing both dynamic allocation and embedding will create a more complex API 
> with more opportunities for drivers to get it wrong. I'd like to try and 
> standardize the expected behaviour.

Let's discuss dynamic allocation when we come with the patches. For
now, if media_obj_init is not called, objects won't have an unique
ID and will cause an OOPS if debug is enabled, with is easily tracked.

> 
> > + */
> > +void media_gobj_init(struct media_device *mdev,
> > +			   enum media_gobj_type type,
> > +			   struct media_gobj *gobj)
> > +{
> > +	/* For now, nothing to do */
> > +}
> > +
> > +/**
> > + *  media_gobj_remove - Stop using a graph object on a media device
> 
> Is this function supposed to be the counterpart of media_gobj_init ? If so it 
> should be called media_gobj_cleanup instead.

*_cleanup doesn't mean anything for me. The usual Kernel way is to use either
*_init and *_remove or *_register/*_remove for a kernel "object"
creation/removal.

If you prefer, I could rename the first function to media_gobj_register.

> 
> > + *
> > + * @graph_obj:	Pointer to the object
> 
> The parameter is called gobj. Could you compile the kerneldoc to ensure that 
> such typos get caught ?

I will fix at a next version and compile kerneldoc.

> 
> > + *
> > + * This should be called at media_device_unregister_*() routines
> > + */
> > +void media_gobj_remove(struct media_gobj *gobj)
> > +{
> > +	/* For now, nothing to do */
> > +}
> > +
> > +/**
> >   * media_entity_init - Initialize a media entity
> >   *
> >   * @num_pads: Total number of sink and source pads.
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index 0a66fc225559..c1cd4fba051d 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -28,6 +28,39 @@
> >  #include <linux/list.h>
> >  #include <linux/media.h>
> > 
> > +/* Enums used internally at the media controller to represent graphs */
> > +
> > +/**
> > + * enum media_gobj_type - type of a graph element
> 
> Let's try to standardize the vocabulary, should it be called graph object or 
> graph element ? In the first case let's document it as graph object. In the 
> second case it would be more consistent to refer to it as enum 
> media_gelem_type (and struct media_gelem below).

graph object. Thanks for noticing it. I'll fix.

> 
> > + *
> > + */
> > +enum media_gobj_type {
> > +	 /* FIXME: add the types here, as we embed media_gobj */
> > +	MEDIA_GRAPH_NONE
> > +};
> > +
> > +#define MEDIA_BITS_PER_TYPE		8
> > +#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
> > +#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 0)
> > +
> > +/* Structs to represent the objects that belong to a media graph */
> > +
> > +/**
> > + * struct media_gobj - Define a graph object.
> > + *
> > + * @id:		Non-zero object ID identifier. The ID should be unique
> > + *		inside a media_device, as it is composed by
> > + *		MEDIA_BITS_PER_TYPE to store the type plus
> > + *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
> > + *		(called as "local ID").
> 
> I'd very much prefer using a single ID range and adding a type field. Abusing 
> bits of the ID field to store the type will just makes IDs impractical to use. 
> Let's do it properly.

This came actually from the feedback I got on the first RFC, but
it is not possible to use a singe ID range. We can, of course
have a separate type, but we need at least two ID ranges.

Otherwise, both Kernelspace and userspace will break.

At least on my tests, the media-ctl implementation is very sensitive to
the way the things are currently implemented on Kernel, and even small
changes like reporting a backlink or changing the initial object ID to
0 causes it to crash or fail. I suspect that other userspace apps
could be even worse.

Also, as I pointed before, the graph traversal algorithm wants that
the entity number to be below 64 (MEDIA_ENTITY_ENUM_MAX_ID) and 
similar mechanisms inside drivers at have even lower constraints for
the entity range: no entity can have an ID bigger than 32.

While removing such restrictions at Kernespace is doable, this is out
of the scope of this work, and would require changes/testing on
hardware that could otherwise work forever keeping the entity range
below 32.

That means, in practice, that the first driver that will use dynamic
entity addition and removal and need to call the graph_traversal routines
at the MC core will have to come up with a different graph traversal
algorithm.

So, the question is either if we'll have 2 ranges (one for entities and
another one for the other types) or one range per type.

On the first case, we'll be using something like:
	ID range from 0x000000000000 to 0x7fffffffffff - entities
	ID range from 0x800000000000 to 0xffffffffffff - other elements

And split that "global_id" field into two separate fields, as I
proposed on my initial patch series:
	struct media_gobj {
		u32 id;
		enum media_gobj_type type;
	}


While I'm ok with that, it has some drawbacks:

1) if we remove the concept of type+id together, the IDs on userspace
will not be "human-friendly", as Sakari requested on his feedback (or it
would require some messy hacks). 
With the current proposal, if one would like to change something at a pad,
instead of using an object ID like: 
	0x010000000004
It could, instead, use:
	pad#4

2) What would be the name of the var that would carry on the non-entities
ID? I guess the internal API namespace will be a little messier. Should
we call it:
	mdev.entity_id
	mdev.non_entity_id
Or do you have another suggestion for the namespace thing?

3) At debug/tracing logs, it is easier for humans to identify something
called "pad#4" than 0x010000000004.

So, at least while we're debugging the patches, I'll keep the ranges 
separate.

If we decide to do it otherwise, I'll add a patch near the end of the MC
next generation patches to change the range ID to whatever gets decided.

> 
> > + * All elements on the media graph should have this struct embedded
> 
> All elements (objects) or only the ones that need an ID ? Or maybe we'll 
> define graph element (object) as an element (object) that has an ID, making 
> some "elements" not elements.

The idea is to have the common struct embedded on all objects, containing
the object type, and other common data.

A common struct is very useful for debugging purposes, for notification
purposes, etc, as from the object struct is possible to go to the main
object. It will also be important when we'll need dynamic support.

All objects need a type. If we split the ID, we might move the
ID out of the struct if we ever need an ID-less object, but, I think that
an ID-less object is a terrible idea, as it makes a way harder to track
the object lifecycle when debugging the code, and objects will then
be only referenced internally via pointers.

See, with an object ID for the links, any debug messages can contain the ID,
like:
	media_gobj_init: id 0x02000002 link#2: 'Xceive XC5000' pad#4 ==> 'Auvitek AU8522 QAM/8VSB Frontend' pad#7

If I need, for example, to check if the ioctl's are properly reporting
such link to userspace, all I would need to do is to print the
link "name":
		link#2

as this is a good enough reference for the object (and yes, I had do do
something exactly like that yesterday).

With a combined id+type, there's no penalty of having an ID for all
objects. If we split into id + type, we'll "waste" just 4 bytes, with
seems a low price to pay to avoid the waste of time when debugging the
object lifecycle.

> 
> > + */
> > +struct media_gobj {
> > +	u32			id;
> > +};
> > +
> > +
> >  struct media_pipeline {
> >  };
> > 
> > @@ -118,6 +151,26 @@ static inline u32 media_entity_id(struct media_entity
> > *entity) return entity->id;
> >  }
> > 
> > +static inline enum media_gobj_type media_type(struct media_gobj *gobj)
> > +{
> > +	return gobj->id >> MEDIA_BITS_PER_LOCAL_ID;
> > +}
> > +
> > +static inline u32 media_localid(struct media_gobj *gobj)
> > +{
> > +	return gobj->id & MEDIA_LOCAL_ID_MASK;
> > +}
> > +
> > +static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32
> > local_id)
> > +{
> > +	u32 id;
> > +
> > +	id = type << MEDIA_BITS_PER_LOCAL_ID;
> > +	id |= local_id & MEDIA_LOCAL_ID_MASK;
> > +
> > +	return id;
> > +}
> > +
> >  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
> >  #define MEDIA_ENTITY_ENUM_MAX_ID	64
> > 
> > @@ -131,6 +184,14 @@ struct media_entity_graph {
> >  	int top;
> >  };
> > 
> > +#define gobj_to_entity(gobj) \
> > +		container_of(gobj, struct media_entity, graph_obj)
> 
> For consistency reason would this be called media_gobj_to_entity ? 

I would avoid having a big name for those containers macros.

Also, the usual Kernel practice is to use exactly the same type of
declaration like above:

#define <object>_to_<object>(foo) \
		container_of(foo, ...)

> I would 
> also turn it into an inline function to ensure type checking.

container_of() already provides type checking. So, I don't see any
gain of inlining it.

> 
> > +
> > +void media_gobj_init(struct media_device *mdev,
> > +		    enum media_gobj_type type,
> > +		    struct media_gobj *gobj);
> > +void media_gobj_remove(struct media_gobj *gobj);
> > +
> >  int media_entity_init(struct media_entity *entity, u16 num_pads,
> >  		struct media_pad *pads);
> >  void media_entity_cleanup(struct media_entity *entity);
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 3/8] [media] media: use media_gobj inside entities
  2015-08-21  1:10   ` Laurent Pinchart
@ 2015-08-21 10:09     ` Mauro Carvalho Chehab
  2015-08-21 17:51       ` Laurent Pinchart
  0 siblings, 1 reply; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 10:09 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Fri, 21 Aug 2015 04:10:03 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Wednesday 19 August 2015 08:01:50 Mauro Carvalho Chehab wrote:
> > As entities are graph elements, 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.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index e429605ca2c3..81d6a130efef 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -379,7 +379,6 @@ int __must_check __media_device_register(struct
> > media_device *mdev, if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
> >  		return -EINVAL;
> > 
> > -	mdev->entity_id = 1;
> >  	INIT_LIST_HEAD(&mdev->entities);
> >  	spin_lock_init(&mdev->lock);
> >  	mutex_init(&mdev->graph_mutex);
> > @@ -433,10 +432,8 @@ int __must_check media_device_register_entity(struct
> > media_device *mdev, entity->parent = mdev;
> > 
> >  	spin_lock(&mdev->lock);
> > -	if (entity->id == 0)
> > -		entity->id = mdev->entity_id++;
> > -	else
> > -		mdev->entity_id = max(entity->id + 1, mdev->entity_id);
> > +	/* Initialize media_gobj embedded at the entity */
> > +	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> 
> Graph object initialization should be moved to media_entity_init() to keep 
> initialization separate from registration.

Won't work. I tried. My first RFC patches were doing that.

The problem is that media_entity_init() is currently called too early
at the V4L2 drivers, before having mdev assigned.

Also, objects without PADs don't call media_entity_init(). At long
term, this function may even disappear, as it only exists today to
allocate arrays for pads/links. If we get rid of the pads array, it
will make no sense to keep it.

> >  	list_add_tail(&entity->list, &mdev->entities);
> >  	spin_unlock(&mdev->lock);
> > 
> > @@ -459,6 +456,7 @@ void media_device_unregister_entity(struct media_entity
> > *entity) return;
> > 
> >  	spin_lock(&mdev->lock);
> > +	media_gobj_remove(&entity->graph_obj);
> >  	list_del(&entity->list);
> >  	spin_unlock(&mdev->lock);
> >  	entity->parent = NULL;
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index 4834172bf6f8..888cb88e19bf 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -43,7 +43,12 @@ void media_gobj_init(struct media_device *mdev,
> >  			   enum media_gobj_type type,
> >  			   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;
> > +	}
> >  }
> > 
> >  /**
> > diff --git a/include/media/media-device.h b/include/media/media-device.h
> > index a44f18fdf321..f6deef6e5820 100644
> > --- a/include/media/media-device.h
> > +++ b/include/media/media-device.h
> > @@ -41,7 +41,7 @@ struct device;
> >   * @bus_info:	Unique and stable device location identifier
> >   * @hw_revision: Hardware device revision
> >   * @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
> >   * @lock:	Entities list lock
> >   * @graph_mutex: Entities graph operation lock
> > @@ -69,6 +69,7 @@ struct media_device {
> >  	u32 driver_version;
> > 
> >  	u32 entity_id;
> > +
> >  	struct list_head entities;
> > 
> >  	/* Protects the entities list */
> > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > index c1cd4fba051d..9ca366334bcf 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -33,10 +33,10 @@
> >  /**
> >   * enum media_gobj_type - type of a graph element
> >   *
> > + * @MEDIA_GRAPH_ENTITY:		Identify a media entity
> 
> I think we should explicitly define here what an entity is.

I'm happy to add a new text here if you have a better idea.

Anyway, for now, I'm more concerned on getting things done than to spend
lots of time with the comments. As pointed on patch 1/8, while we're
changing a lot the code, those comments tend to become obsolete very
quick. The comments there is more like a boilerplate, as, once we finish
touching at the core,  it makes sense to review the comments at media *.h
files, converting all descriptions to kernel-doc-nano format (there are
several not using it) and review Documentation/media-framework.txt, adding
the missing parts.

> 
> >   */
> >  enum media_gobj_type {
> > -	 /* FIXME: add the types here, as we embed media_gobj */
> > -	MEDIA_GRAPH_NONE
> > +	MEDIA_GRAPH_ENTITY,
> >  };
> > 
> >  #define MEDIA_BITS_PER_TYPE		8
> > @@ -94,10 +94,9 @@ struct media_entity_operations {
> >  };
> > 
> >  struct media_entity {
> > +	struct media_gobj graph_obj;
> >  	struct list_head list;
> >  	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 */
> >  	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
> >  	u32 revision;			/* Entity revision, driver specific */
> > @@ -148,7 +147,7 @@ static inline u32 media_entity_subtype(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)
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-21  1:32   ` Laurent Pinchart
@ 2015-08-21 10:19     ` Mauro Carvalho Chehab
  2015-08-21 17:54       ` Laurent Pinchart
  0 siblings, 1 reply; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 10:19 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Fri, 21 Aug 2015 04:32:51 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Wednesday 19 August 2015 08:01:54 Mauro Carvalho Chehab wrote:
> > 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.
> 
> CONFIG_DYNAMIC_DEBUG is often enabled.

True, but once a driver/core is properly debugged, images without DEBUG
could be used in production, if the amount of memory constraints are
too tight.

> You're more or less adding function call tracing in this patch, isn't that 
> something that ftrace is supposed to do ?

Ftrace is a great infrastructure and helps a lot when we need to
identify bottlenecks and other performance related stuff, but it
doesn't replace debug functions.

There are some fundamental differences on what you could do with ftrace
and what you can't.

At least on this stage, what I need is something that will provide
output via serial console when the driver gets loaded, and that provides
a synchronous output with the other Kernel messages.

This is the only way to debug certain OOPSes that are happening during
the development of the patches.

This is something you cannot do with ftrace, but dynamic DEBUG works
like a charm.

> 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > index 36d725ec5f3d..6d515e149d7f 100644
> > --- a/drivers/media/media-entity.c
> > +++ b/drivers/media/media-entity.c
> > @@ -27,6 +27,69 @@
> >  #include <media/media-device.h>
> > 
> >  /**
> > + *  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 749b46c91217..bdd5e565ae76 100644
> > --- a/include/media/media-entity.h
> > +++ b/include/media/media-entity.h
> > @@ -61,6 +61,7 @@ enum media_gobj_type {
> >   * All elements on the media graph should have this struct embedded
> >   */
> >  struct media_gobj {
> > +	struct media_device	*mdev;
> 
> I'd move this to the patch that introduces media_gobj.
> 
> >  	u32			id;
> >  };
> > 
> > @@ -192,6 +193,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)
> > +
> 
> And I'd call these media_gobj_* as commented on patch 2/8.
> 
> >  void media_gobj_init(struct media_device *mdev,
> >  		    enum media_gobj_type type,
> >  		    struct media_gobj *gobj);
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered
  2015-08-21  1:35   ` Laurent Pinchart
@ 2015-08-21 10:25     ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 10:25 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Fri, 21 Aug 2015 04:35:04 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> Thank you for the patch.
> 
> On Wednesday 19 August 2015 08:01:53 Mauro Carvalho Chehab wrote:
> > We can only free the media device after being sure that no
> > graph object is used.
> 
> media_device_release() is currently broken as it should call back to the 
> driver that has allocated the media_device() structure. I think we should fix 
> that before adding more code on top of the problem.

Either that or move all allocations to happen via some MC function,
but this is out of the scope of this patch.

Whatever way we fix it, it is important to know when mdev
is supposed to cease to exist, and if this call happens
before or after the removal of all objects from the graph.

> 
> > In order to help tracking it, let's add debug messages
> > that will print when the media controller gets registered
> > or unregistered.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > index 065f6f08da37..0f3844470147 100644
> > --- a/drivers/media/media-device.c
> > +++ b/drivers/media/media-device.c
> > @@ -359,6 +359,7 @@ static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
> > 
> >  static void media_device_release(struct media_devnode *mdev)
> >  {
> > +	dev_dbg(mdev->parent, "Media device released\n");
> 
> As commented on patch 7/8, ftrace is a better candidate for function tracing.

Again, the problem here is to compare this with OOPs and other debug
messages, to see if the release is happening at the proper place.

Ftrace is not meant to be used for OOPS debug, nor it provides data
to the console, as it is not designed to be used for that purpose.

> 
> >  }
> > 
> >  /**
> > @@ -397,6 +398,8 @@ int __must_check __media_device_register(struct
> > media_device *mdev, return ret;
> >  	}
> > 
> > +	dev_dbg(mdev->dev, "Media device registered\n");
> > +
> >  	return 0;
> >  }
> >  EXPORT_SYMBOL_GPL(__media_device_register);
> > @@ -416,6 +419,8 @@ void media_device_unregister(struct media_device *mdev)
> > 
> >  	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
> >  	media_devnode_unregister(&mdev->devnode);
> > +
> > +	dev_dbg(mdev->dev, "Media device unregistered\n");
> >  }
> >  EXPORT_SYMBOL_GPL(media_device_unregister);
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
  2015-08-21  8:42       ` Mauro Carvalho Chehab
@ 2015-08-21 17:27         ` Laurent Pinchart
  -1 siblings, 0 replies; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21 17:27 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Hi Mauro,

On Friday 21 August 2015 05:42:29 Mauro Carvalho Chehab wrote:
> Em Fri, 21 Aug 2015 03:40:48 +0300 Laurent Pinchart escreveu:
> > On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> > > Instead of accessing directly entity.id, let's create a macro,
> > > as this field will be moved into a common struct later on.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

[snip]

> > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > > b/drivers/media/platform/vsp1/vsp1_video.c index
> > > 17f08973f835..debe4e539df6
> > > 100644
> > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> > > vsp1_pipeline *pipe,
> > > 			break;
> > > 
> > >  		/* Ensure the branch has no loop. */
> > > -		if (entities & (1 << entity->subdev.entity.id))
> > > +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
> > >  			return -EPIPE;
> > > 
> > > -		entities |= 1 << entity->subdev.entity.id;
> > > +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> > > 
> > >  		/* UDS can't be chained. */
> > >  		if (entity->type = VSP1_ENTITY_UDS) {
> > 
> > I would move the modification of the vsp1 driver to Javier's patch that
> > modifies the OMAP3 and OMAP4 drivers. Alternatively you could squash them
> > into this patch, but I believe having a first patch that adds the inline
> > function and a second patch that modifies all drivers to use it would be
> > better.
>
> Squashing will lose Javier's authorship. I guess the better is have a
> first patch with the inline, then my paches and Javier's ones, and
> latter on the patch removing entity->id.

What I meant is

1. This patch without the VSP1 chunk, with your authorship
2. Javier's patches for OMAP3 and OMAP4 + the VSP1 chunk squashed in a single 
patch, with Javier's authorship
3. Javier's patch removing entity->id, with Javier's authorship

I don't see a need to split usage of media_entity_id() into per-driver 
patches.

> I'll do that on the next patch series.
> 
> > > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > > index 8b21a4d920d9..0a66fc225559 100644
> > > --- a/include/media/media-entity.h
> > > +++ b/include/media/media-entity.h
> > > @@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct
> > > media_entity *entity) return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> > > 
> > >  }
> > > 
> > > +static inline u32 media_entity_id(struct media_entity *entity)
> > > +{
> > > +	return entity->id;
> > > +}
> > > +
> > > 
> > >  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
> > >  #define MEDIA_ENTITY_ENUM_MAX_ID	64

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
@ 2015-08-21 17:27         ` Laurent Pinchart
  0 siblings, 0 replies; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21 17:27 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Hi Mauro,

On Friday 21 August 2015 05:42:29 Mauro Carvalho Chehab wrote:
> Em Fri, 21 Aug 2015 03:40:48 +0300 Laurent Pinchart escreveu:
> > On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> > > Instead of accessing directly entity.id, let's create a macro,
> > > as this field will be moved into a common struct later on.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

[snip]

> > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > > b/drivers/media/platform/vsp1/vsp1_video.c index
> > > 17f08973f835..debe4e539df6
> > > 100644
> > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> > > vsp1_pipeline *pipe,
> > > 			break;
> > > 
> > >  		/* Ensure the branch has no loop. */
> > > -		if (entities & (1 << entity->subdev.entity.id))
> > > +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
> > >  			return -EPIPE;
> > > 
> > > -		entities |= 1 << entity->subdev.entity.id;
> > > +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> > > 
> > >  		/* UDS can't be chained. */
> > >  		if (entity->type == VSP1_ENTITY_UDS) {
> > 
> > I would move the modification of the vsp1 driver to Javier's patch that
> > modifies the OMAP3 and OMAP4 drivers. Alternatively you could squash them
> > into this patch, but I believe having a first patch that adds the inline
> > function and a second patch that modifies all drivers to use it would be
> > better.
>
> Squashing will lose Javier's authorship. I guess the better is have a
> first patch with the inline, then my paches and Javier's ones, and
> latter on the patch removing entity->id.

What I meant is

1. This patch without the VSP1 chunk, with your authorship
2. Javier's patches for OMAP3 and OMAP4 + the VSP1 chunk squashed in a single 
patch, with Javier's authorship
3. Javier's patch removing entity->id, with Javier's authorship

I don't see a need to split usage of media_entity_id() into per-driver 
patches.

> I'll do that on the next patch series.
> 
> > > diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > > index 8b21a4d920d9..0a66fc225559 100644
> > > --- a/include/media/media-entity.h
> > > +++ b/include/media/media-entity.h
> > > @@ -113,6 +113,11 @@ static inline u32 media_entity_subtype(struct
> > > media_entity *entity) return entity->type & MEDIA_ENT_SUBTYPE_MASK;
> > > 
> > >  }
> > > 
> > > +static inline u32 media_entity_id(struct media_entity *entity)
> > > +{
> > > +	return entity->id;
> > > +}
> > > +
> > > 
> > >  #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
> > >  #define MEDIA_ENTITY_ENUM_MAX_ID	64

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
  2015-08-21 17:27         ` Laurent Pinchart
@ 2015-08-21 17:45           ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 17:45 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Em Fri, 21 Aug 2015 20:27:19 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 21 August 2015 05:42:29 Mauro Carvalho Chehab wrote:
> > Em Fri, 21 Aug 2015 03:40:48 +0300 Laurent Pinchart escreveu:
> > > On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> > > > Instead of accessing directly entity.id, let's create a macro,
> > > > as this field will be moved into a common struct later on.
> > > > 
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> [snip]
> 
> > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > > > b/drivers/media/platform/vsp1/vsp1_video.c index
> > > > 17f08973f835..debe4e539df6
> > > > 100644
> > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> > > > vsp1_pipeline *pipe,
> > > > 			break;
> > > > 
> > > >  		/* Ensure the branch has no loop. */
> > > > -		if (entities & (1 << entity->subdev.entity.id))
> > > > +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
> > > >  			return -EPIPE;
> > > > 
> > > > -		entities |= 1 << entity->subdev.entity.id;
> > > > +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> > > > 
> > > >  		/* UDS can't be chained. */
> > > >  		if (entity->type = VSP1_ENTITY_UDS) {
> > > 
> > > I would move the modification of the vsp1 driver to Javier's patch that
> > > modifies the OMAP3 and OMAP4 drivers. Alternatively you could squash them
> > > into this patch, but I believe having a first patch that adds the inline
> > > function and a second patch that modifies all drivers to use it would be
> > > better.
> >
> > Squashing will lose Javier's authorship. I guess the better is have a
> > first patch with the inline, then my paches and Javier's ones, and
> > latter on the patch removing entity->id.
> 
> What I meant is
> 
> 1. This patch without the VSP1 chunk, with your authorship
> 2. Javier's patches for OMAP3 and OMAP4 + the VSP1 chunk squashed in a single 
> patch, with Javier's authorship
> 3. Javier's patch removing entity->id, with Javier's authorship

Actually, the removal of entity->id is at the first patch, with my
authorship, but I got the idea ;)

Btw, this was noticed because Javier is testing the MC new gen on OMAP3.
We should really enforce that all all drivers should compile with
COMPILE_TEST, as otherwise we'll keep having troubles like that.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
@ 2015-08-21 17:45           ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 17:45 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Em Fri, 21 Aug 2015 20:27:19 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 21 August 2015 05:42:29 Mauro Carvalho Chehab wrote:
> > Em Fri, 21 Aug 2015 03:40:48 +0300 Laurent Pinchart escreveu:
> > > On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> > > > Instead of accessing directly entity.id, let's create a macro,
> > > > as this field will be moved into a common struct later on.
> > > > 
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > > Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > > > Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> 
> [snip]
> 
> > > > diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > > > b/drivers/media/platform/vsp1/vsp1_video.c index
> > > > 17f08973f835..debe4e539df6
> > > > 100644
> > > > --- a/drivers/media/platform/vsp1/vsp1_video.c
> > > > +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > > > @@ -352,10 +352,10 @@ static int vsp1_pipeline_validate_branch(struct
> > > > vsp1_pipeline *pipe,
> > > > 			break;
> > > > 
> > > >  		/* Ensure the branch has no loop. */
> > > > -		if (entities & (1 << entity->subdev.entity.id))
> > > > +		if (entities & (1 << media_entity_id(&entity->subdev.entity)))
> > > >  			return -EPIPE;
> > > > 
> > > > -		entities |= 1 << entity->subdev.entity.id;
> > > > +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> > > > 
> > > >  		/* UDS can't be chained. */
> > > >  		if (entity->type == VSP1_ENTITY_UDS) {
> > > 
> > > I would move the modification of the vsp1 driver to Javier's patch that
> > > modifies the OMAP3 and OMAP4 drivers. Alternatively you could squash them
> > > into this patch, but I believe having a first patch that adds the inline
> > > function and a second patch that modifies all drivers to use it would be
> > > better.
> >
> > Squashing will lose Javier's authorship. I guess the better is have a
> > first patch with the inline, then my paches and Javier's ones, and
> > latter on the patch removing entity->id.
> 
> What I meant is
> 
> 1. This patch without the VSP1 chunk, with your authorship
> 2. Javier's patches for OMAP3 and OMAP4 + the VSP1 chunk squashed in a single 
> patch, with Javier's authorship
> 3. Javier's patch removing entity->id, with Javier's authorship

Actually, the removal of entity->id is at the first patch, with my
authorship, but I got the idea ;)

Btw, this was noticed because Javier is testing the MC new gen on OMAP3.
We should really enforce that all all drivers should compile with
COMPILE_TEST, as otherwise we'll keep having troubles like that.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 3/8] [media] media: use media_gobj inside entities
  2015-08-21 10:09     ` Mauro Carvalho Chehab
@ 2015-08-21 17:51       ` Laurent Pinchart
  2015-08-21 21:01         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21 17:51 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

On Friday 21 August 2015 07:09:44 Mauro Carvalho Chehab wrote:
> Em Fri, 21 Aug 2015 04:10:03 +0300 Laurent Pinchart escreveu:
> > On Wednesday 19 August 2015 08:01:50 Mauro Carvalho Chehab wrote:
> >> As entities are graph elements, 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.
> >> 
> >> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> >> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >> 
> >> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> >> index e429605ca2c3..81d6a130efef 100644
> >> --- a/drivers/media/media-device.c
> >> +++ b/drivers/media/media-device.c
> >> @@ -379,7 +379,6 @@ int __must_check __media_device_register(struct
> >> media_device *mdev,
> >> 	if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
> >>  		return -EINVAL;
> >> 
> >> -	mdev->entity_id = 1;
> >>  	INIT_LIST_HEAD(&mdev->entities);
> >>  	spin_lock_init(&mdev->lock);
> >>  	mutex_init(&mdev->graph_mutex);
> >> @@ -433,10 +432,8 @@ int __must_check media_device_register_entity(struct
> >> media_device *mdev,
> >> 	entity->parent = mdev;
> >>  	spin_lock(&mdev->lock);
> >> 
> >> -	if (entity->id == 0)
> >> -		entity->id = mdev->entity_id++;
> >> -	else
> >> -		mdev->entity_id = max(entity->id + 1, mdev->entity_id);
> >> +	/* Initialize media_gobj embedded at the entity */
> >> +	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> > 
> > Graph object initialization should be moved to media_entity_init() to keep
> > initialization separate from registration.
> 
> Won't work. I tried. My first RFC patches were doing that.
> 
> The problem is that media_entity_init() is currently called too early
> at the V4L2 drivers, before having mdev assigned.

That looks like a problem that should be fixed in the drivers then. The 
initialization of media devices and entities hasn't been thought of correctly, 
let's not carry mistakes forward.

> Also, objects without PADs don't call media_entity_init(). At long
> term, this function may even disappear, as it only exists today to
> allocate arrays for pads/links. If we get rid of the pads array, it
> will make no sense to keep it.

I wouldn't do that, as if we later add a field to media_entity that requires 
an initialization function to be called we would need to go and patch all the 
code that instantiates media_entity to add init calls. I'd prefer keeping the 
media_entity_init function even if all it does is call media_gobj_init.

> >>  	list_add_tail(&entity->list, &mdev->entities);
> >>  	spin_unlock(&mdev->lock);
> >> 
> >> @@ -459,6 +456,7 @@ void media_device_unregister_entity(struct
> >> media_entity *entity)
> >> 		return;
> >> 
> >>  	spin_lock(&mdev->lock);
> >> +	media_gobj_remove(&entity->graph_obj);
> >>  	list_del(&entity->list);
> >>  	spin_unlock(&mdev->lock);
> >>  	entity->parent = NULL;
> >> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> >> index 4834172bf6f8..888cb88e19bf 100644
> >> --- a/drivers/media/media-entity.c
> >> +++ b/drivers/media/media-entity.c
> >> @@ -43,7 +43,12 @@ void media_gobj_init(struct media_device *mdev,
> >>  			   enum media_gobj_type type,
> >>  			   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;
> >> +	}
> >>  }
> >>  
> >>  /**
> >> diff --git a/include/media/media-device.h b/include/media/media-device.h
> >> index a44f18fdf321..f6deef6e5820 100644
> >> --- a/include/media/media-device.h
> >> +++ b/include/media/media-device.h
> >> @@ -41,7 +41,7 @@ struct device;
> >>   * @bus_info:	Unique and stable device location identifier
> >>   * @hw_revision: Hardware device revision
> >>   * @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
> >>   * @lock:	Entities list lock
> >>   * @graph_mutex: Entities graph operation lock
> >> @@ -69,6 +69,7 @@ struct media_device {
> >>  	u32 driver_version;
> >>  	
> >>  	u32 entity_id;
> >> +
> >>  	struct list_head entities;
> >>  	
> >>  	/* Protects the entities list */
> >> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> >> index c1cd4fba051d..9ca366334bcf 100644
> >> --- a/include/media/media-entity.h
> >> +++ b/include/media/media-entity.h
> >> @@ -33,10 +33,10 @@
> >>  /**
> >>   * enum media_gobj_type - type of a graph element
> >>   *
> >> + * @MEDIA_GRAPH_ENTITY:		Identify a media entity
> > 
> > I think we should explicitly define here what an entity is.
> 
> I'm happy to add a new text here if you have a better idea.
>
> Anyway, for now, I'm more concerned on getting things done than to spend
> lots of time with the comments. As pointed on patch 1/8, while we're
> changing a lot the code, those comments tend to become obsolete very
> quick. The comments there is more like a boilerplate, as, once we finish
> touching at the core,  it makes sense to review the comments at media *.h
> files, converting all descriptions to kernel-doc-nano format (there are
> several not using it) and review Documentation/media-framework.txt, adding
> the missing parts.

Yes, we'll need to update Documentation/media-framework.txt. It doesn't have 
to be done right now, but should be ready by the time patches get merged. And 
from my experience, even though writing documentation feels like wasting time 
when you develop a patch series such as this one, it gets even more painful if 
you delay it.

> >>   */
> >>  enum media_gobj_type {
> >> -	 /* FIXME: add the types here, as we embed media_gobj */
> >> -	MEDIA_GRAPH_NONE
> >> +	MEDIA_GRAPH_ENTITY,
> >>  };

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-21 10:19     ` Mauro Carvalho Chehab
@ 2015-08-21 17:54       ` Laurent Pinchart
  2015-08-21 21:09         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21 17:54 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

On Friday 21 August 2015 07:19:21 Mauro Carvalho Chehab wrote:
> Em Fri, 21 Aug 2015 04:32:51 +0300 Laurent Pinchart escreveu:
> > On Wednesday 19 August 2015 08:01:54 Mauro Carvalho Chehab wrote:
> > > 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.
> > 
> > CONFIG_DYNAMIC_DEBUG is often enabled.
> 
> True, but once a driver/core is properly debugged, images without DEBUG
> could be used in production, if the amount of memory constraints are
> too tight.
> 
> > You're more or less adding function call tracing in this patch, isn't that
> > something that ftrace is supposed to do ?
> 
> Ftrace is a great infrastructure and helps a lot when we need to
> identify bottlenecks and other performance related stuff, but it
> doesn't replace debug functions.
> 
> There are some fundamental differences on what you could do with ftrace
> and what you can't.
> 
> At least on this stage, what I need is something that will provide
> output via serial console when the driver gets loaded, and that provides
> a synchronous output with the other Kernel messages.
> 
> This is the only way to debug certain OOPSes that are happening during
> the development of the patches.
> 
> This is something you cannot do with ftrace, but dynamic DEBUG works
> like a charm.

I understand the need for debug messages during development of a patch series, 
but I don't think this level of debugging belongs to mainline. Debug messages 
for function call tracing, even more in patch 6/8 and 7/8, is frowned upon in 
the kernel.

Or maybe I got it wrong and patches 6/8 and 7/8 are only for development and 
you don't plan to get them in mainline ?

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
  2015-08-21 17:45           ` Mauro Carvalho Chehab
@ 2015-08-21 18:11             ` Laurent Pinchart
  -1 siblings, 0 replies; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21 18:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Hi Mauro,

On Friday 21 August 2015 14:45:35 Mauro Carvalho Chehab wrote:
> Em Fri, 21 Aug 2015 20:27:19 +0300 Laurent Pinchart escreveu:
> > On Friday 21 August 2015 05:42:29 Mauro Carvalho Chehab wrote:
> >> Em Fri, 21 Aug 2015 03:40:48 +0300 Laurent Pinchart escreveu:
> >> > On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> >>>> Instead of accessing directly entity.id, let's create a macro,
> >>>> as this field will be moved into a common struct later on.
> >>>> 
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >>>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > [snip]
> > 
> >>>> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> >>>> b/drivers/media/platform/vsp1/vsp1_video.c index
> >>>> 17f08973f835..debe4e539df6
> >>>> 100644
> >>>> --- a/drivers/media/platform/vsp1/vsp1_video.c
> >>>> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> >>>> @@ -352,10 +352,10 @@ static int
> >>>> vsp1_pipeline_validate_branch(struct
> >>>> vsp1_pipeline *pipe,
> >>>> 			break;
> >>>> 			
> >>>>  		/* Ensure the branch has no loop. */
> >>>> -		if (entities & (1 << entity->subdev.entity.id))
> >>>> +		if (entities & (1 << media_entity_id(&entity->subdevntity)))
> >>>>  			return -EPIPE;
> >>>> 
> >>>> -		entities |= 1 << entity->subdev.entity.id;
> >>>> +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> >>>> 
> >>>>  		/* UDS can't be chained. */
> >>>>  		if (entity->type = VSP1_ENTITY_UDS) {
> >>> 
> >>> I would move the modification of the vsp1 driver to Javier's patch
> >>> that modifies the OMAP3 and OMAP4 drivers. Alternatively you could
> >>> squash them into this patch, but I believe having a first patch that
> >>> adds the inline function and a second patch that modifies all drivers
> >>> to use it would be better.
> >> 
> >> Squashing will lose Javier's authorship. I guess the better is have a
> >> first patch with the inline, then my paches and Javier's ones, and
> >> latter on the patch removing entity->id.
> > 
> > What I meant is
> > 
> > 1. This patch without the VSP1 chunk, with your authorship
> > 2. Javier's patches for OMAP3 and OMAP4 + the VSP1 chunk squashed in a
> > single patch, with Javier's authorship
> > 3. Javier's patch removing entity->id, with Javier's authorship
> 
> Actually, the removal of entity->id is at the first patch, with my
> authorship, but I got the idea ;)

I'm not sure to follow you. The first patch is this one, and it doesn't remove 
the id field from struct media_entity.

> Btw, this was noticed because Javier is testing the MC new gen on OMAP3.
> We should really enforce that all all drivers should compile with
> COMPILE_TEST, as otherwise we'll keep having troubles like that.

I agree with that. I've just sent a patch to enable compilation of the 
omap3isp driver with COMPILE_TEST. There's still a compile-time dependency on 
ARM, as well as a dependency on OMAP_IOMMU which currently depends on OMAP, 
but that can be fixed independently.

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
@ 2015-08-21 18:11             ` Laurent Pinchart
  0 siblings, 0 replies; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21 18:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Hi Mauro,

On Friday 21 August 2015 14:45:35 Mauro Carvalho Chehab wrote:
> Em Fri, 21 Aug 2015 20:27:19 +0300 Laurent Pinchart escreveu:
> > On Friday 21 August 2015 05:42:29 Mauro Carvalho Chehab wrote:
> >> Em Fri, 21 Aug 2015 03:40:48 +0300 Laurent Pinchart escreveu:
> >> > On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> >>>> Instead of accessing directly entity.id, let's create a macro,
> >>>> as this field will be moved into a common struct later on.
> >>>> 
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >>>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > 
> > [snip]
> > 
> >>>> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> >>>> b/drivers/media/platform/vsp1/vsp1_video.c index
> >>>> 17f08973f835..debe4e539df6
> >>>> 100644
> >>>> --- a/drivers/media/platform/vsp1/vsp1_video.c
> >>>> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> >>>> @@ -352,10 +352,10 @@ static int
> >>>> vsp1_pipeline_validate_branch(struct
> >>>> vsp1_pipeline *pipe,
> >>>> 			break;
> >>>> 			
> >>>>  		/* Ensure the branch has no loop. */
> >>>> -		if (entities & (1 << entity->subdev.entity.id))
> >>>> +		if (entities & (1 << media_entity_id(&entity->subdevntity)))
> >>>>  			return -EPIPE;
> >>>> 
> >>>> -		entities |= 1 << entity->subdev.entity.id;
> >>>> +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> >>>> 
> >>>>  		/* UDS can't be chained. */
> >>>>  		if (entity->type == VSP1_ENTITY_UDS) {
> >>> 
> >>> I would move the modification of the vsp1 driver to Javier's patch
> >>> that modifies the OMAP3 and OMAP4 drivers. Alternatively you could
> >>> squash them into this patch, but I believe having a first patch that
> >>> adds the inline function and a second patch that modifies all drivers
> >>> to use it would be better.
> >> 
> >> Squashing will lose Javier's authorship. I guess the better is have a
> >> first patch with the inline, then my paches and Javier's ones, and
> >> latter on the patch removing entity->id.
> > 
> > What I meant is
> > 
> > 1. This patch without the VSP1 chunk, with your authorship
> > 2. Javier's patches for OMAP3 and OMAP4 + the VSP1 chunk squashed in a
> > single patch, with Javier's authorship
> > 3. Javier's patch removing entity->id, with Javier's authorship
> 
> Actually, the removal of entity->id is at the first patch, with my
> authorship, but I got the idea ;)

I'm not sure to follow you. The first patch is this one, and it doesn't remove 
the id field from struct media_entity.

> Btw, this was noticed because Javier is testing the MC new gen on OMAP3.
> We should really enforce that all all drivers should compile with
> COMPILE_TEST, as otherwise we'll keep having troubles like that.

I agree with that. I've just sent a patch to enable compilation of the 
omap3isp driver with COMPILE_TEST. There's still a compile-time dependency on 
ARM, as well as a dependency on OMAP_IOMMU which currently depends on OMAP, 
but that can be fixed independently.

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
  2015-08-21 18:11             ` Laurent Pinchart
@ 2015-08-21 20:46               ` Mauro Carvalho Chehab
  -1 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 20:46 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Em Fri, 21 Aug 2015 21:11:57 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 21 August 2015 14:45:35 Mauro Carvalho Chehab wrote:
> > Em Fri, 21 Aug 2015 20:27:19 +0300 Laurent Pinchart escreveu:
> > > On Friday 21 August 2015 05:42:29 Mauro Carvalho Chehab wrote:
> > >> Em Fri, 21 Aug 2015 03:40:48 +0300 Laurent Pinchart escreveu:
> > >> > On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> > >>>> Instead of accessing directly entity.id, let's create a macro,
> > >>>> as this field will be moved into a common struct later on.
> > >>>> 
> > >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > >>>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > [snip]
> > > 
> > >>>> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > >>>> b/drivers/media/platform/vsp1/vsp1_video.c index
> > >>>> 17f08973f835..debe4e539df6
> > >>>> 100644
> > >>>> --- a/drivers/media/platform/vsp1/vsp1_video.c
> > >>>> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > >>>> @@ -352,10 +352,10 @@ static int
> > >>>> vsp1_pipeline_validate_branch(struct
> > >>>> vsp1_pipeline *pipe,
> > >>>> 			break;
> > >>>> 			
> > >>>>  		/* Ensure the branch has no loop. */
> > >>>> -		if (entities & (1 << entity->subdev.entity.id))
> > >>>> +		if (entities & (1 << media_entity_id(&entity->subdevntity)))
> > >>>>  			return -EPIPE;
> > >>>> 
> > >>>> -		entities |= 1 << entity->subdev.entity.id;
> > >>>> +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> > >>>> 
> > >>>>  		/* UDS can't be chained. */
> > >>>>  		if (entity->type = VSP1_ENTITY_UDS) {
> > >>> 
> > >>> I would move the modification of the vsp1 driver to Javier's patch
> > >>> that modifies the OMAP3 and OMAP4 drivers. Alternatively you could
> > >>> squash them into this patch, but I believe having a first patch that
> > >>> adds the inline function and a second patch that modifies all drivers
> > >>> to use it would be better.
> > >> 
> > >> Squashing will lose Javier's authorship. I guess the better is have a
> > >> first patch with the inline, then my paches and Javier's ones, and
> > >> latter on the patch removing entity->id.
> > > 
> > > What I meant is
> > > 
> > > 1. This patch without the VSP1 chunk, with your authorship
> > > 2. Javier's patches for OMAP3 and OMAP4 + the VSP1 chunk squashed in a
> > > single patch, with Javier's authorship
> > > 3. Javier's patch removing entity->id, with Javier's authorship
> > 
> > Actually, the removal of entity->id is at the first patch, with my
> > authorship, but I got the idea ;)
> 
> I'm not sure to follow you. The first patch is this one, and it doesn't remove 
> the id field from struct media_entity.

Sorry, I meant to say "the first patch series I submitted after the workshop",
e. .g RFC v1.

> > Btw, this was noticed because Javier is testing the MC new gen on OMAP3.
> > We should really enforce that all all drivers should compile with
> > COMPILE_TEST, as otherwise we'll keep having troubles like that.
> 
> I agree with that. I've just sent a patch to enable compilation of the 
> omap3isp driver with COMPILE_TEST. There's still a compile-time dependency on 
> ARM, as well as a dependency on OMAP_IOMMU which currently depends on OMAP, 
> but that can be fixed independently.

See the comments for the patch.

Regards,
Mauro



^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 1/8] [media] media: create a macro to get entity ID
@ 2015-08-21 20:46               ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 20:46 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Linux Media Mailing List, Mauro Carvalho Chehab, linux-sh

Em Fri, 21 Aug 2015 21:11:57 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 21 August 2015 14:45:35 Mauro Carvalho Chehab wrote:
> > Em Fri, 21 Aug 2015 20:27:19 +0300 Laurent Pinchart escreveu:
> > > On Friday 21 August 2015 05:42:29 Mauro Carvalho Chehab wrote:
> > >> Em Fri, 21 Aug 2015 03:40:48 +0300 Laurent Pinchart escreveu:
> > >> > On Wednesday 19 August 2015 08:01:48 Mauro Carvalho Chehab wrote:
> > >>>> Instead of accessing directly entity.id, let's create a macro,
> > >>>> as this field will be moved into a common struct later on.
> > >>>> 
> > >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > >>>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > > 
> > > [snip]
> > > 
> > >>>> diff --git a/drivers/media/platform/vsp1/vsp1_video.c
> > >>>> b/drivers/media/platform/vsp1/vsp1_video.c index
> > >>>> 17f08973f835..debe4e539df6
> > >>>> 100644
> > >>>> --- a/drivers/media/platform/vsp1/vsp1_video.c
> > >>>> +++ b/drivers/media/platform/vsp1/vsp1_video.c
> > >>>> @@ -352,10 +352,10 @@ static int
> > >>>> vsp1_pipeline_validate_branch(struct
> > >>>> vsp1_pipeline *pipe,
> > >>>> 			break;
> > >>>> 			
> > >>>>  		/* Ensure the branch has no loop. */
> > >>>> -		if (entities & (1 << entity->subdev.entity.id))
> > >>>> +		if (entities & (1 << media_entity_id(&entity->subdevntity)))
> > >>>>  			return -EPIPE;
> > >>>> 
> > >>>> -		entities |= 1 << entity->subdev.entity.id;
> > >>>> +		entities |= 1 << media_entity_id(&entity->subdev.entity);
> > >>>> 
> > >>>>  		/* UDS can't be chained. */
> > >>>>  		if (entity->type == VSP1_ENTITY_UDS) {
> > >>> 
> > >>> I would move the modification of the vsp1 driver to Javier's patch
> > >>> that modifies the OMAP3 and OMAP4 drivers. Alternatively you could
> > >>> squash them into this patch, but I believe having a first patch that
> > >>> adds the inline function and a second patch that modifies all drivers
> > >>> to use it would be better.
> > >> 
> > >> Squashing will lose Javier's authorship. I guess the better is have a
> > >> first patch with the inline, then my paches and Javier's ones, and
> > >> latter on the patch removing entity->id.
> > > 
> > > What I meant is
> > > 
> > > 1. This patch without the VSP1 chunk, with your authorship
> > > 2. Javier's patches for OMAP3 and OMAP4 + the VSP1 chunk squashed in a
> > > single patch, with Javier's authorship
> > > 3. Javier's patch removing entity->id, with Javier's authorship
> > 
> > Actually, the removal of entity->id is at the first patch, with my
> > authorship, but I got the idea ;)
> 
> I'm not sure to follow you. The first patch is this one, and it doesn't remove 
> the id field from struct media_entity.

Sorry, I meant to say "the first patch series I submitted after the workshop",
e. .g RFC v1.

> > Btw, this was noticed because Javier is testing the MC new gen on OMAP3.
> > We should really enforce that all all drivers should compile with
> > COMPILE_TEST, as otherwise we'll keep having troubles like that.
> 
> I agree with that. I've just sent a patch to enable compilation of the 
> omap3isp driver with COMPILE_TEST. There's still a compile-time dependency on 
> ARM, as well as a dependency on OMAP_IOMMU which currently depends on OMAP, 
> but that can be fixed independently.

See the comments for the patch.

Regards,
Mauro



^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 3/8] [media] media: use media_gobj inside entities
  2015-08-21 17:51       ` Laurent Pinchart
@ 2015-08-21 21:01         ` Mauro Carvalho Chehab
  2015-08-21 22:47           ` Laurent Pinchart
  0 siblings, 1 reply; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 21:01 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Fri, 21 Aug 2015 20:51:10 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 21 August 2015 07:09:44 Mauro Carvalho Chehab wrote:
> > Em Fri, 21 Aug 2015 04:10:03 +0300 Laurent Pinchart escreveu:
> > > On Wednesday 19 August 2015 08:01:50 Mauro Carvalho Chehab wrote:
> > >> As entities are graph elements, 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.
> > >> 
> > >> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > >> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > >> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > >> 
> > >> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> > >> index e429605ca2c3..81d6a130efef 100644
> > >> --- a/drivers/media/media-device.c
> > >> +++ b/drivers/media/media-device.c
> > >> @@ -379,7 +379,6 @@ int __must_check __media_device_register(struct
> > >> media_device *mdev,
> > >> 	if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
> > >>  		return -EINVAL;
> > >> 
> > >> -	mdev->entity_id = 1;
> > >>  	INIT_LIST_HEAD(&mdev->entities);
> > >>  	spin_lock_init(&mdev->lock);
> > >>  	mutex_init(&mdev->graph_mutex);
> > >> @@ -433,10 +432,8 @@ int __must_check media_device_register_entity(struct
> > >> media_device *mdev,
> > >> 	entity->parent = mdev;
> > >>  	spin_lock(&mdev->lock);
> > >> 
> > >> -	if (entity->id == 0)
> > >> -		entity->id = mdev->entity_id++;
> > >> -	else
> > >> -		mdev->entity_id = max(entity->id + 1, mdev->entity_id);
> > >> +	/* Initialize media_gobj embedded at the entity */
> > >> +	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> > > 
> > > Graph object initialization should be moved to media_entity_init() to keep
> > > initialization separate from registration.
> > 
> > Won't work. I tried. My first RFC patches were doing that.
> > 
> > The problem is that media_entity_init() is currently called too early
> > at the V4L2 drivers, before having mdev assigned.
> 
> That looks like a problem that should be fixed in the drivers then. The 
> initialization of media devices and entities hasn't been thought of correctly, 
> let's not carry mistakes forward.

In this particular case, calling media_gobj_init() during
media_entity_register() won't cause any troubles, and moving it latter
to media_entity_init() is a two lines patch, once drivers got fixed
by the drivers maintainers.

> > Also, objects without PADs don't call media_entity_init(). At long
> > term, this function may even disappear, as it only exists today to
> > allocate arrays for pads/links. If we get rid of the pads array, it
> > will make no sense to keep it.
> 
> I wouldn't do that, as if we later add a field to media_entity that requires 
> an initialization function to be called we would need to go and patch all the 
> code that instantiates media_entity to add init calls. I'd prefer keeping the 
> media_entity_init function even if all it does is call media_gobj_init.

OK.

> 
> > >>  	list_add_tail(&entity->list, &mdev->entities);
> > >>  	spin_unlock(&mdev->lock);
> > >> 
> > >> @@ -459,6 +456,7 @@ void media_device_unregister_entity(struct
> > >> media_entity *entity)
> > >> 		return;
> > >> 
> > >>  	spin_lock(&mdev->lock);
> > >> +	media_gobj_remove(&entity->graph_obj);
> > >>  	list_del(&entity->list);
> > >>  	spin_unlock(&mdev->lock);
> > >>  	entity->parent = NULL;
> > >> diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
> > >> index 4834172bf6f8..888cb88e19bf 100644
> > >> --- a/drivers/media/media-entity.c
> > >> +++ b/drivers/media/media-entity.c
> > >> @@ -43,7 +43,12 @@ void media_gobj_init(struct media_device *mdev,
> > >>  			   enum media_gobj_type type,
> > >>  			   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;
> > >> +	}
> > >>  }
> > >>  
> > >>  /**
> > >> diff --git a/include/media/media-device.h b/include/media/media-device.h
> > >> index a44f18fdf321..f6deef6e5820 100644
> > >> --- a/include/media/media-device.h
> > >> +++ b/include/media/media-device.h
> > >> @@ -41,7 +41,7 @@ struct device;
> > >>   * @bus_info:	Unique and stable device location identifier
> > >>   * @hw_revision: Hardware device revision
> > >>   * @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
> > >>   * @lock:	Entities list lock
> > >>   * @graph_mutex: Entities graph operation lock
> > >> @@ -69,6 +69,7 @@ struct media_device {
> > >>  	u32 driver_version;
> > >>  	
> > >>  	u32 entity_id;
> > >> +
> > >>  	struct list_head entities;
> > >>  	
> > >>  	/* Protects the entities list */
> > >> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > >> index c1cd4fba051d..9ca366334bcf 100644
> > >> --- a/include/media/media-entity.h
> > >> +++ b/include/media/media-entity.h
> > >> @@ -33,10 +33,10 @@
> > >>  /**
> > >>   * enum media_gobj_type - type of a graph element
> > >>   *
> > >> + * @MEDIA_GRAPH_ENTITY:		Identify a media entity
> > > 
> > > I think we should explicitly define here what an entity is.
> > 
> > I'm happy to add a new text here if you have a better idea.
> >
> > Anyway, for now, I'm more concerned on getting things done than to spend
> > lots of time with the comments. As pointed on patch 1/8, while we're
> > changing a lot the code, those comments tend to become obsolete very
> > quick. The comments there is more like a boilerplate, as, once we finish
> > touching at the core,  it makes sense to review the comments at media *.h
> > files, converting all descriptions to kernel-doc-nano format (there are
> > several not using it) and review Documentation/media-framework.txt, adding
> > the missing parts.
> 
> Yes, we'll need to update Documentation/media-framework.txt. It doesn't have 
> to be done right now, but should be ready by the time patches get merged.

Ok.

> And 
> from my experience, even though writing documentation feels like wasting time 
> when you develop a patch series such as this one, it gets even more painful if 
> you delay it.
> 
> > >>   */
> > >>  enum media_gobj_type {
> > >> -	 /* FIXME: add the types here, as we embed media_gobj */
> > >> -	MEDIA_GRAPH_NONE
> > >> +	MEDIA_GRAPH_ENTITY,
> > >>  };
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-21 17:54       ` Laurent Pinchart
@ 2015-08-21 21:09         ` Mauro Carvalho Chehab
  2015-08-21 22:54           ` Laurent Pinchart
  0 siblings, 1 reply; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-21 21:09 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Fri, 21 Aug 2015 20:54:29 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 21 August 2015 07:19:21 Mauro Carvalho Chehab wrote:
> > Em Fri, 21 Aug 2015 04:32:51 +0300 Laurent Pinchart escreveu:
> > > On Wednesday 19 August 2015 08:01:54 Mauro Carvalho Chehab wrote:
> > > > 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.
> > > 
> > > CONFIG_DYNAMIC_DEBUG is often enabled.
> > 
> > True, but once a driver/core is properly debugged, images without DEBUG
> > could be used in production, if the amount of memory constraints are
> > too tight.
> > 
> > > You're more or less adding function call tracing in this patch, isn't that
> > > something that ftrace is supposed to do ?
> > 
> > Ftrace is a great infrastructure and helps a lot when we need to
> > identify bottlenecks and other performance related stuff, but it
> > doesn't replace debug functions.
> > 
> > There are some fundamental differences on what you could do with ftrace
> > and what you can't.
> > 
> > At least on this stage, what I need is something that will provide
> > output via serial console when the driver gets loaded, and that provides
> > a synchronous output with the other Kernel messages.
> > 
> > This is the only way to debug certain OOPSes that are happening during
> > the development of the patches.
> > 
> > This is something you cannot do with ftrace, but dynamic DEBUG works
> > like a charm.
> 
> I understand the need for debug messages during development of a patch series, 
> but I don't think this level of debugging belongs to mainline. Debug messages 
> for function call tracing, even more in patch 6/8 and 7/8, is frowned upon in 
> the kernel.
> 
> Or maybe I got it wrong and patches 6/8 and 7/8 are only for development and 
> you don't plan to get them in mainline ?

As we've agreed, the first phase won't have dynamic support. Both patches
6/8 and 7/8 are important until then.

So, they should reach mainline together with the first MC new gen series.

Patch 6/8 can be reverted after we finish implementing dynamic support.

I think patch 7/8 will still be a good debug feature, but we can discuss
about that after implementing dynamic support.

Regards,
Mauro


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 3/8] [media] media: use media_gobj inside entities
  2015-08-21 21:01         ` Mauro Carvalho Chehab
@ 2015-08-21 22:47           ` Laurent Pinchart
  2015-08-24  9:18             ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21 22:47 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

On Friday 21 August 2015 18:01:31 Mauro Carvalho Chehab wrote:
> Em Fri, 21 Aug 2015 20:51:10 +0300 Laurent Pinchart escreveu:
> > On Friday 21 August 2015 07:09:44 Mauro Carvalho Chehab wrote:
> >> Em Fri, 21 Aug 2015 04:10:03 +0300 Laurent Pinchart escreveu:
> >>> On Wednesday 19 August 2015 08:01:50 Mauro Carvalho Chehab wrote:
> >>>> As entities are graph elements, 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.
> >>>> 
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >>>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> >>>> 
> >>>> diff --git a/drivers/media/media-device.c
> >>>> b/drivers/media/media-device.c
> >>>> index e429605ca2c3..81d6a130efef 100644
> >>>> --- a/drivers/media/media-device.c
> >>>> +++ b/drivers/media/media-device.c
> >>>> @@ -379,7 +379,6 @@ int __must_check __media_device_register(struct
> >>>> media_device *mdev,
> >>>> 	if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
> >>>>  		return -EINVAL;
> >>>> 
> >>>> -	mdev->entity_id = 1;
> >>>>  	INIT_LIST_HEAD(&mdev->entities);
> >>>>  	spin_lock_init(&mdev->lock);
> >>>>  	mutex_init(&mdev->graph_mutex);
> >>>> @@ -433,10 +432,8 @@ int __must_check 
> >>>> media_device_register_entity(struct media_device *mdev,
> >>>> 
> >>>> 	entity->parent = mdev;
> >>>> 	
> >>>>  	spin_lock(&mdev->lock);
> >>>> 
> >>>> -	if (entity->id == 0)
> >>>> -		entity->id = mdev->entity_id++;
> >>>> -	else
> >>>> -		mdev->entity_id = max(entity->id + 1, mdev->entity_id);
> >>>> +	/* Initialize media_gobj embedded at the entity */
> >>>> +	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> >>> 
> >>> Graph object initialization should be moved to media_entity_init() to
> >>> keep initialization separate from registration.
> >> 
> >> Won't work. I tried. My first RFC patches were doing that.
> >> 
> >> The problem is that media_entity_init() is currently called too early
> >> at the V4L2 drivers, before having mdev assigned.
> > 
> > That looks like a problem that should be fixed in the drivers then. The
> > initialization of media devices and entities hasn't been thought of
> > correctly, let's not carry mistakes forward.
> 
> In this particular case, calling media_gobj_init() during
> media_entity_register() won't cause any troubles, and moving it latter
> to media_entity_init() is a two lines patch, once drivers got fixed
> by the drivers maintainers.

It's the "once drivers got fixed by the drivers maintainers" that worries me. 
We all know it unfortunately doesn't happen by itself, and I believe it will 
become more and more difficult as time goes by and more drivers use the MC 
framework. We're trying to refactor, clean up and extend MC, both in-kernel 
and towards userspace, to correct design and implementation mistakes. I'm 
worried that we'll make different but similarly painful mistakes if we don't 
take a bit of time to do things properly now. And while it will require a 
couple more patches, I don't think we're looking at months of work either.

It might be that assigning an ID to objects can only be done at at 
registration time, especially for standalone subdev drivers (I'm thinking 
about the I2C camera sensors in particular). Still, calling media_gobj_init() 
in media_device_register_entity() doesn't sound right. Maybe the solution is 
to use media_gobj_init() for init-time initialization, and creating a 
media_gobj_assign_id() (or similarly-named) function to call at registration 
time. What I'd really like to see is clear explicit rules regarding how 
init/cleanup and register/unregister interact and how they should be used by 
drivers. The current mess is partly caused by not having thought this out 
properly to start with.

I also have a feeling that we'll realize changes are required when 
implementing support for dynamic changes.

> >> Also, objects without PADs don't call media_entity_init(). At long
> >> term, this function may even disappear, as it only exists today to
> >> allocate arrays for pads/links. If we get rid of the pads array, it
> >> will make no sense to keep it.
> > 
> > I wouldn't do that, as if we later add a field to media_entity that
> > requires an initialization function to be called we would need to go and
> > patch all the code that instantiates media_entity to add init calls. I'd
> > prefer keeping the media_entity_init function even if all it does is call
> > media_gobj_init.
>
> OK.
> 
> >>>>  	list_add_tail(&entity->list, &mdev->entities);
> >>>>  	spin_unlock(&mdev->lock);
> >>>> 

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-21 21:09         ` Mauro Carvalho Chehab
@ 2015-08-21 22:54           ` Laurent Pinchart
  2015-08-24  9:40             ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 48+ messages in thread
From: Laurent Pinchart @ 2015-08-21 22:54 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Hi Mauro,

On Friday 21 August 2015 18:09:31 Mauro Carvalho Chehab wrote:
> Em Fri, 21 Aug 2015 20:54:29 +0300 Laurent Pinchart escreveu:
> > On Friday 21 August 2015 07:19:21 Mauro Carvalho Chehab wrote:
> >> Em Fri, 21 Aug 2015 04:32:51 +0300 Laurent Pinchart escreveu:
> >>> On Wednesday 19 August 2015 08:01:54 Mauro Carvalho Chehab wrote:
> >>>> 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.
> >>> 
> >>> CONFIG_DYNAMIC_DEBUG is often enabled.
> >> 
> >> True, but once a driver/core is properly debugged, images without DEBUG
> >> could be used in production, if the amount of memory constraints are
> >> too tight.
> >> 
> >> > You're more or less adding function call tracing in this patch, isn't
> >> > that something that ftrace is supposed to do ?
> >> 
> >> Ftrace is a great infrastructure and helps a lot when we need to
> >> identify bottlenecks and other performance related stuff, but it
> >> doesn't replace debug functions.
> >> 
> >> There are some fundamental differences on what you could do with ftrace
> >> and what you can't.
> >> 
> >> At least on this stage, what I need is something that will provide
> >> output via serial console when the driver gets loaded, and that provides
> >> a synchronous output with the other Kernel messages.
> >> 
> >> This is the only way to debug certain OOPSes that are happening during
> >> the development of the patches.
> >> 
> >> This is something you cannot do with ftrace, but dynamic DEBUG works
> >> like a charm.
> > 
> > I understand the need for debug messages during development of a patch
> > series, but I don't think this level of debugging belongs to mainline.
> > Debug messages for function call tracing, even more in patch 6/8 and 7/8,
> > is frowned upon in the kernel.
> > 
> > Or maybe I got it wrong and patches 6/8 and 7/8 are only for development
> > and you don't plan to get them in mainline ?
> 
> As we've agreed, the first phase won't have dynamic support. Both patches
> 6/8 and 7/8 are important until then.

Why are they more important with dynamic support ?

> So, they should reach mainline together with the first MC new gen series.

Patch 6/8 states in its commit message that

"We can only free the media device after being sure that no graph object is 
used. In order to help tracking it, let's add debug messages that will print 
when the media controller gets registered or unregistered."

Instead of debug messages that need to be enabled and tracked manually, why 
not detecting the condition and issuing a WARN_ON() ?

> Patch 6/8 can be reverted after we finish implementing dynamic support.
> 
> I think patch 7/8 will still be a good debug feature, but we can discuss
> about that after implementing dynamic support.

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 3/8] [media] media: use media_gobj inside entities
  2015-08-21 22:47           ` Laurent Pinchart
@ 2015-08-24  9:18             ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-24  9:18 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Sat, 22 Aug 2015 01:47:37 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 21 August 2015 18:01:31 Mauro Carvalho Chehab wrote:
> > Em Fri, 21 Aug 2015 20:51:10 +0300 Laurent Pinchart escreveu:
> > > On Friday 21 August 2015 07:09:44 Mauro Carvalho Chehab wrote:
> > >> Em Fri, 21 Aug 2015 04:10:03 +0300 Laurent Pinchart escreveu:
> > >>> On Wednesday 19 August 2015 08:01:50 Mauro Carvalho Chehab wrote:
> > >>>> As entities are graph elements, 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.
> > >>>> 
> > >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > >>>> Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
> > >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
> > >>>> 
> > >>>> diff --git a/drivers/media/media-device.c
> > >>>> b/drivers/media/media-device.c
> > >>>> index e429605ca2c3..81d6a130efef 100644
> > >>>> --- a/drivers/media/media-device.c
> > >>>> +++ b/drivers/media/media-device.c
> > >>>> @@ -379,7 +379,6 @@ int __must_check __media_device_register(struct
> > >>>> media_device *mdev,
> > >>>> 	if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
> > >>>>  		return -EINVAL;
> > >>>> 
> > >>>> -	mdev->entity_id = 1;
> > >>>>  	INIT_LIST_HEAD(&mdev->entities);
> > >>>>  	spin_lock_init(&mdev->lock);
> > >>>>  	mutex_init(&mdev->graph_mutex);
> > >>>> @@ -433,10 +432,8 @@ int __must_check 
> > >>>> media_device_register_entity(struct media_device *mdev,
> > >>>> 
> > >>>> 	entity->parent = mdev;
> > >>>> 	
> > >>>>  	spin_lock(&mdev->lock);
> > >>>> 
> > >>>> -	if (entity->id == 0)
> > >>>> -		entity->id = mdev->entity_id++;
> > >>>> -	else
> > >>>> -		mdev->entity_id = max(entity->id + 1, mdev->entity_id);
> > >>>> +	/* Initialize media_gobj embedded at the entity */
> > >>>> +	media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
> > >>> 
> > >>> Graph object initialization should be moved to media_entity_init() to
> > >>> keep initialization separate from registration.
> > >> 
> > >> Won't work. I tried. My first RFC patches were doing that.
> > >> 
> > >> The problem is that media_entity_init() is currently called too early
> > >> at the V4L2 drivers, before having mdev assigned.
> > > 
> > > That looks like a problem that should be fixed in the drivers then. The
> > > initialization of media devices and entities hasn't been thought of
> > > correctly, let's not carry mistakes forward.
> > 
> > In this particular case, calling media_gobj_init() during
> > media_entity_register() won't cause any troubles, and moving it latter
> > to media_entity_init() is a two lines patch, once drivers got fixed
> > by the drivers maintainers.
> 
> It's the "once drivers got fixed by the drivers maintainers" that worries me. 
> We all know it unfortunately doesn't happen by itself, and I believe it will 
> become more and more difficult as time goes by and more drivers use the MC 
> framework. We're trying to refactor, clean up and extend MC, both in-kernel 
> and towards userspace, to correct design and implementation mistakes. I'm 
> worried that we'll make different but similarly painful mistakes if we don't 
> take a bit of time to do things properly now. And while it will require a 
> couple more patches, I don't think we're looking at months of work either.
> 
> It might be that assigning an ID to objects can only be done at at 
> registration time, especially for standalone subdev drivers (I'm thinking 
> about the I2C camera sensors in particular). Still, calling media_gobj_init() 
> in media_device_register_entity() doesn't sound right. Maybe the solution is 
> to use media_gobj_init() for init-time initialization, and creating a 
> media_gobj_assign_id() (or similarly-named) function to call at registration 
> time. What I'd really like to see is clear explicit rules regarding how 
> init/cleanup and register/unregister interact and how they should be used by 
> drivers. The current mess is partly caused by not having thought this out 
> properly to start with.

See the latest patch series, as it now has the big picture. What
media_gobj_init() is meant to be (and it does) is to register a graph
object at the media device. This can only be done if mdev is known.
And media_gobj_remove() does the opposite.

Ok, perhaps we can rename it to media_gobj_register() and 
media_gobj_unregister(), but the right place for it to be called
is when the object is ready to be registered, and not before.

> 
> I also have a feeling that we'll realize changes are required when 
> implementing support for dynamic changes.

You're probably right here: we'll likely need to change the drivers
for them to create things only when the media_device is known, and
splitting entity creation from pads creation.

> 
> > >> Also, objects without PADs don't call media_entity_init(). At long
> > >> term, this function may even disappear, as it only exists today to
> > >> allocate arrays for pads/links. If we get rid of the pads array, it
> > >> will make no sense to keep it.
> > > 
> > > I wouldn't do that, as if we later add a field to media_entity that
> > > requires an initialization function to be called we would need to go and
> > > patch all the code that instantiates media_entity to add init calls. I'd
> > > prefer keeping the media_entity_init function even if all it does is call
> > > media_gobj_init.
> >
> > OK.
> > 
> > >>>>  	list_add_tail(&entity->list, &mdev->entities);
> > >>>>  	spin_unlock(&mdev->lock);
> > >>>> 
> 

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal
  2015-08-21 22:54           ` Laurent Pinchart
@ 2015-08-24  9:40             ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-08-24  9:40 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: Linux Media Mailing List, Mauro Carvalho Chehab

Em Sat, 22 Aug 2015 01:54:07 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Mauro,
> 
> On Friday 21 August 2015 18:09:31 Mauro Carvalho Chehab wrote:
> > Em Fri, 21 Aug 2015 20:54:29 +0300 Laurent Pinchart escreveu:
> > > On Friday 21 August 2015 07:19:21 Mauro Carvalho Chehab wrote:
> > >> Em Fri, 21 Aug 2015 04:32:51 +0300 Laurent Pinchart escreveu:
> > >>> On Wednesday 19 August 2015 08:01:54 Mauro Carvalho Chehab wrote:
> > >>>> 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.
> > >>> 
> > >>> CONFIG_DYNAMIC_DEBUG is often enabled.
> > >> 
> > >> True, but once a driver/core is properly debugged, images without DEBUG
> > >> could be used in production, if the amount of memory constraints are
> > >> too tight.
> > >> 
> > >> > You're more or less adding function call tracing in this patch, isn't
> > >> > that something that ftrace is supposed to do ?
> > >> 
> > >> Ftrace is a great infrastructure and helps a lot when we need to
> > >> identify bottlenecks and other performance related stuff, but it
> > >> doesn't replace debug functions.
> > >> 
> > >> There are some fundamental differences on what you could do with ftrace
> > >> and what you can't.
> > >> 
> > >> At least on this stage, what I need is something that will provide
> > >> output via serial console when the driver gets loaded, and that provides
> > >> a synchronous output with the other Kernel messages.
> > >> 
> > >> This is the only way to debug certain OOPSes that are happening during
> > >> the development of the patches.
> > >> 
> > >> This is something you cannot do with ftrace, but dynamic DEBUG works
> > >> like a charm.
> > > 
> > > I understand the need for debug messages during development of a patch
> > > series, but I don't think this level of debugging belongs to mainline.
> > > Debug messages for function call tracing, even more in patch 6/8 and 7/8,
> > > is frowned upon in the kernel.
> > > 
> > > Or maybe I got it wrong and patches 6/8 and 7/8 are only for development
> > > and you don't plan to get them in mainline ?
> > 
> > As we've agreed, the first phase won't have dynamic support. Both patches
> > 6/8 and 7/8 are important until then.
> 
> Why are they more important with dynamic support ?

Because it helps to identify if the creation/removal of the objects are
being done at the right order. If the media_device got unregistered
and kfreed before unregistering the devices, things will go bad.
Also, a PAD can't be destroyed if any links that reference it still
exists.

I got tons of troubles like that during the development of the PATCH v7
series.

> > So, they should reach mainline together with the first MC new gen series.
> 
> Patch 6/8 states in its commit message that
> 
> "We can only free the media device after being sure that no graph object is 
> used. In order to help tracking it, let's add debug messages that will print 
> when the media controller gets registered or unregistered."
> 
> Instead of debug messages that need to be enabled and tracked manually, why 
> not detecting the condition and issuing a WARN_ON() ?

Because I'm not sure how to write such patch ;) I don't know any
algorithm that could be used to detect that a kfree() happening at the
wrong order.

My old proposal were to use kref() for that, but neither you nor Lars
saw the need for that. Also, after looking deeper in the code, adding
a kref() for the graph objects isn't trivial.

My original idea to support dynamic objects is to have a code at
media_graph_init() that would increment the kref() count for the
created object and for the referenced objects (like the two pads
on a data link and the media_device), and decrementing kref() at
media_graph_remove(). The actual function that would free the memory
would be called when kref() count reaches zero.

In other words, if we add a kref() count for the objects and for
media_device, then we can get rid of patch 6/8, but we're not there
yet.

For that to work, there are several changes that would be needed:

- The media_device should be dynamically allocated;

- All graph objects can only be created after having the media
  device created, and should not be embedded;

- The PAD allocation should be moved to the MC core.

IMO, that's the best solution if we were starting to design MC
right now. However, changing the drivers at this moment to do
that will require retest the MC there, with means that the
driver maintainer should very likely be helping. That's an
unlikely scenario, unfortunately.

So, I guess we'll need to find another way. That's why we need
to keep patch 6/8 until we figure out a solution for that.

Regards,
Mauro


^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects
  2015-08-21  8:07     ` Hans Verkuil
@ 2015-09-07 21:49       ` Laurent Pinchart
  2015-09-08 10:05         ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 48+ messages in thread
From: Laurent Pinchart @ 2015-09-07 21:49 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Mauro Carvalho Chehab, Linux Media Mailing List, Mauro Carvalho Chehab

Hi Hans,

On Friday 21 August 2015 10:07:36 Hans Verkuil wrote:
> On 08/21/2015 03:02 AM, Laurent Pinchart wrote:
> > On Wednesday 19 August 2015 08:01:49 Mauro Carvalho Chehab wrote:
> >> +/* Enums used internally at the media controller to represent graphs */
> >> +
> >> +/**
> >> + * enum media_gobj_type - type of a graph element
> > 
> > Let's try to standardize the vocabulary, should it be called graph object
> > or graph element ? In the first case let's document it as graph object.
> > In the second case it would be more consistent to refer to it as enum
> > media_gelem_type (and struct media_gelem below).
> 
> For what it is worth, I prefer the term graph object.

So do I.

> >> + *
> >> + */
> >> +enum media_gobj_type {
> >> +	 /* FIXME: add the types here, as we embed media_gobj */
> >> +	MEDIA_GRAPH_NONE
> >> +};
> >> +
> >> +#define MEDIA_BITS_PER_TYPE		8
> >> +#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
> >> +#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 
0)
> >> +
> >> +/* Structs to represent the objects that belong to a media graph */
> >> +
> >> +/**
> >> + * struct media_gobj - Define a graph object.
> >> + *
> >> + * @id:		Non-zero object ID identifier. The ID should be unique
> >> + *		inside a media_device, as it is composed by
> >> + *		MEDIA_BITS_PER_TYPE to store the type plus
> >> + *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
> >> + *		(called as "local ID").
> > 
> > I'd very much prefer using a single ID range and adding a type field.
> > Abusing bits of the ID field to store the type will just makes IDs
> > impractical to use. Let's do it properly.
> 
> Why is that impractical? I think it is more practical. Why waste memory on
> something that is easy to encode in the ID?
> 
> I'm not necessarily opposed to splitting this up (Mauro's initial patch
> series used a separate type field if I remember correctly), but it's not
> clear to me what the benefits are. Keeping it in a single u32 makes
> describing links also very easy since you just give it the two objects that
> are linked and it is immediately clear which object types are linked: no
> need to either store the types in the link struct or look up each object to
> find the type.
> 
> >> + * All elements on the media graph should have this struct embedded
> > 
> > All elements (objects) or only the ones that need an ID ? Or maybe we'll
> > define graph element (object) as an element (object) that has an ID,
> > making some "elements" not elements.
> 
> Yes, all objects have an ID. I see no reason to special-case this.
> 
> You wrote this at 3 am, so you were probably sleep-deprived when you wrote
> the second sentence as I can't wrap my head around that one :-)

It's always 3:00am in some time zone, but it wasn't in Seattle ;-)

The question was whether every element is required to have an ID. If some of 
what we currently call element doesn't need an ID, then we'll have to either 
modify the quoted documentation, or redefine "element" to only include the 
elements that have an ID, making the graph objects that don't have an ID not 
"elements".

> >> + */
> >> +struct media_gobj {
> >> +	u32			id;
> >> +};

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects
  2015-09-07 21:49       ` Laurent Pinchart
@ 2015-09-08 10:05         ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 48+ messages in thread
From: Mauro Carvalho Chehab @ 2015-09-08 10:05 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Hans Verkuil, Linux Media Mailing List, Mauro Carvalho Chehab

Em Tue, 08 Sep 2015 00:49:58 +0300
Laurent Pinchart <laurent.pinchart@ideasonboard.com> escreveu:

> Hi Hans,
> 
> On Friday 21 August 2015 10:07:36 Hans Verkuil wrote:
> > On 08/21/2015 03:02 AM, Laurent Pinchart wrote:
> > > On Wednesday 19 August 2015 08:01:49 Mauro Carvalho Chehab wrote:
> > >> +/* Enums used internally at the media controller to represent graphs */
> > >> +
> > >> +/**
> > >> + * enum media_gobj_type - type of a graph element
> > > 
> > > Let's try to standardize the vocabulary, should it be called graph object
> > > or graph element ? In the first case let's document it as graph object.
> > > In the second case it would be more consistent to refer to it as enum
> > > media_gelem_type (and struct media_gelem below).
> > 
> > For what it is worth, I prefer the term graph object.
> 
> So do I.

At v7 we removed the term "elements" in favor of "objects", as proposed by
Hans.

> 
> > >> + *
> > >> + */
> > >> +enum media_gobj_type {
> > >> +	 /* FIXME: add the types here, as we embed media_gobj */
> > >> +	MEDIA_GRAPH_NONE
> > >> +};
> > >> +
> > >> +#define MEDIA_BITS_PER_TYPE		8
> > >> +#define MEDIA_BITS_PER_LOCAL_ID		(32 - MEDIA_BITS_PER_TYPE)
> > >> +#define MEDIA_LOCAL_ID_MASK		 GENMASK(MEDIA_BITS_PER_LOCAL_ID - 1, 
> 0)
> > >> +
> > >> +/* Structs to represent the objects that belong to a media graph */
> > >> +
> > >> +/**
> > >> + * struct media_gobj - Define a graph object.
> > >> + *
> > >> + * @id:		Non-zero object ID identifier. The ID should be unique
> > >> + *		inside a media_device, as it is composed by
> > >> + *		MEDIA_BITS_PER_TYPE to store the type plus
> > >> + *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
> > >> + *		(called as "local ID").
> > > 
> > > I'd very much prefer using a single ID range and adding a type field.
> > > Abusing bits of the ID field to store the type will just makes IDs
> > > impractical to use. Let's do it properly.
> > 
> > Why is that impractical? I think it is more practical. Why waste memory on
> > something that is easy to encode in the ID?
> > 
> > I'm not necessarily opposed to splitting this up (Mauro's initial patch
> > series used a separate type field if I remember correctly), but it's not
> > clear to me what the benefits are. Keeping it in a single u32 makes
> > describing links also very easy since you just give it the two objects that
> > are linked and it is immediately clear which object types are linked: no
> > need to either store the types in the link struct or look up each object to
> > find the type.
> > 
> > >> + * All elements on the media graph should have this struct embedded
> > > 
> > > All elements (objects) or only the ones that need an ID ? Or maybe we'll
> > > define graph element (object) as an element (object) that has an ID,
> > > making some "elements" not elements.
> > 
> > Yes, all objects have an ID. I see no reason to special-case this.
> > 
> > You wrote this at 3 am, so you were probably sleep-deprived when you wrote
> > the second sentence as I can't wrap my head around that one :-)
> 
> It's always 3:00am in some time zone, but it wasn't in Seattle ;-)
> 
> The question was whether every element is required to have an ID. If some of 
> what we currently call element doesn't need an ID, then we'll have to either 
> modify the quoted documentation, or redefine "element" to only include the 
> elements that have an ID, making the graph objects that don't have an ID not 
> "elements".

Sorry but I read the above 3 or 4 times, but I failed to understand
what you're meaning.

There's one good reason for all objects to have an ID: userspace
should be able to detect if a graph object was removed.

I mean, let's suppose that the topology_version has changed, because
some links were removed and others added, among other changes.

If all objects have an object ID, it is easy (and quick, because all
it needs to do is to compare a u32 integer) for userspace to compare the
previously retrieved topology with the new one and check what objects
were dropped/added by checking the object ID.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2015-09-08 10:05 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-19 11:01 [PATCH v6 0/8] MC preparation patches Mauro Carvalho Chehab
2015-08-19 11:01 ` [PATCH v6 1/8] [media] media: create a macro to get entity ID Mauro Carvalho Chehab
2015-08-19 11:01   ` Mauro Carvalho Chehab
2015-08-21  0:40   ` Laurent Pinchart
2015-08-21  0:40     ` Laurent Pinchart
2015-08-21  8:42     ` Mauro Carvalho Chehab
2015-08-21  8:42       ` Mauro Carvalho Chehab
2015-08-21 17:27       ` Laurent Pinchart
2015-08-21 17:27         ` Laurent Pinchart
2015-08-21 17:45         ` Mauro Carvalho Chehab
2015-08-21 17:45           ` Mauro Carvalho Chehab
2015-08-21 18:11           ` Laurent Pinchart
2015-08-21 18:11             ` Laurent Pinchart
2015-08-21 20:46             ` Mauro Carvalho Chehab
2015-08-21 20:46               ` Mauro Carvalho Chehab
2015-08-19 11:01 ` [PATCH v6 2/8] [media] media: add a common struct to be embed on media graph objects Mauro Carvalho Chehab
2015-08-19 11:09   ` Hans Verkuil
2015-08-21  1:02   ` Laurent Pinchart
2015-08-21  8:07     ` Hans Verkuil
2015-09-07 21:49       ` Laurent Pinchart
2015-09-08 10:05         ` Mauro Carvalho Chehab
2015-08-21  9:57     ` Mauro Carvalho Chehab
2015-08-19 11:01 ` [PATCH v6 3/8] [media] media: use media_gobj inside entities Mauro Carvalho Chehab
2015-08-21  1:10   ` Laurent Pinchart
2015-08-21 10:09     ` Mauro Carvalho Chehab
2015-08-21 17:51       ` Laurent Pinchart
2015-08-21 21:01         ` Mauro Carvalho Chehab
2015-08-21 22:47           ` Laurent Pinchart
2015-08-24  9:18             ` Mauro Carvalho Chehab
2015-08-19 11:01 ` [PATCH v6 4/8] [media] media: use media_gobj inside pads Mauro Carvalho Chehab
2015-08-19 11:01 ` [PATCH v6 5/8] [media] media: use media_gobj inside links Mauro Carvalho Chehab
2015-08-19 11:11   ` Hans Verkuil
2015-08-19 11:01 ` [PATCH v6 6/8] [media] media: add messages when media device gets (un)registered Mauro Carvalho Chehab
2015-08-19 11:11   ` Hans Verkuil
2015-08-21  1:35   ` Laurent Pinchart
2015-08-21 10:25     ` Mauro Carvalho Chehab
2015-08-19 11:01 ` [PATCH v6 7/8] [media] media: add a debug message to warn about gobj creation/removal Mauro Carvalho Chehab
2015-08-19 11:12   ` Hans Verkuil
2015-08-21  1:32   ` Laurent Pinchart
2015-08-21 10:19     ` Mauro Carvalho Chehab
2015-08-21 17:54       ` Laurent Pinchart
2015-08-21 21:09         ` Mauro Carvalho Chehab
2015-08-21 22:54           ` Laurent Pinchart
2015-08-24  9:40             ` Mauro Carvalho Chehab
2015-08-19 11:01 ` [PATCH v6 8/8] [media] media: rename the function that create pad links Mauro Carvalho Chehab
2015-08-19 11:01   ` Mauro Carvalho Chehab
2015-08-19 11:01   ` Mauro Carvalho Chehab
2015-08-19 11:01   ` Mauro Carvalho Chehab

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.