Skip to contentSkip to conversation

MC next generation patches

PATCH In review Mauro Carvalho Chehab 12 participants 247 messages Aug 30, 2015 – Feb 16, 2016 13 messages not in the archive Page 1 of 3

Subsystems (15)
lore
Share & tools
lore
#0 lore raw

v8 cover MC next generation patches

That's the 8th version of the MC next generation patches.

Differences from version 7:

- Patches reworked to make the reviewers happy;
- Bug fixes;
- ALSA changes got their own separate patches;
- Javier patches got integrated into this series;
- media-entity.h structs are now properly documented;
- Tested on both au0828 and omap3isp.

Due to the complexity of this change, other platform drivers may require some fixes.

As the patch series sent before, this is not meant to be sent upstream yet. Its goal is to merge it for Kernel 4.4, in order to give people enough time to review and fix pending issues.

Regards,
Mauro

Javier Martinez Canillas (6):
[media] staging: omap4iss: get entity ID using media_entity_id() [media] omap3isp: get entity ID using media_entity_id() [media] media: use entity.graph_obj.mdev instead of .parent [media] media: remove media entity .parent field [media] omap3isp: separate links creation from entities init [media] omap3isp: create links after all subdevs have been bound

Mauro Carvalho Chehab (49):
[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 [media] uapi/media.h: Declare interface types for V4L2 and DVB [media] media: add functions to allow creating interfaces [media] uapi/media.h: Declare interface types for ALSA [media] media: Don't accept early-created links
[media] media: convert links from array to list
[media] media: make add link more generic
[media] media: make media_link more generic to handle interace links [media] media: make link debug printk more generic
[media] media: add support to link interfaces and entities [media] media-entity: add a helper function to create interface [media] dvbdev: add support for interfaces
[media] media: add a linked list to track interfaces by mdev [media] dvbdev: add support for indirect interface links [media] uapi/media.h: Fix entity namespace
[media] replace all occurrences of MEDIA_ENT_T_DEVNODE_V4L [media] replace all occurrences of MEDIA_ENT_T_DEVNODE_DVB [media] media: add macros to check if subdev or V4L2 DMA [media] media: use macros to check for V4L2 subdev entities [media] omap3/omap4/davinci: get rid of MEDIA_ENT_T_V4L2_SUBDEV abuse [media] s5c73m3: fix subdev type
[media] s5k5baf: fix subdev type
[media] davinci_vbpe: stop MEDIA_ENT_T_V4L2_SUBDEV abuse [media] omap4iss: stop MEDIA_ENT_T_V4L2_SUBDEV abuse [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs [media] media controller: get rid of entity subtype on Kernel [media] media.h: don't use legacy entity macros at Kernel [media] DocBook: update descriptions for the media controller entities [media] dvb: modify core to implement interfaces/entities at MC new
gen
[media] media: report if a pad is sink or source at debug msg [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl [media] media: Use a macro to interate between all interfaces [media] media: move mdev list init to gobj
[media] media-device: add pads and links to media_device [media] media_device: add a topology version field
[media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl [media] media-entity: unregister entity links
[media] remove interface links at media_entity_unregister() [media] media-device: remove interfaces and interface links [media] v4l2-core: create MC interfaces for devnodes [media] au0828: unregister MC at the end
[media] media-entity.h: document all the structs

 .../DocBook/media/v4l/media-ioc-enum-entities.xml  |  57 +--
 Documentation/media-framework.txt                  |   2 +-
 drivers/media/dvb-core/dmxdev.c                    |   4 +-
 drivers/media/dvb-core/dvb_ca_en50221.c            |   2 +-
 drivers/media/dvb-core/dvb_frontend.c              |  11 +-
 drivers/media/dvb-core/dvb_net.c                   |   2 +-
 drivers/media/dvb-core/dvbdev.c                    | 278 +++++++++---
 drivers/media/dvb-core/dvbdev.h                    |  10 +-
 drivers/media/firewire/firedtv-ci.c                |   2 +-
 drivers/media/i2c/s5c73m3/s5c73m3-core.c           |   8 +-
 drivers/media/i2c/s5k5baf.c                        |   4 +-
 drivers/media/i2c/smiapp/smiapp-core.c             |   4 +-
 drivers/media/media-device.c                       | 245 +++++++++--
 drivers/media/media-entity.c                       | 473 +++++++++++++++++----
 drivers/media/pci/bt8xx/dst_ca.c                   |   3 +-
 drivers/media/pci/ddbridge/ddbridge-core.c         |   2 +-
 drivers/media/pci/ngene/ngene-core.c               |   2 +-
 drivers/media/pci/ttpci/av7110.c                   |   2 +-
 drivers/media/pci/ttpci/av7110_av.c                |   4 +-
 drivers/media/pci/ttpci/av7110_ca.c                |   2 +-
 drivers/media/platform/exynos4-is/common.c         |   3 +-
 drivers/media/platform/exynos4-is/fimc-capture.c   |   5 +-
 drivers/media/platform/exynos4-is/fimc-isp-video.c |   9 +-
 drivers/media/platform/exynos4-is/fimc-lite.c      |  18 +-
 drivers/media/platform/exynos4-is/media-dev.c      |  25 +-
 drivers/media/platform/exynos4-is/media-dev.h      |   8 +-
 drivers/media/platform/omap3isp/isp.c              | 202 +++++----
 drivers/media/platform/omap3isp/ispccdc.c          |  39 +-
 drivers/media/platform/omap3isp/ispccdc.h          |   1 +
 drivers/media/platform/omap3isp/ispccp2.c          |  35 +-
 drivers/media/platform/omap3isp/ispccp2.h          |   1 +
 drivers/media/platform/omap3isp/ispcsi2.c          |  33 +-
 drivers/media/platform/omap3isp/ispcsi2.h          |   1 +
 drivers/media/platform/omap3isp/isppreview.c       |  48 ++-
 drivers/media/platform/omap3isp/isppreview.h       |   1 +
 drivers/media/platform/omap3isp/ispresizer.c       |  46 +-
 drivers/media/platform/omap3isp/ispresizer.h       |   1 +
 drivers/media/platform/omap3isp/ispvideo.c         |  17 +-
 drivers/media/platform/s3c-camif/camif-capture.c   |   2 +-
 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           |  15 +-
 drivers/media/platform/vsp1/vsp1_wpf.c             |   2 +-
 drivers/media/platform/xilinx/xilinx-dma.c         |  10 +-
 drivers/media/platform/xilinx/xilinx-vipp.c        |   4 +-
 drivers/media/usb/au0828/au0828-core.c             |  18 +-
 drivers/media/usb/au0828/au0828-video.c            |   8 +-
 drivers/media/usb/cx231xx/cx231xx-cards.c          |   6 +-
 drivers/media/usb/cx231xx/cx231xx-video.c          |   8 +-
 drivers/media/usb/uvc/uvc_entity.c                 |   2 +-
 drivers/media/v4l2-core/v4l2-dev.c                 | 105 ++++-
 drivers/media/v4l2-core/v4l2-device.c              |  10 +-
 drivers/media/v4l2-core/v4l2-subdev.c              |   6 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipe.c   |   9 +-
 drivers/staging/media/davinci_vpfe/dm365_ipipeif.c |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_isif.c    |  15 +-
 drivers/staging/media/davinci_vpfe/dm365_resizer.c |  33 +-
 .../staging/media/davinci_vpfe/vpfe_mc_capture.c   |  10 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.c    |  17 +-
 drivers/staging/media/omap4iss/iss.c               |  32 +-
 drivers/staging/media/omap4iss/iss_csi2.c          |  13 +-
 drivers/staging/media/omap4iss/iss_ipipe.c         |   9 +-
 drivers/staging/media/omap4iss/iss_ipipeif.c       |  15 +-
 drivers/staging/media/omap4iss/iss_resizer.c       |  13 +-
 drivers/staging/media/omap4iss/iss_video.c         |   9 +-
 include/media/media-device.h                       |  34 +-
 include/media/media-entity.h                       | 305 +++++++++++--
 include/media/v4l2-dev.h                           |   1 +
 include/uapi/linux/media.h                         | 205 ++++++++-
 70 files changed, 1924 insertions(+), 627 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v8 1/55 media: create a macro to get entity ID

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

drivers/media/media-device.c +4 -4
index c55ab5029323..e429605ca2c3 100644
@@ -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;
 }
drivers/media/media-entity.c +4 -4
index 949e5f92cbdc..cb0ac4e0dfa5 100644
@@ -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;
 		}
drivers/media/platform/vsp1/vsp1_video.c +2 -2
index 17f08973f835..debe4e539df6 100644
@@ -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) {
include/media/media-entity.h +5 -0
index 8b21a4d920d9..0a66fc225559 100644
@@ -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
 
Signature · 1 line
2.4.3
Reviewed-by Tested-by on v8 1/55
#2 lore raw

Re: [PATCH v8 01/55] [media] media: create a macro to get entity ID

Quoted 6 lines · Mauro Carvalho Chehab

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

Best regards,
Javier

maintainer Acked-by on v8 1/55
#3 lore raw

Re: [PATCH v8 01/55] [media] media: create a macro to get entity ID

In reply to Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

Quoted 5 lines · On Sunday 30 August 2015 00:06:12 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.

Quoted 98 lines
drivers/media/media-device.c +3 -3
index c55ab5029323..e429605ca2c3 100644
@@ -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)
{

drivers/media/media-device.c +1 -1
-	upad->entity = kpad->entity->id;
+	upad->entity = media_entity_id(kpad->entity);
 	upad->index = kpad->index;
 	upad->flags = kpad->flags;
 }
drivers/media/media-entity.c +4 -4
index 949e5f92cbdc..cb0ac4e0dfa5 100644
@@ -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;
drivers/media/media-entity.c +0 -0
 		}
(quoted diff) +0 -0

b/drivers/media/platform/vsp1/vsp1_video.c index 17f08973f835..debe4e539df6 100644

drivers/media/platform/vsp1/vsp1_video.c +2 -2
@@ -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) {
include/media/media-entity.h +5 -0
index 8b21a4d920d9..0a66fc225559 100644
@@ -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
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

PATCH v8 2/55 staging: omap4iss: get entity ID using media_entity_id()

In reply to Mauro Carvalho Chehab

From: Javier Martinez Canillas <[email protected]>

Assessing media_entity ID should now use media_entity_id() macro to obtain the entity ID, as a next patch will remove the .id field from struct media_entity .

So, get rid of it, otherwise the omap4iss driver will fail to build.

drivers/staging/media/omap4iss/iss.c +1 -1
index 9bfb725b9986..e54a7afd31de 100644
@@ -607,7 +607,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
 			 * crashed. Mark it as such, the ISS will be reset when
 			 * applications will release it.
 			 */
-			iss->crashed |= 1U << subdev->entity.id;
+			iss->crashed |= 1U << media_entity_id(&subdev->entity);
 			failure = -ETIMEDOUT;
 		}
 	}
drivers/staging/media/omap4iss/iss_video.c +1 -1
index bae67742706f..25e9e7a6b99d 100644
@@ -784,7 +784,7 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
 	entity = &video->video.entity;
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph)))
-		pipe->entities |= 1 << entity->id;
+		pipe->entities |= 1 << media_entity_id(entity);
 
 	/* Verify that the currently configured format matches the output of
 	 * the connected subdev.
Signature · 1 line
2.4.3
maintainer Acked-by on v8 2/55
#5 lore raw

Re: [PATCH v8 02/55] [media] staging: omap4iss: get entity ID using media_entity_id()

Hi Javier,

Thank you for the patch.

Quoted 3 lines · On Sunday 30 August 2015 00:06:13 Mauro Carvalho Chehab wrote:

From: Javier Martinez Canillas <[email protected]>

Assessing media_entity ID should now use media_entity_id() macro to

Did you mean "accessing" ?

Quoted 8 lines

obtain the entity ID, as a next patch will remove the .id field from struct media_entity .

So, get rid of it, otherwise the omap4iss driver will fail to build.

With the typo fixed,

Quoted 28 lines
(quoted diff) +0 -0

b/drivers/staging/media/omap4iss/iss.c index 9bfb725b9986..e54a7afd31de 100644

drivers/staging/media/omap4iss/iss.c +1 -1
@@ -607,7 +607,7 @@ static int iss_pipeline_disable(struct iss_pipeline
 *pipe, * crashed. Mark it as such, the ISS will be reset when
 			 * applications will release it.
 			 */
-			iss->crashed |= 1U << subdev->entity.id;
+			iss->crashed |= 1U << media_entity_id(&subdev->entity);
 			failure = -ETIMEDOUT;
 		}
 	}
(quoted diff) +0 -0

b/drivers/staging/media/omap4iss/iss_video.c index bae67742706f..25e9e7a6b99d 100644

drivers/staging/media/omap4iss/iss_video.c +1 -1
@@ -784,7 +784,7 @@ iss_video_streamon(struct file *file, void *fh, enum
 v4l2_buf_type type) entity = &video->video.entity;
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph)))
-		pipe->entities |= 1 << entity->id;
+		pipe->entities |= 1 << media_entity_id(entity);
 
 	/* Verify that the currently configured format matches the output of
 	 * the connected subdev.
Signature · 3 lines
Regards,

Laurent Pinchart
#6 lore raw

Re: [PATCH v8 02/55] [media] staging: omap4iss: get entity ID using media_entity_id()

Hello Laurent,

Quoted 11 lines · Laurent Pinchart

Hi Javier,

Thank you for the patch.

Quoted 3 lines · On Sunday 30 August 2015 00:06:13 Mauro Carvalho Chehab wrote:

From: Javier Martinez Canillas <[email protected]>

Assessing media_entity ID should now use media_entity_id() macro to

Did you mean "accessing" ?

Sigh, yet another typo error that seems to be due copy and paste.

Quoted 5 lines
Quoted 5 lines

obtain the entity ID, as a next patch will remove the .id field from struct media_entity .

So, get rid of it, otherwise the omap4iss driver will fail to build.

Quoted 8 lines
Quoted 3 lines

With the typo fixed,

Thanks.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Open Source Group
Samsung Research America
#7 lore raw

PATCH v8 3/55 omap3isp: get entity ID using media_entity_id()

In reply to Mauro Carvalho Chehab

From: Javier Martinez Canillas <[email protected]>

Assessing media_entity ID should now use media_entity_id() macro to obtain the entity ID, as a next patch will remove the .id field from struct media_entity .

So, get rid of it, otherwise the omap3isp driver will fail to build.

drivers/media/platform/omap3isp/isp.c +5 -2
index 56e683b19a73..e08183f9d0f7 100644
@@ -975,6 +975,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 	struct v4l2_subdev *subdev;
 	int failure = 0;
 	int ret;
+	u32 id;
 
 	/*
 	 * We need to stop all the modules after CCDC first or they'll
@@ -1027,8 +1028,10 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 		if (ret) {
 			dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
 			isp->stop_failure = true;
-			if (subdev == &isp->isp_prev.subdev)
-				isp->crashed |= 1U << subdev->entity.id;
+			if (subdev == &isp->isp_prev.subdev) {
+				id = media_entity_id(&subdev->entity);
+				isp->crashed |= 1U << id;
+			}
 			failure = -ETIMEDOUT;
 		}
 	}
drivers/media/platform/omap3isp/ispccdc.c +1 -1
index 3b10304b580b..d96e3be5e252 100644
@@ -1608,7 +1608,7 @@ static int ccdc_isr_buffer(struct isp_ccdc_device *ccdc)
 	/* Wait for the CCDC to become idle. */
 	if (ccdc_sbl_wait_idle(ccdc, 1000)) {
 		dev_info(isp->dev, "CCDC won't become idle!\n");
-		isp->crashed |= 1U << ccdc->subdev.entity.id;
+		isp->crashed |= 1U << media_entity_id(&ccdc->subdev.entity);
 		omap3isp_pipeline_cancel_stream(pipe);
 		return 0;
 	}
drivers/media/platform/omap3isp/ispvideo.c +5 -3
index 3094572f8897..6c89dc40df85 100644
@@ -235,7 +235,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		struct isp_video *__video;
 
-		pipe->entities |= 1 << entity->id;
+		pipe->entities |= 1 << media_entity_id(entity);
 
 		if (far_end != NULL)
 			continue;
@@ -891,6 +891,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 	struct v4l2_ext_control ctrl;
 	unsigned int i;
 	int ret;
+	u32 id;
 
 	/* Memory-to-memory pipelines have no external subdev. */
 	if (pipe->input != NULL)
@@ -898,7 +899,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 
 	for (i = 0; i < ARRAY_SIZE(ents); i++) {
 		/* Is the entity part of the pipeline? */
-		if (!(pipe->entities & (1 << ents[i]->id)))
+		if (!(pipe->entities & (1 << media_entity_id(ents[i]))))
 			continue;
 
 		/* ISP entities have always sink pad == 0. Find source. */
@@ -950,7 +951,8 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 
 	pipe->external_rate = ctrl.value64;
 
-	if (pipe->entities & (1 << isp->isp_ccdc.subdev.entity.id)) {
+	id = media_entity_id(&isp->isp_ccdc.subdev.entity);
+	if (pipe->entities & (1 << id)) {
 		unsigned int rate = UINT_MAX;
 		/*
 		 * Check that maximum allowed CCDC pixel rate isn't
Signature · 1 line
2.4.3
Acked-by on v8 3/55
#8 lore raw

Re: [PATCH v8 03/55] [media] omap3isp: get entity ID using media_entity_id()

Quoted 10 lines · Mauro Carvalho Chehab

From: Javier Martinez Canillas <[email protected]>

Assessing media_entity ID should now use media_entity_id() macro to obtain the entity ID, as a next patch will remove the .id field from struct media_entity .

So, get rid of it, otherwise the omap3isp driver will fail to build.

Regards,

Hans

Quoted 80 lines
drivers/media/platform/omap3isp/isp.c +5 -2
index 56e683b19a73..e08183f9d0f7 100644
@@ -975,6 +975,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 	struct v4l2_subdev *subdev;
 	int failure = 0;
 	int ret;
+	u32 id;
 
 	/*
 	 * We need to stop all the modules after CCDC first or they'll
@@ -1027,8 +1028,10 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
 		if (ret) {
 			dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
 			isp->stop_failure = true;
-			if (subdev == &isp->isp_prev.subdev)
-				isp->crashed |= 1U << subdev->entity.id;
+			if (subdev == &isp->isp_prev.subdev) {
+				id = media_entity_id(&subdev->entity);
+				isp->crashed |= 1U << id;
+			}
 			failure = -ETIMEDOUT;
 		}
 	}
drivers/media/platform/omap3isp/ispccdc.c +1 -1
index 3b10304b580b..d96e3be5e252 100644
@@ -1608,7 +1608,7 @@ static int ccdc_isr_buffer(struct isp_ccdc_device *ccdc)
 	/* Wait for the CCDC to become idle. */
 	if (ccdc_sbl_wait_idle(ccdc, 1000)) {
 		dev_info(isp->dev, "CCDC won't become idle!\n");
-		isp->crashed |= 1U << ccdc->subdev.entity.id;
+		isp->crashed |= 1U << media_entity_id(&ccdc->subdev.entity);
 		omap3isp_pipeline_cancel_stream(pipe);
 		return 0;
 	}
drivers/media/platform/omap3isp/ispvideo.c +5 -3
index 3094572f8897..6c89dc40df85 100644
@@ -235,7 +235,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 	while ((entity = media_entity_graph_walk_next(&graph))) {
 		struct isp_video *__video;
 
-		pipe->entities |= 1 << entity->id;
+		pipe->entities |= 1 << media_entity_id(entity);
 
 		if (far_end != NULL)
 			continue;
@@ -891,6 +891,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 	struct v4l2_ext_control ctrl;
 	unsigned int i;
 	int ret;
+	u32 id;
 
 	/* Memory-to-memory pipelines have no external subdev. */
 	if (pipe->input != NULL)
@@ -898,7 +899,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 
 	for (i = 0; i < ARRAY_SIZE(ents); i++) {
 		/* Is the entity part of the pipeline? */
-		if (!(pipe->entities & (1 << ents[i]->id)))
+		if (!(pipe->entities & (1 << media_entity_id(ents[i]))))
 			continue;
 
 		/* ISP entities have always sink pad == 0. Find source. */
@@ -950,7 +951,8 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
 
 	pipe->external_rate = ctrl.value64;
 
-	if (pipe->entities & (1 << isp->isp_ccdc.subdev.entity.id)) {
+	id = media_entity_id(&isp->isp_ccdc.subdev.entity);
+	if (pipe->entities & (1 << id)) {
 		unsigned int rate = UINT_MAX;
 		/*
 		 * Check that maximum allowed CCDC pixel rate isn't
maintainer Acked-by on v8 3/55
#9 lore raw

Re: [PATCH v8 03/55] [media] omap3isp: get entity ID using media_entity_id()

In reply to Mauro Carvalho Chehab

Hi Javier,

Thank you for the patch.

Quoted 3 lines · On Sunday 30 August 2015 00:06:14 Mauro Carvalho Chehab wrote:

From: Javier Martinez Canillas <[email protected]>

Assessing media_entity ID should now use media_entity_id() macro to

Did you mean "accessing" ?

Quoted 7 lines

obtain the entity ID, as a next patch will remove the .id field from struct media_entity .

So, get rid of it, otherwise the omap3isp driver will fail to build.

With the typo fixed,

Quoted 83 lines
(quoted diff) +0 -0

b/drivers/media/platform/omap3isp/isp.c index 56e683b19a73..e08183f9d0f7 100644

drivers/media/platform/omap3isp/isp.c +5 -2
@@ -975,6 +975,7 @@ static int isp_pipeline_disable(struct isp_pipeline
 *pipe) struct v4l2_subdev *subdev;
 	int failure = 0;
 	int ret;
+	u32 id;
 
 	/*
 	 * We need to stop all the modules after CCDC first or they'll
@@ -1027,8 +1028,10 @@ static int isp_pipeline_disable(struct isp_pipeline
 *pipe) if (ret) {
 			dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
 			isp->stop_failure = true;
-			if (subdev == &isp->isp_prev.subdev)
-				isp->crashed |= 1U << subdev->entity.id;
+			if (subdev == &isp->isp_prev.subdev) {
+				id = media_entity_id(&subdev->entity);
+				isp->crashed |= 1U << id;
+			}
 			failure = -ETIMEDOUT;
 		}
 	}
(quoted diff) +0 -0

b/drivers/media/platform/omap3isp/ispccdc.c index
3b10304b580b..d96e3be5e252 100644

drivers/media/platform/omap3isp/ispccdc.c +1 -1
@@ -1608,7 +1608,7 @@ static int ccdc_isr_buffer(struct isp_ccdc_device
 *ccdc) /* Wait for the CCDC to become idle. */
 	if (ccdc_sbl_wait_idle(ccdc, 1000)) {
 		dev_info(isp->dev, "CCDC won't become idle!\n");
-		isp->crashed |= 1U << ccdc->subdev.entity.id;
+		isp->crashed |= 1U << media_entity_id(&ccdc->subdev.entity);
 		omap3isp_pipeline_cancel_stream(pipe);
 		return 0;
 	}
(quoted diff) +0 -0

b/drivers/media/platform/omap3isp/ispvideo.c index 3094572f8897..6c89dc40df85 100644

drivers/media/platform/omap3isp/ispvideo.c +3 -2
@@ -235,7 +235,7 @@ static int isp_video_get_graph_data(struct isp_video
 *video, while ((entity = media_entity_graph_walk_next(&graph))) {
 		struct isp_video *__video;
 
-		pipe->entities |= 1 << entity->id;
+		pipe->entities |= 1 << media_entity_id(entity);
 
 		if (far_end != NULL)
 			continue;
@@ -891,6 +891,7 @@ static int isp_video_check_external_subdevs(struct
 isp_video *video, struct v4l2_ext_control ctrl;
 	unsigned int i;
 	int ret;
+	u32 id;
 
 	/* Memory-to-memory pipelines have no external subdev. */
 	if (pipe->input != NULL)
@@ -898,7 +899,7 @@ static int isp_video_check_external_subdevs(struct
 isp_video *video,
 
 	for (i = 0; i < ARRAY_SIZE(ents); i++) {
 		/* Is the entity part of the pipeline? */
-		if (!(pipe->entities & (1 << ents[i]->id)))
+		if (!(pipe->entities & (1 << media_entity_id(ents[i]))))
 			continue;
 
drivers/media/platform/omap3isp/ispvideo.c +2 -1
 		/* ISP entities have always sink pad == 0. Find source. */
@@ -950,7 +951,8 @@ static int isp_video_check_external_subdevs(struct
 isp_video *video,
 
 	pipe->external_rate = ctrl.value64;
 
-	if (pipe->entities & (1 << isp->isp_ccdc.subdev.entity.id)) {
+	id = media_entity_id(&isp->isp_ccdc.subdev.entity);
+	if (pipe->entities & (1 << id)) {
 		unsigned int rate = UINT_MAX;
 		/*

* Check that maximum allowed CCDC pixel rate isn't

Signature · 3 lines
Regards,

Laurent Pinchart
#10 lore raw

Re: [PATCH v8 03/55] [media] omap3isp: get entity ID using media_entity_id()

Hello Laurent,

Quoted 11 lines · Laurent Pinchart

Hi Javier,

Thank you for the patch.

Quoted 3 lines · On Sunday 30 August 2015 00:06:14 Mauro Carvalho Chehab wrote:

From: Javier Martinez Canillas <[email protected]>

Assessing media_entity ID should now use media_entity_id() macro to

Did you mean "accessing" ?

Yes I did, sorry for the typo. Maybe Mauro can fix it when applying?

Quoted 12 lines
Quoted 7 lines

obtain the entity ID, as a next patch will remove the .id field from struct media_entity .

So, get rid of it, otherwise the omap3isp driver will fail to build.

With the typo fixed,

Thanks.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Open Source Group
Samsung Research America
#11 lore raw

PATCH v8 4/55 media: add a common struct to be embed on media graph objects

In reply to 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.

drivers/media/media-entity.c +32 -0
index cb0ac4e0dfa5..4834172bf6f8 100644
@@ -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.
include/media/media-entity.h +61 -0

79 lines not on this page · raw message

Signature · 1 line
2.4.3
#12 lore raw

Re: [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects

Hi Mauro,

Quoted 84 lines · 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.

drivers/media/media-entity.c +32 -0
index cb0ac4e0dfa5..4834172bf6f8 100644
@@ -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.
include/media/media-entity.h +23 -0
index 0a66fc225559..b1854239a476 100644
@@ -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 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

include/media/media-entity.h line 63

Quoted 10 lines
include/media/media-entity.h +10 -0
+ *		MEDIA_BITS_PER_LOCAL_ID	to store a per-type ID
+ *		(called as "local ID").
+ *
+ * All objects on the media graph should have this struct embedded
+ */
+struct media_gobj {
+	u32			id;
+};
+
+

Two newlines. Looks like one would be enough. A minor matter though.

Quoted 31 lines
include/media/media-entity.h +20 -0
 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
 

include/media/media-entity.h struct media_entity_graph { · line 188

Quoted 5 lines
include/media/media-entity.h +2 -0
@@ -131,6 +184,14 @@ struct media_entity_graph {
 	int top;
 };
 
+#define gobj_to_entity(gobj) \
+		container_of(gobj, struct media_entity, graph_obj)

Just on naming: I'd call this media_gobj_to_entity, as the type is called media_gobj and secondly the common media prefix is used throughout the MC API.

Same for the rest of similar macros in further patches.

Quoted 9 lines
include/media/media-entity.h +6 -0
+
+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);
Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#13 lore raw

Re: [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects

Hi Sakari,

Em Wed, 09 Sep 2015 10:01:49 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 9 lines

Hi Mauro,

Quoted 6 lines · 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.

Thanks for the review!

There are already too much patches on the top of this one. So, I'll be addressing anything we've agreed on at a separate patch series.

I guess this makes easier for reviewers, and avoid spending hours with rebases and re-tests. On my experience, rebasing a long series like this is not a good idea, as errors can be introduced on every rebase. So, doing a separate patch is usually better.

Quoted 82 lines
Quoted 82 lines
drivers/media/media-entity.c +32 -0
index cb0ac4e0dfa5..4834172bf6f8 100644
@@ -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.
include/media/media-entity.h +27 -0
index 0a66fc225559..b1854239a476 100644
@@ -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 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").
+ *
+ * All objects on the media graph should have this struct embedded
Quoted 8 lines

include/media/media-entity.h line 63

Quoted 6 lines
include/media/media-entity.h +6 -0
+ */
+struct media_gobj {
+	u32			id;
+};
+
+

Two newlines. Looks like one would be enough. A minor matter though.

Ok, I'll be dropping the extra line.

Quoted 34 lines
Quoted 34 lines
include/media/media-entity.h +20 -0
 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;
 };
 
Quoted 8 lines

include/media/media-entity.h struct media_entity_graph { · line 188

Quoted 2 lines
include/media/media-entity.h +2 -0
+#define gobj_to_entity(gobj) \
+		container_of(gobj, struct media_entity, graph_obj)

Just on naming: I'd call this media_gobj_to_entity, as the type is called media_gobj and secondly the common media prefix is used throughout the MC API.

Same for the rest of similar macros in further patches.

As commented on my answer to your review on patch 14/55, the above is the right namespace for this kind of macro. Nobody uses big names for those container_of macros, as the hole idea is to have a short name at the form of:

	"to_bar"
or
	"foo_to_bar"
Quoted 10 lines
Quoted 9 lines
include/media/media-entity.h +6 -0
+
+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);
Reviewed-by on v8 4/55
#14 lore raw

Re: [PATCH v8 04/55] [media] media: add a common struct to be embed on media graph objects

In reply to Mauro Carvalho Chehab
Quoted 10 lines · 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.

Best regards,
Javier

#15 lore raw

PATCH v8 5/55 media: use media_gobj inside entities

In reply to Mauro Carvalho Chehab

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

For now, we'll keep the already existing entity ID. Such field need to be dropped at some point, but for now, let's not do this, to avoid needing to review all drivers and the userspace apps.

drivers/media/media-device.c +3 -5
index e429605ca2c3..81d6a130efef 100644
@@ -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;
drivers/media/media-entity.c +6 -1
index 4834172bf6f8..888cb88e19bf 100644
@@ -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;
+	}
 }
 
 /**
include/media/media-device.h +2 -1
index a44f18fdf321..f6deef6e5820 100644
@@ -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 */
include/media/media-entity.h +4 -5
index b1854239a476..bb74b5883cbb 100644
@@ -33,10 +33,10 @@
 /**
  * enum media_gobj_type - type of a graph object
  *
+ * @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)
Signature · 1 line
2.4.3
Reviewed-by Tested-by on v8 5/55
#16 lore raw

Re: [PATCH v8 05/55] [media] media: use media_gobj inside entities

Quoted 4 lines · Mauro Carvalho Chehab

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

Quoted 8 lines

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.

Best regards,
Javier

#17 lore raw

PATCH v8 6/55 media: use media_gobj inside pads

In reply to 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.

drivers/media/media-device.c +11 -0
index 81d6a130efef..3bdda16584fe 100644
@@ -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);
drivers/media/media-entity.c +3 -0
index 888cb88e19bf..377c6655c5d0 100644
@@ -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;
 	}
 }
 
include/media/media-device.h +2 -0
index f6deef6e5820..9493721f630e 100644
@@ -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;
 
include/media/media-entity.h +3 -0
index bb74b5883cbb..ce4c654486d6 100644
@@ -34,9 +34,11 @@
  * enum media_gobj_type - type of a graph object
  *
  * @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_*) */
Signature · 1 line
2.4.3
#18 lore raw

Re: [PATCH v8 06/55] [media] media: use media_gobj inside pads

Hi Mauro,

Quoted 19 lines · 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.

drivers/media/media-device.c +0 -0
index 81d6a130efef..3bdda16584fe 100644

drivers/media/media-device.c EXPORT_SYMBOL_GPL(media_device_unregister); · line 430

Quoted 4 lines
drivers/media/media-device.c +1 -0
@@ -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;

unsigned int?

Quoted 18 lines
drivers/media/media-device.c +7 -0
+
 	/* 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;

drivers/media/media-device.c EXPORT_SYMBOL_GPL(media_device_register_entity); · line 461

Quoted 4 lines
drivers/media/media-device.c +1 -0
@@ -450,12 +458,15 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
  */
 void media_device_unregister_entity(struct media_entity *entity)
 {
+	int i;

Ditto. It'd be nice to declare short temporary and counter variables as last (i.e. after mdev).

Quoted 69 lines
drivers/media/media-device.c +2 -0
 	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);
drivers/media/media-entity.c +3 -0
index 888cb88e19bf..377c6655c5d0 100644
@@ -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;
 	}
 }
 
include/media/media-device.h +2 -0
index f6deef6e5820..9493721f630e 100644
@@ -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;
 
include/media/media-entity.h +3 -0
index bb74b5883cbb..ce4c654486d6 100644
@@ -34,9 +34,11 @@
  * enum media_gobj_type - type of a graph object
  *
  * @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_*) */
Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
Reviewed-by Tested-by on v8 6/55
#19 lore raw

Re: [PATCH v8 06/55] [media] media: use media_gobj inside pads

In reply to Mauro Carvalho Chehab
Quoted 6 lines · 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.

Quoted 8 lines

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.

Best regards,
Javier

#20 lore raw

PATCH v8 7/55 media: use media_gobj inside links

In reply to 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.

drivers/media/media-device.c +9 -0
index 3bdda16584fe..065f6f08da37 100644
@@ -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);
drivers/media/media-entity.c +9 -0
index 377c6655c5d0..36d725ec5f3d 100644
@@ -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;
 
include/media/media-device.h +2 -0
index 9493721f630e..05414e351f8e 100644
@@ -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;
 
include/media/media-entity.h +3 -0
index ce4c654486d6..cd08a96bfbaa 100644
@@ -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 */
Signature · 1 line
2.4.3
Reviewed-by Tested-by on v8 7/55
#21 lore raw

Re: [PATCH v8 07/55] [media] media: use media_gobj inside links

Quoted 9 lines · 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.

Best regards,
Javier

#22 lore raw

PATCH v8 8/55 media: add messages when media device gets (un)registered

In reply to 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.

drivers/media/media-device.c +5 -0
index 065f6f08da37..0f3844470147 100644
@@ -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);
 
Signature · 1 line
2.4.3
Reviewed-by on v8 8/55
#23 lore raw

Re: [PATCH v8 08/55] [media] media: add messages when media device gets (un)registered

Quoted 10 lines · 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.

Best regards,
Javier

#24 lore raw

PATCH v8 9/55 media: add a debug message to warn about gobj creation/removal

In reply to 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.

drivers/media/media-entity.c +67 -1
index 36d725ec5f3d..6d515e149d7f 100644
@@ -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);
 }
 
 /**
include/media/media-entity.h +7 -0
index cd08a96bfbaa..af6646ddf6db 100644
@@ -61,6 +61,7 @@ enum media_gobj_type {
  * All objects on the media graph should have this struct embedded
  */
 struct media_gobj {
+	struct media_device	*mdev;
 	u32			id;
 };
 
@@ -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);
Signature · 1 line
2.4.3
Reviewed-by on v8 9/55
#25 lore raw

Re: [PATCH v8 09/55] [media] media: add a debug message to warn about gobj creation/removal

Quoted 10 lines · 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.

Best regards,
Javier

#26 lore raw

PATCH v8 10/55 media: rename the function that create pad links

In reply to Mauro Carvalho Chehab

With the new API, a link can be either between two PADs or between an interface and an entity. So, we need to use a better name for the function that create links between two pads.

So, rename the such function to 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
Documentation/media-framework.txt +1 -1
index 6903b2503577..b424de6c3bb3 100644
@@ -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);
 
drivers/media/dvb-core/dvbdev.c +4 -4
index 2fdcbb5f000a..65f59f2124b4 100644
@@ -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
drivers/media/i2c/s5c73m3/s5c73m3-core.c +2 -2
index 6d167428727d..c81bfbfea32f 100644
@@ -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);
 
drivers/media/i2c/s5k5baf.c +1 -1
index 30a9ca62e034..d3bff30bcb6f 100644
@@ -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);
drivers/media/i2c/smiapp/smiapp-core.c +2 -2
index 308613ea0aed..5aa49eb393a9 100644
@@ -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;
 		}
 
drivers/media/media-entity.c +2 -2
index 6d515e149d7f..35e52cd1fc5a 100644
@@ -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)
 {
drivers/media/platform/exynos4-is/media-dev.c +8 -8
index 4f5586a4cbff..3ba76940eef5 100644
@@ -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;
drivers/media/platform/omap3isp/isp.c +9 -9
index e08183f9d0f7..6351f35b0a65 100644
@@ -1865,7 +1865,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)
@@ -2004,51 +2004,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);
drivers/media/platform/omap3isp/ispccdc.c +1 -1
index d96e3be5e252..27555e4f4aa8 100644
@@ -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;
drivers/media/platform/omap3isp/ispccp2.c +1 -1
index e1b5f5bea541..b215eb5049d6 100644
@@ -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;
drivers/media/platform/omap3isp/ispcsi2.c +1 -1
index 6fff92f0813a..fcefc1e74881 100644
@@ -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;
drivers/media/platform/omap3isp/isppreview.c +2 -2
index b440c6342ca4..ad38d20c7770 100644
@@ -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;
drivers/media/platform/omap3isp/ispresizer.c +2 -2
index 3deb1ec4a973..b48ad4d4b834 100644
@@ -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;
drivers/media/platform/s3c-camif/camif-core.c +2 -2
index f47b332f0418..3e33c60be004 100644
@@ -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);
drivers/media/platform/vsp1/vsp1_drv.c +2 -2
index 4e61886384e3..9cd94a76a9ed 100644
@@ -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)
drivers/media/platform/vsp1/vsp1_rpf.c +1 -1
index 3294529a3108..b60a528a8fe8 100644
@@ -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 |
drivers/media/platform/vsp1/vsp1_wpf.c +1 -1
index 1d2b3a2f1573..d39aa4b8aea1 100644
@@ -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)
drivers/media/platform/xilinx/xilinx-vipp.c +2 -2
index 7b7cb9c28d2c..79d4be7ce9a5 100644
@@ -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) {
drivers/media/usb/au0828/au0828-core.c +3 -3
index 0378a2c99ebb..a55eb524ea21 100644
@@ -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
 }
drivers/media/usb/cx231xx/cx231xx-cards.c +3 -3
index 4a117a58c39a..3b5c9ae39ad3 100644
@@ -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
 }
drivers/media/usb/uvc/uvc_entity.c +1 -1
index 245445491516..429e428ccd93 100644
@@ -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;
drivers/staging/media/davinci_vpfe/dm365_ipipeif.c +1 -1
index 8fb676186898..d96bdaaae50e 100644
@@ -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;
drivers/staging/media/davinci_vpfe/dm365_isif.c +1 -1
index b1f01adfa7c8..df77288b0ec0 100644
@@ -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)
drivers/staging/media/davinci_vpfe/dm365_resizer.c +4 -4
index 692789aa22f4..ae942de3a23d 100644
@@ -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;
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c +5 -5
index 57426199ad7a..08c8a5f967d3 100644
@@ -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)
drivers/staging/media/omap4iss/iss.c +6 -6
index e54a7afd31de..7226553ceb2f 100644
@@ -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)
drivers/staging/media/omap4iss/iss_csi2.c +1 -1
index e936cfc218cb..6b4dcbfa9425 100644
@@ -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;
drivers/staging/media/omap4iss/iss_ipipeif.c +1 -1
index be5f80d7b5dc..44c432ef2ac5 100644
@@ -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)
drivers/staging/media/omap4iss/iss_resizer.c +1 -1
index 91e724085dba..b659e465cb56 100644
@@ -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)
include/media/media-entity.h +1 -1
index af6646ddf6db..e0e4b014ce62 100644
@@ -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);
Signature · 1 line
2.4.3
#27 lore raw

PATCH v8 10/55 media: rename the function that create pad links

Quoted 6 lines · Mauro Carvalho Chehab

With the new API, a link can be either between two PADs or between an interface and an entity. So, we need to use a better name for the function that create links between two pads.

So, rename the such function to media_create_pad_link().

Quoted 9 lines

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

Best regards,
Javier

A message that is not in the archive (sent off-list or not yet received): cover.1440902901.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

#29 lore raw

PATCH v8 40/55 media.h: don't use legacy entity macros at Kernel

Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__, in order to be sure that none of those old symbols are used inside the Kernel.

include/uapi/linux/media.h +2 -0
index cd486fc25f1e..4186891e5e81 100644
@@ -107,6 +107,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 3)
 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 4)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
@@ -120,6 +121,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
 
Signature · 1 line
2.4.3

A message that is not in the archive (sent off-list or not yet received): 720b750e2738f8c70535b01c9c3a3dddf044db69.1440902901.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

Acked-by
#31 lore raw

Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel

Quoted 5 lines · Mauro Carvalho Chehab

Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__, in order to be sure that none of those old symbols are used inside the Kernel.

Quoted 22 lines
include/uapi/linux/media.h +2 -0
index cd486fc25f1e..4186891e5e81 100644
@@ -107,6 +107,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 3)
 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 4)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
@@ -120,6 +121,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
 
#32 lore raw

PATCH v8 11/55 media: use entity.graph_obj.mdev instead of .parent

In reply to Mauro Carvalho Chehab

From: Javier Martinez Canillas <[email protected]>

The struct media_entity has a .parent field that stores a pointer to the parent struct media_device. But recently a media_gobj was embedded into the entities and since struct media_gojb already has a pointer to a struct media_device in the .mdev field, the .parent field becomes redundant and can be removed.

This patch replaces all the usage of .parent by .graph_obj.mdev so that field will become unused and can be removed on a later patch.

No functional changes.

The transformation was made using the following coccinelle spatch:

@@
struct media_entity *me;
@@

- me->parent
+ me->graph_obj.mdev

@@
struct media_entity *link;
@@

- link->source->entity->parent
+ link->source->entity->graph_obj.mdev

@@
struct exynos_video_entity *ve;
@@

- ve->vdev.entity.parent
+ ve->vdev.entity.graph_obj.mdev

drivers/media/media-device.c +4 -4
index 0f3844470147..138b18416460 100644
@@ -435,8 +435,8 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	int i;
 
 	/* Warn if we apparently re-register an entity */
-	WARN_ON(entity->parent != NULL);
-	entity->parent = mdev;
+	WARN_ON(entity->graph_obj.mdev != NULL);
+	entity->graph_obj.mdev = mdev;
 
 	spin_lock(&mdev->lock);
 	/* Initialize media_gobj embedded at the entity */
@@ -471,7 +471,7 @@ EXPORT_SYMBOL_GPL(media_device_register_entity);
 void media_device_unregister_entity(struct media_entity *entity)
 {
 	int i;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	if (mdev == NULL)
 		return;
@@ -484,7 +484,7 @@ void media_device_unregister_entity(struct media_entity *entity)
 	media_gobj_remove(&entity->graph_obj);
 	list_del(&entity->list);
 	spin_unlock(&mdev->lock);
-	entity->parent = NULL;
+	entity->graph_obj.mdev = NULL;
 }
 EXPORT_SYMBOL_GPL(media_device_unregister_entity);
 
drivers/media/media-entity.c +18 -16
index 35e52cd1fc5a..a23c93369a04 100644
@@ -332,7 +332,7 @@ EXPORT_SYMBOL_GPL(media_entity_graph_walk_next);
 __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 	struct media_entity *entity_err = entity;
 	int ret;
@@ -387,7 +387,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 			ret = entity->ops->link_validate(link);
 			if (ret < 0 && ret != -ENOIOCTLCMD) {
-				dev_dbg(entity->parent->dev,
+				dev_dbg(entity->graph_obj.mdev->dev,
 					"link validation failed for \"%s\":%u -> \"%s\":%u, error %d\n",
 					link->source->entity->name,
 					link->source->index,
@@ -401,7 +401,7 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 
 		if (!bitmap_full(active, entity->num_pads)) {
 			ret = -EPIPE;
-			dev_dbg(entity->parent->dev,
+			dev_dbg(entity->graph_obj.mdev->dev,
 				"\"%s\":%u must be connected by an enabled link\n",
 				entity->name,
 				(unsigned)find_first_zero_bit(
@@ -454,7 +454,7 @@ EXPORT_SYMBOL_GPL(media_entity_pipeline_start);
  */
 void media_entity_pipeline_stop(struct media_entity *entity)
 {
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct media_entity_graph graph;
 
 	mutex_lock(&mdev->graph_mutex);
@@ -490,8 +490,8 @@ struct media_entity *media_entity_get(struct media_entity *entity)
 	if (entity == NULL)
 		return NULL;
 
-	if (entity->parent->dev &&
-	    !try_module_get(entity->parent->dev->driver->owner))
+	if (entity->graph_obj.mdev->dev &&
+	    !try_module_get(entity->graph_obj.mdev->dev->driver->owner))
 		return NULL;
 
 	return entity;
@@ -511,8 +511,8 @@ void media_entity_put(struct media_entity *entity)
 	if (entity == NULL)
 		return;
 
-	if (entity->parent->dev)
-		module_put(entity->parent->dev->driver->owner);
+	if (entity->graph_obj.mdev->dev)
+		module_put(entity->graph_obj.mdev->dev->driver->owner);
 }
 EXPORT_SYMBOL_GPL(media_entity_put);
 
@@ -561,7 +561,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	link->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(source->parent, MEDIA_GRAPH_LINK, &link->graph_obj);
+	media_gobj_init(source->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&link->graph_obj);
 
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
@@ -577,7 +578,8 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	backlink->flags = flags;
 
 	/* Initialize graph object embedded at the new link */
-	media_gobj_init(sink->parent, MEDIA_GRAPH_LINK, &backlink->graph_obj);
+	media_gobj_init(sink->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&backlink->graph_obj);
 
 	link->reverse = backlink;
 	backlink->reverse = link;
@@ -629,12 +631,12 @@ EXPORT_SYMBOL_GPL(__media_entity_remove_links);
 void media_entity_remove_links(struct media_entity *entity)
 {
 	/* Do nothing if the entity is not registered. */
-	if (entity->parent == NULL)
+	if (entity->graph_obj.mdev == NULL)
 		return;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 	__media_entity_remove_links(entity);
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_entity_remove_links);
 
@@ -703,7 +705,7 @@ int __media_entity_setup_link(struct media_link *link, u32 flags)
 	    (source->stream_count || sink->stream_count))
 		return -EBUSY;
 
-	mdev = source->parent;
+	mdev = source->graph_obj.mdev;
 
 	if (mdev->link_notify) {
 		ret = mdev->link_notify(link, flags,
@@ -724,9 +726,9 @@ int media_entity_setup_link(struct media_link *link, u32 flags)
 {
 	int ret;
 
-	mutex_lock(&link->source->entity->parent->graph_mutex);
+	mutex_lock(&link->source->entity->graph_obj.mdev->graph_mutex);
 	ret = __media_entity_setup_link(link, flags);
-	mutex_unlock(&link->source->entity->parent->graph_mutex);
+	mutex_unlock(&link->source->entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
drivers/media/platform/exynos4-is/fimc-isp-video.c +3 -3
index b7dc5ac66e36..3d9ccbf5f10f 100644
@@ -288,7 +288,7 @@ static int isp_video_open(struct file *file)
 		goto rel_fh;
 
 	if (v4l2_fh_is_singular_file(file)) {
-		mutex_lock(&me->parent->graph_mutex);
+		mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 		ret = fimc_pipeline_call(ve, open, me, true);
 
@@ -296,7 +296,7 @@ static int isp_video_open(struct file *file)
 		if (ret == 0)
 			me->use_count++;
 
-		mutex_unlock(&me->parent->graph_mutex);
+		mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 	}
 	if (!ret)
 		goto unlock;
@@ -312,7 +312,7 @@ static int isp_video_release(struct file *file)
 	struct fimc_isp *isp = video_drvdata(file);
 	struct fimc_is_video *ivc = &isp->video_capture;
 	struct media_entity *entity = &ivc->ve.vdev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 
 	mutex_lock(&isp->video_lock);
 
drivers/media/platform/exynos4-is/fimc-lite.c +4 -4
index e8f707d1729b..b2607da4ad14 100644
@@ -500,7 +500,7 @@ static int fimc_lite_open(struct file *file)
 	    atomic_read(&fimc->out_path) != FIMC_IO_DMA)
 		goto unlock;
 
-	mutex_lock(&me->parent->graph_mutex);
+	mutex_lock(&me->graph_obj.mdev->graph_mutex);
 
 	ret = fimc_pipeline_call(&fimc->ve, open, me, true);
 
@@ -508,7 +508,7 @@ static int fimc_lite_open(struct file *file)
 	if (ret == 0)
 		me->use_count++;
 
-	mutex_unlock(&me->parent->graph_mutex);
+	mutex_unlock(&me->graph_obj.mdev->graph_mutex);
 
 	if (!ret) {
 		fimc_lite_clear_event_counters(fimc);
@@ -541,9 +541,9 @@ static int fimc_lite_release(struct file *file)
 		fimc_pipeline_call(&fimc->ve, close);
 		clear_bit(ST_FLITE_IN_USE, &fimc->state);
 
-		mutex_lock(&entity->parent->graph_mutex);
+		mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 		entity->use_count--;
-		mutex_unlock(&entity->parent->graph_mutex);
+		mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 	}
 
 	_vb2_fop_release(file, NULL);
drivers/media/platform/exynos4-is/media-dev.c +1 -1
index 3ba76940eef5..92dbade2fffc 100644
@@ -1046,7 +1046,7 @@ static int __fimc_md_modify_pipeline(struct media_entity *entity, bool enable)
 	return ret;
 }
 
-/* Locking: called with entity->parent->graph_mutex mutex held. */
+/* Locking: called with entity->graph_obj.mdev->graph_mutex mutex held. */
 static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
 {
 	struct media_entity *entity_err = entity;
drivers/media/platform/exynos4-is/media-dev.h +4 -4
index 03214541f149..9a69913b31cb 100644
@@ -164,8 +164,8 @@ struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
 
 static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
 {
-	return me->parent == NULL ? NULL :
-		container_of(me->parent, struct fimc_md, media_dev);
+	return me->graph_obj.mdev == NULL ? NULL :
+		container_of(me->graph_obj.mdev, struct fimc_md, media_dev);
 }
 
 static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
@@ -175,12 +175,12 @@ static inline struct fimc_md *notifier_to_fimc_md(struct v4l2_async_notifier *n)
 
 static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
 {
-	mutex_lock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_lock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
 {
-	mutex_unlock(&ve->vdev.entity.parent->graph_mutex);
+	mutex_unlock(&ve->vdev.entity.graph_obj.mdev->graph_mutex);
 }
 
 int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
drivers/media/platform/omap3isp/isp.c +2 -2
index 6351f35b0a65..aa13b17d19a0 100644
@@ -787,7 +787,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -798,7 +798,7 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
drivers/media/platform/omap3isp/ispvideo.c +1 -1
index 6c89dc40df85..4c367352b1f7 100644
@@ -226,7 +226,7 @@ static int isp_video_get_graph_data(struct isp_video *video,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct isp_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
drivers/media/platform/vsp1/vsp1_video.c +1 -1
index debe4e539df6..1f94c1a54e00 100644
@@ -409,7 +409,7 @@ static int vsp1_pipeline_validate(struct vsp1_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int i;
 	int ret;
 
drivers/media/platform/xilinx/xilinx-dma.c +1 -1
index f7f9aa353a55..92e8116dc28f 100644
@@ -181,7 +181,7 @@ static int xvip_pipeline_validate(struct xvip_pipeline *pipe,
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &start->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	unsigned int num_inputs = 0;
 	unsigned int num_outputs = 0;
 
drivers/staging/media/davinci_vpfe/vpfe_video.c +3 -3
index 61a8d5beff58..92573fa852a9 100644
@@ -130,7 +130,7 @@ __vpfe_video_get_format(struct vpfe_video_device *video,
 static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
 {
 	struct media_entity *entity = &video->video_dev.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct vpfe_pipeline *pipe = &video->pipe;
 	struct vpfe_video_device *far_end = NULL;
 	struct media_entity_graph graph;
@@ -288,7 +288,7 @@ static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 	while ((entity = media_entity_graph_walk_next(&graph))) {
@@ -328,7 +328,7 @@ static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
 	else
 		entity = &pipe->inputs[0]->video_dev.entity;
 
-	mdev = entity->parent;
+	mdev = entity->graph_obj.mdev;
 	mutex_lock(&mdev->graph_mutex);
 	media_entity_graph_walk_start(&graph, entity);
 
drivers/staging/media/omap4iss/iss.c +2 -2
index 7226553ceb2f..40591963b42b 100644
@@ -494,7 +494,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	int change = use ? 1 : -1;
 	int ret;
 
-	mutex_lock(&entity->parent->graph_mutex);
+	mutex_lock(&entity->graph_obj.mdev->graph_mutex);
 
 	/* Apply use count to node. */
 	entity->use_count += change;
@@ -505,7 +505,7 @@ int omap4iss_pipeline_pm_use(struct media_entity *entity, int use)
 	if (ret < 0)
 		entity->use_count -= change;
 
-	mutex_unlock(&entity->parent->graph_mutex);
+	mutex_unlock(&entity->graph_obj.mdev->graph_mutex);
 
 	return ret;
 }
drivers/staging/media/omap4iss/iss_video.c +1 -1
index 25e9e7a6b99d..45a3f2d778fc 100644
@@ -207,7 +207,7 @@ iss_video_far_end(struct iss_video *video)
 {
 	struct media_entity_graph graph;
 	struct media_entity *entity = &video->video.entity;
-	struct media_device *mdev = entity->parent;
+	struct media_device *mdev = entity->graph_obj.mdev;
 	struct iss_video *far_end = NULL;
 
 	mutex_lock(&mdev->graph_mutex);
Signature · 1 line
2.4.3
#33 lore raw

PATCH v8 12/55 media: remove media entity .parent field

In reply to Mauro Carvalho Chehab

From: Javier Martinez Canillas <[email protected]>

Now that the struct media_entity .parent field is unused, it can be safely removed. Since all the previous users were converted to use the .mdev field from the embedded struct media_gobj instead.

include/media/media-entity.h +0 -1
index e0e4b014ce62..239c4ec30ef6 100644
@@ -103,7 +103,6 @@ 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*/
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
Signature · 1 line
2.4.3
#34 lore raw

PATCH v8 13/55 uapi/media.h: Declare interface types for V4L2 and DVB

In reply to Mauro Carvalho Chehab

Declare the interface types that will be used by the new G_TOPOLOGY ioctl that will be defined latter on.

For now, we need those types, as they'll be used on the internal structs associated with the new media_interface graph object defined on the next patch.

include/uapi/linux/media.h +21 -0
index 4e816be3de39..3ad3d6be293f 100644
@@ -167,6 +167,27 @@ struct media_links_enum {
 	__u32 reserved[4];
 };
 
+/* Interface type ranges */
+
+#define MEDIA_INTF_T_DVB_BASE	0x00000100
+#define MEDIA_INTF_T_V4L_BASE	0x00000200
+
+/* Interface types */
+
+#define MEDIA_INTF_T_DVB_FE    	(MEDIA_INTF_T_DVB_BASE)
+#define MEDIA_INTF_T_DVB_DEMUX  (MEDIA_INTF_T_DVB_BASE + 1)
+#define MEDIA_INTF_T_DVB_DVR    (MEDIA_INTF_T_DVB_BASE + 2)
+#define MEDIA_INTF_T_DVB_CA     (MEDIA_INTF_T_DVB_BASE + 3)
+#define MEDIA_INTF_T_DVB_NET    (MEDIA_INTF_T_DVB_BASE + 4)
+
+#define MEDIA_INTF_T_V4L_VIDEO  (MEDIA_INTF_T_V4L_BASE)
+#define MEDIA_INTF_T_V4L_VBI    (MEDIA_INTF_T_V4L_BASE + 1)
+#define MEDIA_INTF_T_V4L_RADIO  (MEDIA_INTF_T_V4L_BASE + 2)
+#define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
+#define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
+
+/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
+
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct media_entity_desc)
 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
Signature · 1 line
2.4.3

A message that is not in the archive (sent off-list or not yet received): 4bf60081a6756f559407052aa92e343456697a08.1440902901.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

#36 lore raw

Re: [PATCH v8 13/55] [media] uapi/media.h: Declare interface types for V4L2 and DVB

Quoted 10 lines · Mauro Carvalho Chehab

Declare the interface types that will be used by the new G_TOPOLOGY ioctl that will be defined latter on.

For now, we need those types, as they'll be used on the internal structs associated with the new media_interface graph object defined on the next patch.

Best regards,
Javier

#37 lore raw

PATCH v8 14/55 media: add functions to allow creating interfaces

In reply to Mauro Carvalho Chehab

Interfaces are different than entities: they represent a Kernel<->userspace interaction, while entities represent a piece of hardware/firmware/software that executes a function.

Let's distinguish them by creating a separate structure to store the interfaces.

Latter patches should change the existing drivers and logic to split the current interface embedded inside the entity structure (device nodes) into a separate object of the graph.

drivers/media/media-entity.c +83 -0
index a23c93369a04..583666e2cc25 100644
@@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
 		return "pad";
 	case MEDIA_GRAPH_LINK:
 		return "link";
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		return "intf_devnode";
 	default:
 		return "unknown";
 	}
 }
 
+static inline const char *intf_type(struct media_interface *intf)
+{
+	switch (intf->type) {
+	case MEDIA_INTF_T_DVB_FE:
+		return "frontend";
+	case MEDIA_INTF_T_DVB_DEMUX:
+		return "demux";
+	case MEDIA_INTF_T_DVB_DVR:
+		return "DVR";
+	case MEDIA_INTF_T_DVB_CA:
+		return  "CA";
+	case MEDIA_INTF_T_DVB_NET:
+		return "dvbnet";
+	case MEDIA_INTF_T_V4L_VIDEO:
+		return "video";
+	case MEDIA_INTF_T_V4L_VBI:
+		return "vbi";
+	case MEDIA_INTF_T_V4L_RADIO:
+		return "radio";
+	case MEDIA_INTF_T_V4L_SUBDEV:
+		return "v4l2-subdev";
+	case MEDIA_INTF_T_V4L_SWRADIO:
+		return "swradio";
+	default:
+		return "unknown-intf";
+	}
+};
+
 static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 {
 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
@@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 			"%s: id 0x%08x pad#%d: '%s':%d\n",
 			event_name, gobj->id, media_localid(gobj),
 			pad->entity->name, pad->index);
+		break;
+	}
+	case MEDIA_GRAPH_INTF_DEVNODE:
+	{
+		struct media_interface *intf = gobj_to_intf(gobj);
+		struct media_intf_devnode *devnode = intf_to_devnode(intf);
+
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
+			event_name, gobj->id, media_localid(gobj),
+			intf_type(intf),
+			devnode->major, devnode->minor);
+		break;
 	}
 	}
 #endif
@@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		break;
 	}
 	dev_dbg_obj(__func__, gobj);
 }
@@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 
 }
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
+
+
+/* Functions related to the media interface via device nodes */
+
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags)
+{
+	struct media_intf_devnode *devnode;
+	struct media_interface *intf;
+
+	devnode = kzalloc(sizeof(*devnode), gfp_flags);
+	if (!devnode)
+		return NULL;
+
+	intf = &devnode->intf;
+
+	intf->type = type;
+	intf->flags = flags;
+
+	devnode->major = major;
+	devnode->minor = minor;
+
+	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
+		       &devnode->intf.graph_obj);
+
+	return devnode;
+}
+EXPORT_SYMBOL_GPL(media_devnode_create);
+
+void media_devnode_remove(struct media_intf_devnode *devnode)
+{
+	media_gobj_remove(&devnode->intf.graph_obj);
+	kfree(devnode);
+}
+EXPORT_SYMBOL_GPL(media_devnode_remove);
include/media/media-device.h +2 -0
index 05414e351f8e..3b14394d5701 100644
@@ -44,6 +44,7 @@ struct device;
  * @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
+ * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -73,6 +74,7 @@ struct media_device {
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
+	u32 intf_devnode_id;
 
 	struct list_head entities;
 
include/media/media-entity.h +48 -0

77 lines not on this page · raw message

Signature · 1 line
2.4.3
Acked-by on v8 14/55
#38 lore raw

Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces

Quoted 8 lines · Mauro Carvalho Chehab

Interfaces are different than entities: they represent a Kernel<->userspace interaction, while entities represent a piece of hardware/firmware/software that executes a function.

Let's distinguish them by creating a separate structure to store the interfaces.

Latter patches should change the existing drivers and logic

s/Latter/Later/

FYI: you almost never use 'latter' in English texts. The only common use of 'latter' is in the phrase "the latter of two options" where 'latter' means 'second'.

Quoted 10 lines

to split the current interface embedded inside the entity structure (device nodes) into a separate object of the graph.

drivers/media/media-entity.c +0 -0
index a23c93369a04..583666e2cc25 100644

drivers/media/media-entity.c static inline const char *gobj_type(enum media_gobj_type type) · line 48

Quoted 5 lines
drivers/media/media-entity.c +2 -0
@@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
 		return "pad";
 	case MEDIA_GRAPH_LINK:
 		return "link";
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		return "intf_devnode";

You use '-' below for 'v4l-subdev' and 'unknown-intf', so I think this too should use '-'. My opinion though.

It's a nitpick, so I give my Ack anyway:

Regards,

Hans

Quoted 213 lines
drivers/media/media-entity.c +81 -0
 	default:
 		return "unknown";
 	}
 }
 
+static inline const char *intf_type(struct media_interface *intf)
+{
+	switch (intf->type) {
+	case MEDIA_INTF_T_DVB_FE:
+		return "frontend";
+	case MEDIA_INTF_T_DVB_DEMUX:
+		return "demux";
+	case MEDIA_INTF_T_DVB_DVR:
+		return "DVR";
+	case MEDIA_INTF_T_DVB_CA:
+		return  "CA";
+	case MEDIA_INTF_T_DVB_NET:
+		return "dvbnet";
+	case MEDIA_INTF_T_V4L_VIDEO:
+		return "video";
+	case MEDIA_INTF_T_V4L_VBI:
+		return "vbi";
+	case MEDIA_INTF_T_V4L_RADIO:
+		return "radio";
+	case MEDIA_INTF_T_V4L_SUBDEV:
+		return "v4l2-subdev";
+	case MEDIA_INTF_T_V4L_SWRADIO:
+		return "swradio";
+	default:
+		return "unknown-intf";
+	}
+};
+
 static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 {
 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
@@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 			"%s: id 0x%08x pad#%d: '%s':%d\n",
 			event_name, gobj->id, media_localid(gobj),
 			pad->entity->name, pad->index);
+		break;
+	}
+	case MEDIA_GRAPH_INTF_DEVNODE:
+	{
+		struct media_interface *intf = gobj_to_intf(gobj);
+		struct media_intf_devnode *devnode = intf_to_devnode(intf);
+
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
+			event_name, gobj->id, media_localid(gobj),
+			intf_type(intf),
+			devnode->major, devnode->minor);
+		break;
 	}
 	}
 #endif
@@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		break;
 	}
 	dev_dbg_obj(__func__, gobj);
 }
@@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 
 }
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
+
+
+/* Functions related to the media interface via device nodes */
+
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags)
+{
+	struct media_intf_devnode *devnode;
+	struct media_interface *intf;
+
+	devnode = kzalloc(sizeof(*devnode), gfp_flags);
+	if (!devnode)
+		return NULL;
+
+	intf = &devnode->intf;
+
+	intf->type = type;
+	intf->flags = flags;
+
+	devnode->major = major;
+	devnode->minor = minor;
+
+	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
+		       &devnode->intf.graph_obj);
+
+	return devnode;
+}
+EXPORT_SYMBOL_GPL(media_devnode_create);
+
+void media_devnode_remove(struct media_intf_devnode *devnode)
+{
+	media_gobj_remove(&devnode->intf.graph_obj);
+	kfree(devnode);
+}
+EXPORT_SYMBOL_GPL(media_devnode_remove);
include/media/media-device.h +2 -0
index 05414e351f8e..3b14394d5701 100644
@@ -44,6 +44,7 @@ struct device;
  * @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
+ * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -73,6 +74,7 @@ struct media_device {
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
+	u32 intf_devnode_id;
 
 	struct list_head entities;
 
include/media/media-entity.h +48 -0
index 239c4ec30ef6..7df8836f4eef 100644
@@ -36,11 +36,14 @@
  * @MEDIA_GRAPH_ENTITY:		Identify a media entity
  * @MEDIA_GRAPH_PAD:		Identify a media pad
  * @MEDIA_GRAPH_LINK:		Identify a media link
+ * @MEDIA_GRAPH_INTF_DEVNODE:	Identify a media Kernel API interface via
+ *				a device node
  */
 enum media_gobj_type {
 	MEDIA_GRAPH_ENTITY,
 	MEDIA_GRAPH_PAD,
 	MEDIA_GRAPH_LINK,
+	MEDIA_GRAPH_INTF_DEVNODE,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -141,6 +144,34 @@ struct media_entity {
 	} info;
 };
 
+/**
+ * struct media_intf_devnode - Define a Kernel API interface
+ *
+ * @graph_obj:		embedded graph object
+ * @type:		Type of the interface as defined at the
+ *			uapi/media/media.h header, e. g.
+ *			MEDIA_INTF_T_*
+ * @flags:		Interface flags as defined at uapi/media/media.h
+ */
+struct media_interface {
+	struct media_gobj		graph_obj;
+	u32				type;
+	u32				flags;
+};
+
+/**
+ * struct media_intf_devnode - Define a Kernel API interface via a device node
+ *
+ * @intf:	embedded interface object
+ * @major:	Major number of a device node
+ * @minor:	Minor number of a device node
+ */
+struct media_intf_devnode {
+	struct media_interface		intf;
+	u32				major;
+	u32				minor;
+};
+
 static inline u32 media_entity_type(struct media_entity *entity)
 {
 	return entity->type & MEDIA_ENT_TYPE_MASK;
@@ -198,6 +229,18 @@ struct media_entity_graph {
 #define gobj_to_link(gobj) \
 		container_of(gobj, struct media_link, graph_obj)
 
+#define gobj_to_link(gobj) \
+		container_of(gobj, struct media_link, graph_obj)
+
+#define gobj_to_pad(gobj) \
+		container_of(gobj, struct media_pad, graph_obj)
+
+#define gobj_to_intf(gobj) \
+		container_of(gobj, struct media_interface, graph_obj)
+
+#define intf_to_devnode(intf) \
+		container_of(intf, struct media_intf_devnode, intf)
+
 void media_gobj_init(struct media_device *mdev,
 		    enum media_gobj_type type,
 		    struct media_gobj *gobj);
@@ -229,6 +272,11 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe);
 void media_entity_pipeline_stop(struct media_entity *entity);
 
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags);
+void media_devnode_remove(struct media_intf_devnode *devnode);
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
 	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
#39 lore raw

Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces

Em Mon, 31 Aug 2015 12:20:43 +0200
Hans Verkuil <[email protected]> escreveu:

Quoted 8 lines · Mauro Carvalho Chehab
Quoted 7 lines

Interfaces are different than entities: they represent a Kernel<->userspace interaction, while entities represent a piece of hardware/firmware/software that executes a function.

Let's distinguish them by creating a separate structure to store the interfaces.

Quoted 7 lines
Quoted 1 line

Latter patches should change the existing drivers and logic

s/Latter/Later/

FYI: you almost never use 'latter' in English texts. The only common use of 'latter' is in the phrase "the latter of two options" where 'latter' means 'second'.

I did a global replace on the patches, but perhaps the regex expression I used didn't got this one.

Quoted 6 lines
Quoted 6 lines

to split the current interface embedded inside the entity structure (device nodes) into a separate object of the graph.

Quoted 13 lines

drivers/media/media-entity.c static inline const char *gobj_type(enum media_gobj_type type) · line 48

Quoted 10 lines
drivers/media/media-entity.c +2 -0
index a23c93369a04..583666e2cc25 100644
@@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
 		return "pad";
 	case MEDIA_GRAPH_LINK:
 		return "link";
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		return "intf_devnode";

You use '-' below for 'v4l-subdev' and 'unknown-intf', so I think this too should use '-'. My opinion though.

Gah, forgot this one ;)

Quoted 223 lines

It's a nitpick, so I give my Ack anyway:

Regards,

Hans

Quoted 213 lines
drivers/media/media-entity.c +81 -0
 	default:
 		return "unknown";
 	}
 }
 
+static inline const char *intf_type(struct media_interface *intf)
+{
+	switch (intf->type) {
+	case MEDIA_INTF_T_DVB_FE:
+		return "frontend";
+	case MEDIA_INTF_T_DVB_DEMUX:
+		return "demux";
+	case MEDIA_INTF_T_DVB_DVR:
+		return "DVR";
+	case MEDIA_INTF_T_DVB_CA:
+		return  "CA";
+	case MEDIA_INTF_T_DVB_NET:
+		return "dvbnet";
+	case MEDIA_INTF_T_V4L_VIDEO:
+		return "video";
+	case MEDIA_INTF_T_V4L_VBI:
+		return "vbi";
+	case MEDIA_INTF_T_V4L_RADIO:
+		return "radio";
+	case MEDIA_INTF_T_V4L_SUBDEV:
+		return "v4l2-subdev";
+	case MEDIA_INTF_T_V4L_SWRADIO:
+		return "swradio";
+	default:
+		return "unknown-intf";
+	}
+};
+
 static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 {
 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
@@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 			"%s: id 0x%08x pad#%d: '%s':%d\n",
 			event_name, gobj->id, media_localid(gobj),
 			pad->entity->name, pad->index);
+		break;
+	}
+	case MEDIA_GRAPH_INTF_DEVNODE:
+	{
+		struct media_interface *intf = gobj_to_intf(gobj);
+		struct media_intf_devnode *devnode = intf_to_devnode(intf);
+
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
+			event_name, gobj->id, media_localid(gobj),
+			intf_type(intf),
+			devnode->major, devnode->minor);
+		break;
 	}
 	}
 #endif
@@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		break;
 	}
 	dev_dbg_obj(__func__, gobj);
 }
@@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 
 }
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
+
+
+/* Functions related to the media interface via device nodes */
+
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags)
+{
+	struct media_intf_devnode *devnode;
+	struct media_interface *intf;
+
+	devnode = kzalloc(sizeof(*devnode), gfp_flags);
+	if (!devnode)
+		return NULL;
+
+	intf = &devnode->intf;
+
+	intf->type = type;
+	intf->flags = flags;
+
+	devnode->major = major;
+	devnode->minor = minor;
+
+	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
+		       &devnode->intf.graph_obj);
+
+	return devnode;
+}
+EXPORT_SYMBOL_GPL(media_devnode_create);
+
+void media_devnode_remove(struct media_intf_devnode *devnode)
+{
+	media_gobj_remove(&devnode->intf.graph_obj);
+	kfree(devnode);
+}
+EXPORT_SYMBOL_GPL(media_devnode_remove);
include/media/media-device.h +2 -0
index 05414e351f8e..3b14394d5701 100644
@@ -44,6 +44,7 @@ struct device;
  * @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
+ * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -73,6 +74,7 @@ struct media_device {
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
+	u32 intf_devnode_id;
 
 	struct list_head entities;
 
include/media/media-entity.h +48 -0
index 239c4ec30ef6..7df8836f4eef 100644
@@ -36,11 +36,14 @@
  * @MEDIA_GRAPH_ENTITY:		Identify a media entity
  * @MEDIA_GRAPH_PAD:		Identify a media pad
  * @MEDIA_GRAPH_LINK:		Identify a media link
+ * @MEDIA_GRAPH_INTF_DEVNODE:	Identify a media Kernel API interface via
+ *				a device node
  */
 enum media_gobj_type {
 	MEDIA_GRAPH_ENTITY,
 	MEDIA_GRAPH_PAD,
 	MEDIA_GRAPH_LINK,
+	MEDIA_GRAPH_INTF_DEVNODE,
 };
 
 #define MEDIA_BITS_PER_TYPE		8
@@ -141,6 +144,34 @@ struct media_entity {
 	} info;
 };
 
+/**
+ * struct media_intf_devnode - Define a Kernel API interface
+ *
+ * @graph_obj:		embedded graph object
+ * @type:		Type of the interface as defined at the
+ *			uapi/media/media.h header, e. g.
+ *			MEDIA_INTF_T_*
+ * @flags:		Interface flags as defined at uapi/media/media.h
+ */
+struct media_interface {
+	struct media_gobj		graph_obj;
+	u32				type;
+	u32				flags;
+};
+
+/**
+ * struct media_intf_devnode - Define a Kernel API interface via a device node
+ *
+ * @intf:	embedded interface object
+ * @major:	Major number of a device node
+ * @minor:	Minor number of a device node
+ */
+struct media_intf_devnode {
+	struct media_interface		intf;
+	u32				major;
+	u32				minor;
+};
+
 static inline u32 media_entity_type(struct media_entity *entity)
 {
 	return entity->type & MEDIA_ENT_TYPE_MASK;
@@ -198,6 +229,18 @@ struct media_entity_graph {
 #define gobj_to_link(gobj) \
 		container_of(gobj, struct media_link, graph_obj)
 
+#define gobj_to_link(gobj) \
+		container_of(gobj, struct media_link, graph_obj)
+
+#define gobj_to_pad(gobj) \
+		container_of(gobj, struct media_pad, graph_obj)
+
+#define gobj_to_intf(gobj) \
+		container_of(gobj, struct media_interface, graph_obj)
+
+#define intf_to_devnode(intf) \
+		container_of(intf, struct media_intf_devnode, intf)
+
 void media_gobj_init(struct media_device *mdev,
 		    enum media_gobj_type type,
 		    struct media_gobj *gobj);
@@ -229,6 +272,11 @@ __must_check int media_entity_pipeline_start(struct media_entity *entity,
 					     struct media_pipeline *pipe);
 void media_entity_pipeline_stop(struct media_entity *entity);
 
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags);
+void media_devnode_remove(struct media_intf_devnode *devnode);
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
 	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
#40 lore raw

Re: [PATCH v8 14/55] [media] media: add functions to allow creating interfaces

In reply to Mauro Carvalho Chehab

Interfaces are different than entities: they represent a Kernel<->userspace interaction, while entities represent a piece of hardware/firmware/software that executes a function.

Let's distinguish them by creating a separate structure to store the interfaces.

Later patches should change the existing drivers and logic to split the current interface embedded inside the entity structure (device nodes) into a separate object of the graph.

drivers/media/media-entity.c +83 -0
index a23c93369a04..dc679dfe8ade 100644
@@ -44,11 +44,41 @@ static inline const char *gobj_type(enum media_gobj_type type)
 		return "pad";
 	case MEDIA_GRAPH_LINK:
 		return "link";
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		return "intf-devnode";
 	default:
 		return "unknown";
 	}
 }
 
+static inline const char *intf_type(struct media_interface *intf)
+{
+	switch (intf->type) {
+	case MEDIA_INTF_T_DVB_FE:
+		return "frontend";
+	case MEDIA_INTF_T_DVB_DEMUX:
+		return "demux";
+	case MEDIA_INTF_T_DVB_DVR:
+		return "DVR";
+	case MEDIA_INTF_T_DVB_CA:
+		return  "CA";
+	case MEDIA_INTF_T_DVB_NET:
+		return "dvbnet";
+	case MEDIA_INTF_T_V4L_VIDEO:
+		return "video";
+	case MEDIA_INTF_T_V4L_VBI:
+		return "vbi";
+	case MEDIA_INTF_T_V4L_RADIO:
+		return "radio";
+	case MEDIA_INTF_T_V4L_SUBDEV:
+		return "v4l2-subdev";
+	case MEDIA_INTF_T_V4L_SWRADIO:
+		return "swradio";
+	default:
+		return "unknown-intf";
+	}
+};
+
 static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 {
 #if defined(DEBUG) || defined (CONFIG_DYNAMIC_DEBUG)
@@ -84,6 +114,19 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 			"%s: id 0x%08x pad#%d: '%s':%d\n",
 			event_name, gobj->id, media_localid(gobj),
 			pad->entity->name, pad->index);
+		break;
+	}
+	case MEDIA_GRAPH_INTF_DEVNODE:
+	{
+		struct media_interface *intf = gobj_to_intf(gobj);
+		struct media_intf_devnode *devnode = intf_to_devnode(intf);
+
+		dev_dbg(gobj->mdev->dev,
+			"%s: id 0x%08x intf_devnode#%d: %s - major: %d, minor: %d\n",
+			event_name, gobj->id, media_localid(gobj),
+			intf_type(intf),
+			devnode->major, devnode->minor);
+		break;
 	}
 	}
 #endif
@@ -119,6 +162,9 @@ void media_gobj_init(struct media_device *mdev,
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		break;
 	}
 	dev_dbg_obj(__func__, gobj);
 }
@@ -793,3 +839,40 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 
 }
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
+
+
+/* Functions related to the media interface via device nodes */
+
+struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
+						u32 type, u32 flags,
+						u32 major, u32 minor,
+						gfp_t gfp_flags)
+{
+	struct media_intf_devnode *devnode;
+	struct media_interface *intf;
+
+	devnode = kzalloc(sizeof(*devnode), gfp_flags);
+	if (!devnode)
+		return NULL;
+
+	intf = &devnode->intf;
+
+	intf->type = type;
+	intf->flags = flags;
+
+	devnode->major = major;
+	devnode->minor = minor;
+
+	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
+		       &devnode->intf.graph_obj);
+
+	return devnode;
+}
+EXPORT_SYMBOL_GPL(media_devnode_create);
+
+void media_devnode_remove(struct media_intf_devnode *devnode)
+{
+	media_gobj_remove(&devnode->intf.graph_obj);
+	kfree(devnode);
+}
+EXPORT_SYMBOL_GPL(media_devnode_remove);
include/media/media-device.h +2 -0
index 05414e351f8e..3b14394d5701 100644
@@ -44,6 +44,7 @@ struct device;
  * @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
+ * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
@@ -73,6 +74,7 @@ struct media_device {
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
+	u32 intf_devnode_id;
 
 	struct list_head entities;
 
include/media/media-entity.h +48 -0

77 lines not on this page · raw message

Signature · 1 line
2.4.3

A message that is not in the archive (sent off-list or not yet received): cd69226f7f42baafbc4a3db5f8a8c387fba879dd.1440902901.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

A message that is not in the archive (sent off-list or not yet received): ec40936d7349f390dd8b73b90fa0e0708de596a9.1441540862.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

#43 lore raw

Re: [PATCH v8 15/55] [media] uapi/media.h: Declare interface types for ALSA

Declare the interface types to be used on alsa for the new G_TOPOLOGY ioctl.

drivers/media/media-entity.c +12 -0
index dc679dfe8ade..27fce6224972 100644
@@ -74,6 +74,18 @@ static inline const char *intf_type(struct media_interface *intf)
 		return "v4l2-subdev";
 	case MEDIA_INTF_T_V4L_SWRADIO:
 		return "swradio";
+	case MEDIA_INTF_T_ALSA_PCM_CAPTURE:
+		return "pcm-capture";
+	case MEDIA_INTF_T_ALSA_PCM_PLAYBACK:
+		return "pcm-playback";
+	case MEDIA_INTF_T_ALSA_CONTROL:
+		return "alsa-control";
+	case MEDIA_INTF_T_ALSA_COMPRESS:
+		return "compress";
+	case MEDIA_INTF_T_ALSA_RAWMIDI:
+		return "rawmidi";
+	case MEDIA_INTF_T_ALSA_HWDEP:
+		return "hwdep";
 	default:
 		return "unknown-intf";
 	}
include/uapi/linux/media.h +8 -0
index 3ad3d6be293f..aca828709bad 100644
@@ -171,6 +171,7 @@ struct media_links_enum {
 
 #define MEDIA_INTF_T_DVB_BASE	0x00000100
 #define MEDIA_INTF_T_V4L_BASE	0x00000200
+#define MEDIA_INTF_T_ALSA_BASE	0x00000300
 
 /* Interface types */
 
@@ -186,6 +187,13 @@ struct media_links_enum {
 #define MEDIA_INTF_T_V4L_SUBDEV (MEDIA_INTF_T_V4L_BASE + 3)
 #define MEDIA_INTF_T_V4L_SWRADIO (MEDIA_INTF_T_V4L_BASE + 4)
 
+#define MEDIA_INTF_T_ALSA_PCM_CAPTURE   (MEDIA_INTF_T_ALSA_BASE)
+#define MEDIA_INTF_T_ALSA_PCM_PLAYBACK  (MEDIA_INTF_T_ALSA_BASE + 1)
+#define MEDIA_INTF_T_ALSA_CONTROL       (MEDIA_INTF_T_ALSA_BASE + 2)
+#define MEDIA_INTF_T_ALSA_COMPRESS      (MEDIA_INTF_T_ALSA_BASE + 3)
+#define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
+#define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
+
 /* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct media_device_info)
Signature · 1 line
2.4.3
#45 lore raw

Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace

In reply to a message not in the archive

Now that interfaces got created, we need to fix the entity namespace.

So, let's create a consistent new namespace and add backward compatibility macros to keep the old namespace preserved.

drivers/media/dvb-core/dvbdev.c +13 -13
index ada0738d26f2..dadcf1655070 100644
@@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_DEMUX:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_CA:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
@@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
 void dvb_create_media_graph(struct dvb_adapter *adap)
 {
 	struct media_device *mdev = adap->mdev;
-	struct media_entity *entity, *tuner = NULL, *fe = NULL;
+	struct media_entity *entity, *tuner = NULL, *demod = NULL;
 	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
 	struct media_interface *intf;
 
@@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
 			tuner = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_FE:
-			fe = entity;
+		case MEDIA_ENT_T_DVB_DEMOD:
+			demod = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
+		case MEDIA_ENT_T_DVB_DEMUX:
 			demux = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
+		case MEDIA_ENT_T_DVB_TSOUT:
 			dvr = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_CA:
+		case MEDIA_ENT_T_DVB_CA:
 			ca = entity;
 			break;
 		}
 	}
 
-	if (tuner && fe)
-		media_create_pad_link(tuner, 0, fe, 0, 0);
+	if (tuner && demod)
+		media_create_pad_link(tuner, 0, demod, 0, 0);
 
-	if (fe && demux)
-		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+	if (demod && demux)
+		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
 		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
include/uapi/linux/media.h +56 -18

87 lines not on this page · raw message

Signature · 1 line
2.4.3

A message that is not in the archive (sent off-list or not yet received): 9b372bed2898c86f41c6fe7b7e4e13670701feaf.1441540862.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

Acked-by
#47 lore raw

Re: [PATCH v8 28/55] [media] uapi/media.h: Fix entity namespace

Quoted 7 lines · Mauro Carvalho Chehab

Now that interfaces got created, we need to fix the entity namespace.

So, let's create a consistent new namespace and add backward compatibility macros to keep the old namespace preserved.

Quoted 164 lines
drivers/media/dvb-core/dvbdev.c +13 -13
index ada0738d26f2..dadcf1655070 100644
@@ -230,17 +230,17 @@ static void dvb_create_media_entity(struct dvb_device *dvbdev,
 
 	switch (type) {
 	case DVB_DEVICE_FRONTEND:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_FE;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMOD;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_DEMUX:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_DEMUX;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_DEMUX;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
 	case DVB_DEVICE_CA:
-		dvbdev->entity->type = MEDIA_ENT_T_DEVNODE_DVB_CA;
+		dvbdev->entity->type = MEDIA_ENT_T_DVB_CA;
 		dvbdev->pads[0].flags = MEDIA_PAD_FL_SINK;
 		dvbdev->pads[1].flags = MEDIA_PAD_FL_SOURCE;
 		break;
@@ -439,7 +439,7 @@ EXPORT_SYMBOL(dvb_unregister_device);
 void dvb_create_media_graph(struct dvb_adapter *adap)
 {
 	struct media_device *mdev = adap->mdev;
-	struct media_entity *entity, *tuner = NULL, *fe = NULL;
+	struct media_entity *entity, *tuner = NULL, *demod = NULL;
 	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
 	struct media_interface *intf;
 
@@ -451,26 +451,26 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 		case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
 			tuner = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_FE:
-			fe = entity;
+		case MEDIA_ENT_T_DVB_DEMOD:
+			demod = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DEMUX:
+		case MEDIA_ENT_T_DVB_DEMUX:
 			demux = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_DVR:
+		case MEDIA_ENT_T_DVB_TSOUT:
 			dvr = entity;
 			break;
-		case MEDIA_ENT_T_DEVNODE_DVB_CA:
+		case MEDIA_ENT_T_DVB_CA:
 			ca = entity;
 			break;
 		}
 	}
 
-	if (tuner && fe)
-		media_create_pad_link(tuner, 0, fe, 0, 0);
+	if (tuner && demod)
+		media_create_pad_link(tuner, 0, demod, 0, 0);
 
-	if (fe && demux)
-		media_create_pad_link(fe, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
+	if (demod && demux)
+		media_create_pad_link(demod, 1, demux, 0, MEDIA_LNK_FL_ENABLED);
 
 	if (demux && dvr)
 		media_create_pad_link(demux, 1, dvr, 0, MEDIA_LNK_FL_ENABLED);
include/uapi/linux/media.h +56 -18
index aca828709bad..f8725b881a1d 100644
@@ -42,31 +42,69 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/*
+ * Base numbers for entity types
+ *
+ * Please notice that the huge gap of 16 bits for each base is overkill!
+ * 8 bits is more than enough to avoid starving entity types for each
+ * subsystem.
+ *
+ * However, It is kept this way just to avoid binary breakages with the
+ * namespace provided on legacy versions of this header.
+ */
+#define MEDIA_ENT_T_DVB_BASE		0x00000000
+#define MEDIA_ENT_T_V4L2_BASE		0x00010000
+#define MEDIA_ENT_T_V4L2_SUBDEV_BASE	0x00020000
+
+/*
+ * V4L2 entities - Those are used for DMA (mmap/DMABUF) and
+ *	read()/write() data I/O associated with the V4L2 devnodes.
+ */
+#define MEDIA_ENT_T_V4L2_VIDEO		(MEDIA_ENT_T_V4L2_BASE + 1)
+	/*
+	 * Please notice that numbers between MEDIA_ENT_T_V4L2_BASE + 2 and
+	 * MEDIA_ENT_T_V4L2_BASE + 4 can't be used, as those values used
+	 * to be declared for FB, ALSA and DVB entities.
+	 * As those values were never actually used in practice, we're just
+	 * adding them as backward compatibility macros and keeping the
+	 * numberspace clean here. This way, we avoid breaking compilation,
+	 * in the case of having some userspace application using the old
+	 * symbols.
+	 */
+#define MEDIA_ENT_T_V4L2_VBI		(MEDIA_ENT_T_V4L2_BASE + 5)
+#define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
+
+/* V4L2 Sub-device entities */
+#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
+#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
+#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
+	/* A converter of analogue video to its digital representation. */
+#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 4)
+	/* Tuner entity is actually both V4L2 and DVB subdev */
+#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 5)
+
+/* DVB entities */
+#define MEDIA_ENT_T_DVB_DEMOD		(MEDIA_ENT_T_DVB_BASE + 1)
+#define MEDIA_ENT_T_DVB_DEMUX		(MEDIA_ENT_T_DVB_BASE + 2)
+#define MEDIA_ENT_T_DVB_TSOUT		(MEDIA_ENT_T_DVB_BASE + 3)
+#define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
+#define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
+
+/* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
 #define MEDIA_ENT_SUBTYPE_MASK		0x0000ffff
 
-#define MEDIA_ENT_T_DEVNODE		(1 << MEDIA_ENT_TYPE_SHIFT)
-#define MEDIA_ENT_T_DEVNODE_V4L		(MEDIA_ENT_T_DEVNODE + 1)
+#define MEDIA_ENT_T_DEVNODE		MEDIA_ENT_T_V4L2_BASE
+#define MEDIA_ENT_T_V4L2_SUBDEV		MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
+#define MEDIA_ENT_T_DEVNODE_V4L		MEDIA_ENT_T_V4L2_VIDEO
+
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
-#define MEDIA_ENT_T_DEVNODE_DVB_FE	(MEDIA_ENT_T_DEVNODE + 4)
-#define MEDIA_ENT_T_DEVNODE_DVB_DEMUX	(MEDIA_ENT_T_DEVNODE + 5)
-#define MEDIA_ENT_T_DEVNODE_DVB_DVR	(MEDIA_ENT_T_DEVNODE + 6)
-#define MEDIA_ENT_T_DEVNODE_DVB_CA	(MEDIA_ENT_T_DEVNODE + 7)
-#define MEDIA_ENT_T_DEVNODE_DVB_NET	(MEDIA_ENT_T_DEVNODE + 8)
+#define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
 
-/* Legacy symbol. Use it to avoid userspace compilation breakages */
-#define MEDIA_ENT_T_DEVNODE_DVB		MEDIA_ENT_T_DEVNODE_DVB_FE
-
-#define MEDIA_ENT_T_V4L2_SUBDEV		(2 << MEDIA_ENT_TYPE_SHIFT)
-#define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV + 1)
-#define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV + 2)
-#define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV + 3)
-/* A converter of analogue video to its digital representation. */
-#define MEDIA_ENT_T_V4L2_SUBDEV_DECODER	(MEDIA_ENT_T_V4L2_SUBDEV + 4)
-
-#define MEDIA_ENT_T_V4L2_SUBDEV_TUNER	(MEDIA_ENT_T_V4L2_SUBDEV + 5)
+/* Entity types */
 
 #define MEDIA_ENT_FL_DEFAULT		(1 << 0)
 
#48 lore raw

Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel

In reply to a message not in the archive

Don't use anymore the type/subtype entity data/macros inside the Kernel.

include/media/media-entity.h +0 -10
index 220864319d21..7320cdc45833 100644
@@ -185,16 +185,6 @@ struct media_intf_devnode {
 	u32				minor;
 };
 
-static inline u32 media_entity_type(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_TYPE_MASK;
-}
-
-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->graph_obj.id;
include/uapi/linux/media.h +0 -2
index 3d6210095336..f90147cb9b57 100644
@@ -42,8 +42,6 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
-/* Used values for media_entity_desc::type */
-
 /*
  * Initial value to be used when a new entity is created
  * Drivers should change it to something useful
Signature · 1 line
2.4.3

A message that is not in the archive (sent off-list or not yet received): 728826957177ee11793b6b28b4e61e94b2d3068c.1441540862.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

Acked-by
#50 lore raw

Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel

Quoted 4 lines · Mauro Carvalho Chehab

Don't use anymore the type/subtype entity data/macros inside the Kernel.

Quoted 36 lines
include/media/media-entity.h +0 -10
index 220864319d21..7320cdc45833 100644
@@ -185,16 +185,6 @@ struct media_intf_devnode {
 	u32				minor;
 };
 
-static inline u32 media_entity_type(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_TYPE_MASK;
-}
-
-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->graph_obj.id;
include/uapi/linux/media.h +0 -2
index 3d6210095336..f90147cb9b57 100644
@@ -42,8 +42,6 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
-/* Used values for media_entity_desc::type */
-
 /*
  * Initial value to be used when a new entity is created
  * Drivers should change it to something useful
#51 lore raw

Re: [PATCH v8 39/55] [media] media controller: get rid of entity subtype on Kernel

In reply to a message not in the archive

Hi Mauro,

Thank you for the patch.

Quoted 4 lines · On Sunday 06 September 2015 09:02:59 Mauro Carvalho Chehab wrote:

Don't use anymore the type/subtype entity data/macros inside the Kernel.

Quoted 34 lines
include/media/media-entity.h +0 -10
index 220864319d21..7320cdc45833 100644
@@ -185,16 +185,6 @@ struct media_intf_devnode {
 	u32				minor;
 };
 
-static inline u32 media_entity_type(struct media_entity *entity)
-{
-	return entity->type & MEDIA_ENT_TYPE_MASK;
-}
-
-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->graph_obj.id;
include/uapi/linux/media.h +0 -2
index 3d6210095336..f90147cb9b57 100644
@@ -42,8 +42,6 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
-/* Used values for media_entity_desc::type */
-
 /*
  * Initial value to be used when a new entity is created
  * Drivers should change it to something useful
Signature · 3 lines
Regards,

Laurent Pinchart
Acked-by Hans Verkuil
#52 lore raw

Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel

In reply to a message not in the archive

Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__, in order to be sure that none of those old symbols are used inside the Kernel.

include/uapi/linux/media.h +2 -0
index f90147cb9b57..a1bd7afba110 100644
@@ -105,6 +105,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
@@ -118,6 +119,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
 
Signature · 1 line
2.4.3

A message that is not in the archive (sent off-list or not yet received): 3f2e554613f0b1286bd72dfd08f02ac6b874c95e.1441540862.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

#54 lore raw

Re: [PATCH v8 40/55] [media] media.h: don't use legacy entity macros at Kernel

Hi Mauro,

Thank you for the patch.

Quoted 6 lines · On Sunday 06 September 2015 09:03:00 Mauro Carvalho Chehab wrote:

Put the legacy MEDIA_ENT_* macros under a #ifndef __KERNEL__, in order to be sure that none of those old symbols are used inside the Kernel.

Quoted 19 lines
include/uapi/linux/media.h +2 -0
index f90147cb9b57..a1bd7afba110 100644
@@ -105,6 +105,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DVB_CA		(MEDIA_ENT_T_DVB_BASE + 4)
 #define MEDIA_ENT_T_DVB_NET_DECAP	(MEDIA_ENT_T_DVB_BASE + 5)
 
+#ifndef __KERNEL__
 /* Legacy symbols used to avoid userspace compilation breakages */
 #define MEDIA_ENT_TYPE_SHIFT		16
 #define MEDIA_ENT_TYPE_MASK		0x00ff0000
@@ -118,6 +119,7 @@ struct media_device_info {
 #define MEDIA_ENT_T_DEVNODE_FB		(MEDIA_ENT_T_DEVNODE + 2)
 #define MEDIA_ENT_T_DEVNODE_ALSA	(MEDIA_ENT_T_DEVNODE + 3)
 #define MEDIA_ENT_T_DEVNODE_DVB		(MEDIA_ENT_T_DEVNODE + 4)
+#endif
 
 /* Entity types */
Signature · 3 lines
Regards,

Laurent Pinchart
#55 lore raw

Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl

In reply to a message not in the archive

Add a new ioctl that will report the entire topology on one go.

include/media/media-entity.h +2 -0
index 7320cdc45833..2d5ad40254b7 100644
@@ -181,6 +181,8 @@ struct media_interface {
  */
 struct media_intf_devnode {
 	struct media_interface		intf;
+
+	/* Should match the fields at media_v2_intf_devnode */
 	u32				major;
 	u32				minor;
 };
include/uapi/linux/media.h +87 -1

104 lines not on this page · raw message

Signature · 1 line
2.4.3

A message that is not in the archive (sent off-list or not yet received): 297afcfe4c9c5ebc074f92d1badd34b94e8b28f9.1441540862.git.mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org

Acked-by
#57 lore raw

Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl

Quoted 4 lines · Mauro Carvalho Chehab

Add a new ioctl that will report the entire topology on one go.

I do have one suggestion: media_v2_interface, media_v2_pad and media_v2_link all have a 'flags' field, but it is not clear from the code in the header which flag #defines are used for which struct. Perhaps a few comments would help with that.

Quoted 4 lines
include/uapi/linux/media.h +0 -0
index a1bd7afba110..b17f6763aff4 100644

<snip>

include/uapi/linux/media.h struct media_links_enum { · line 304

Quoted 6 lines
include/uapi/linux/media.h +6 -0
+
+struct media_v2_pad {
+	__u32 id;
+	__u32 entity_id;
+	__u32 flags;
+	__u16 reserved[9];

Strange odd number here for no clear reason. Perhaps use 8 or 10 instead?

Anyway, you have my Ack.

Regards,

Hans

#58 lore raw

Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl

In reply to a message not in the archive

Hi Mauro,

Thank you for the patch.

Quoted 45 lines · On Sunday 06 September 2015 09:03:04 Mauro Carvalho Chehab wrote:

Add a new ioctl that will report the entire topology on one go.

include/media/media-entity.h +2 -0
index 7320cdc45833..2d5ad40254b7 100644
@@ -181,6 +181,8 @@ struct media_interface {
  */
 struct media_intf_devnode {
 	struct media_interface		intf;
+
+	/* Should match the fields at media_v2_intf_devnode */
 	u32				major;
 	u32				minor;
 };
include/uapi/linux/media.h +11 -1
index a1bd7afba110..b17f6763aff4 100644
@@ -206,6 +206,10 @@ struct media_pad_desc {
 #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
 #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
 
+#define MEDIA_LNK_FL_LINK_TYPE		(0xf << 28)
+#  define MEDIA_LNK_FL_DATA_LINK	(0 << 28)
+#  define MEDIA_LNK_FL_INTERFACE_LINK	(1 << 28)
+
 struct media_link_desc {
 	struct media_pad_desc source;
 	struct media_pad_desc sink;
@@ -249,11 +253,93 @@ struct media_links_enum {
 #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
 #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
 
-/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
+/*
+ * MC next gen API definitions
+ *
+ * NOTE: The declarations below are close to the MC RFC for the Media
+ *	 Controller, the next generation. Yet, there are a few adjustments
+ *	 to do, as we want to be able to have a functional API before
+ *	 the MC properties change. Those will be properly marked below.

include/uapi/linux/media.h struct media_links_enum { · line 272

Quoted 10 lines
include/uapi/linux/media.h +10 -0
+ *	 Please also notice that I removed "num_pads", "num_links",
+ *	 from the proposal, as a proper userspace application will likely
+ *	 use lists for pads/links, just as we intend to do in Kernelspace.
+ *	 The API definition should be freed from fields that are bound to
+ *	 some specific data structure.
+ *
+ * FIXME: Currently, I opted to name the new types as "media_v2", as this
+ *	  won't cause any conflict with the Kernelspace namespace, nor with
+ *	  the previous kAPI media_*_desc namespace. This can be changed
+ *	  later, before the adding this API upstream.

Yes, that's a good idea. Or at least we need to remove this comment if we decide to keep the v2 names :-)

include/uapi/linux/media.h struct media_links_enum { · line 278

Quoted 6 lines
include/uapi/linux/media.h +6 -0
+ */
+
+
+struct media_v2_entity {
+	__u32 id;
+	char name[64];		/* FIXME: move to a property? (RFC says so) */

I agree with Sakari that we can keep the name here even if we also expose it as a property. However, there's one issue we need to address : we need to clearly define what the name field should contain and how it should be constructed, otherwise we'll end up with the exact same mess as today, and I don't want that. We can discuss it in this mail thread or as replies to a future documentation patch.

include/uapi/linux/media.h struct media_links_enum { · line 279

Quoted 1 line
include/uapi/linux/media.h +1 -0
+	__u16 reserved[14];

Sakari and Hans have already commented on using __u32 instead of __u16 for reserved fields, as well as on the number of reserved fields. I agree with them but have nothing to add.

Quoted 30 lines
include/uapi/linux/media.h +30 -0
+};
+
+/* Should match the specific fields at media_intf_devnode */
+struct media_v2_intf_devnode {
+	__u32 major;
+	__u32 minor;
+};
+
+struct media_v2_interface {
+	__u32 id;
+	__u32 intf_type;
+	__u32 flags;
+	__u32 reserved[9];
+
+	union {
+		struct media_v2_intf_devnode devnode;
+		__u32 raw[16];
+	};
+};
+
+struct media_v2_pad {
+	__u32 id;
+	__u32 entity_id;
+	__u32 flags;
+	__u16 reserved[9];
+};
+
+struct media_v2_link {
+    __u32 id;
+    __u32 source_id;

include/uapi/linux/media.h struct media_links_enum { · line 319

Quoted 10 lines
include/uapi/linux/media.h +10 -0
+    __u32 sink_id;
+    __u32 flags;
+    __u32 reserved[5];
+};
+
+struct media_v2_topology {
+	__u32 topology_version;
+
+	__u32 num_entities;
+	struct media_v2_entity *entities;

The kernel seems to be moving to using __u64 instead of pointers in userspace- facing structures to avoid compat32 code.

Quoted 5 lines
include/uapi/linux/media.h +5 -0
+
+	__u32 num_interfaces;
+	struct media_v2_interface *interfaces;
+
+	__u32 num_pads;

include/uapi/linux/media.h struct media_links_enum { · line 334

Quoted 10 lines
include/uapi/linux/media.h +10 -0
+	struct media_v2_pad *pads;
+
+	__u32 num_links;
+	struct media_v2_link *links;
+
+	struct {
+		__u32 reserved_num;
+		void *reserved_ptr;
+	} reserved_types[16];
+	__u32 reserved[8];

I'd just create __u32 reserved fields without any reserved_types, we can always use the reserved fields to add new types later.

include/uapi/linux/media.h struct media_links_enum {

Quoted 5 lines
include/uapi/linux/media.h +3 -0
+};
+
+/* ioctls */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct 

media_device_info)

include/uapi/linux/media.h struct media_links_enum { · line 340

Quoted 1 line
include/uapi/linux/media.h +0 -0
 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct 

media_entity_desc)

Quoted 5 lines
include/uapi/linux/media.h +1 -0
 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
 #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
+#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
 
 #endif /* __LINUX_MEDIA_H */
Signature · 3 lines
Regards,

Laurent Pinchart
#59 lore raw

Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl

Em Sun, 06 Dec 2015 02:47:39 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 55 lines

Hi Mauro,

Thank you for the patch.

Quoted 50 lines · On Sunday 06 September 2015 09:03:04 Mauro Carvalho Chehab wrote:

Add a new ioctl that will report the entire topology on one go.

include/media/media-entity.h +2 -0
index 7320cdc45833..2d5ad40254b7 100644
@@ -181,6 +181,8 @@ struct media_interface {
  */
 struct media_intf_devnode {
 	struct media_interface		intf;
+
+	/* Should match the fields at media_v2_intf_devnode */
 	u32				major;
 	u32				minor;
 };
include/uapi/linux/media.h +16 -1
index a1bd7afba110..b17f6763aff4 100644
@@ -206,6 +206,10 @@ struct media_pad_desc {
 #define MEDIA_LNK_FL_IMMUTABLE		(1 << 1)
 #define MEDIA_LNK_FL_DYNAMIC		(1 << 2)
 
+#define MEDIA_LNK_FL_LINK_TYPE		(0xf << 28)
+#  define MEDIA_LNK_FL_DATA_LINK	(0 << 28)
+#  define MEDIA_LNK_FL_INTERFACE_LINK	(1 << 28)
+
 struct media_link_desc {
 	struct media_pad_desc source;
 	struct media_pad_desc sink;
@@ -249,11 +253,93 @@ struct media_links_enum {
 #define MEDIA_INTF_T_ALSA_RAWMIDI       (MEDIA_INTF_T_ALSA_BASE + 4)
 #define MEDIA_INTF_T_ALSA_HWDEP         (MEDIA_INTF_T_ALSA_BASE + 5)
 
-/* TBD: declare the structs needed for the new G_TOPOLOGY ioctl */
+/*
+ * MC next gen API definitions
+ *
+ * NOTE: The declarations below are close to the MC RFC for the Media
+ *	 Controller, the next generation. Yet, there are a few adjustments
+ *	 to do, as we want to be able to have a functional API before
+ *	 the MC properties change. Those will be properly marked below.
+ *	 Please also notice that I removed "num_pads", "num_links",
+ *	 from the proposal, as a proper userspace application will likely
+ *	 use lists for pads/links, just as we intend to do in Kernelspace.
+ *	 The API definition should be freed from fields that are bound to
+ *	 some specific data structure.
Quoted 8 lines

include/uapi/linux/media.h struct media_links_enum { · line 272

Quoted 5 lines
include/uapi/linux/media.h +5 -0
+ *
+ * FIXME: Currently, I opted to name the new types as "media_v2", as this
+ *	  won't cause any conflict with the Kernelspace namespace, nor with
+ *	  the previous kAPI media_*_desc namespace. This can be changed
+ *	  later, before the adding this API upstream.

Yes, that's a good idea. Or at least we need to remove this comment if we decide to keep the v2 names :-)

True ;)

Quoted 14 lines

include/uapi/linux/media.h struct media_links_enum { · line 278

Quoted 7 lines
include/uapi/linux/media.h +6 -0
+ */
+
+
+struct media_v2_entity {
+	__u32 id;
+	char name[64];		/* FIXME: move to a property? (RFC says so) */

I agree with Sakari that we can keep the name here even if we also expose it as a property. However, there's one issue we need to address : we need to clearly define what the name field should contain and how it should be constructed, otherwise we'll end up with the exact same mess as today, and I don't want that. We can discuss it in this mail thread or as replies to a future documentation patch.

Well, let's discuss it then. What's your proposal?

I guess there are actually some different goals that we want to archive with "name":

1) an ideally short name used when displaying an entity on some graph. It would be good if such "short name" would be unique, but it won't hurt much if such name is not unique;

2) an unique ID identifier that will likely take the position of an entity inside the machine bus, like PCI ID, USB ID, I2C bus + I2C addr...

I guess such UID would be better addressed via properties, as it would likely be constructed in userspace via a different set of properties, depending on the device and/or bus type.

Quoted 6 lines

include/uapi/linux/media.h struct media_links_enum { · line 279

Quoted 2 lines
include/uapi/linux/media.h +1 -0
+	__u16 reserved[14];

Sakari and Hans have already commented on using __u32 instead of __u16 for reserved fields, as well as on the number of reserved fields. I agree with them but have nothing to add.

Ok. I'll change this on a later patch.

Quoted 36 lines
Quoted 36 lines
include/uapi/linux/media.h +35 -0
+};
+
+/* Should match the specific fields at media_intf_devnode */
+struct media_v2_intf_devnode {
+	__u32 major;
+	__u32 minor;
+};
+
+struct media_v2_interface {
+	__u32 id;
+	__u32 intf_type;
+	__u32 flags;
+	__u32 reserved[9];
+
+	union {
+		struct media_v2_intf_devnode devnode;
+		__u32 raw[16];
+	};
+};
+
+struct media_v2_pad {
+	__u32 id;
+	__u32 entity_id;
+	__u32 flags;
+	__u16 reserved[9];
+};
+
+struct media_v2_link {
+    __u32 id;
+    __u32 source_id;
+    __u32 sink_id;
+    __u32 flags;
+    __u32 reserved[5];
+};
+
Quoted 8 lines

include/uapi/linux/media.h struct media_links_enum { · line 319

Quoted 5 lines
include/uapi/linux/media.h +5 -0
+struct media_v2_topology {
+	__u32 topology_version;
+
+	__u32 num_entities;
+	struct media_v2_entity *entities;

The kernel seems to be moving to using __u64 instead of pointers in userspace- facing structures to avoid compat32 code.

We had such discussion at the MC summit. I don't object to change to __u64, but we need to reach a consensus ;)

Quoted 11 lines
Quoted 11 lines
include/uapi/linux/media.h +10 -0
+
+	__u32 num_interfaces;
+	struct media_v2_interface *interfaces;
+
+	__u32 num_pads;
+	struct media_v2_pad *pads;
+
+	__u32 num_links;
+	struct media_v2_link *links;
+
Quoted 8 lines

include/uapi/linux/media.h struct media_links_enum { · line 334

Quoted 5 lines
include/uapi/linux/media.h +5 -0
+	struct {
+		__u32 reserved_num;
+		void *reserved_ptr;
+	} reserved_types[16];
+	__u32 reserved[8];

I'd just create __u32 reserved fields without any reserved_types, we can always use the reserved fields to add new types later.

It used to be __u32... Hans requested to change it to an struct.

Btw, I also prefer to use __u32 here ;)

Quoted 15 lines

include/uapi/linux/media.h struct media_links_enum {

Quoted 6 lines
include/uapi/linux/media.h +3 -0
+};
+
+/* ioctls */
 
 #define MEDIA_IOC_DEVICE_INFO		_IOWR('|', 0x00, struct 

media_device_info)

include/uapi/linux/media.h struct media_links_enum { · line 340

Quoted 1 line
include/uapi/linux/media.h +0 -0
 #define MEDIA_IOC_ENUM_ENTITIES		_IOWR('|', 0x01, struct 

media_entity_desc)

Quoted 5 lines
include/uapi/linux/media.h +1 -0
 #define MEDIA_IOC_ENUM_LINKS		_IOWR('|', 0x02, struct media_links_enum)
 #define MEDIA_IOC_SETUP_LINK		_IOWR('|', 0x03, struct media_link_desc)
+#define MEDIA_IOC_G_TOPOLOGY		_IOWR('|', 0x04, struct media_v2_topology)
 
 #endif /* __LINUX_MEDIA_H */

A message that is not in the archive (sent off-list or not yet received): [email protected]

#61 lore raw

Re: [PATCH v8 44/55] [media] uapi/media.h: Add MEDIA_IOC_G_TOPOLOGY ioctl

Quoted 10 lines · On Tuesday 08 December 2015 17:23:40 Mauro Carvalho Chehab wrote:
Quoted 9 lines

include/uapi/linux/media.h struct media_links_enum { · line 319

Quoted 6 lines
include/uapi/linux/media.h +6 -0
+
+struct media_v2_topology {
+   __u32 topology_version;
+
+   __u32 num_entities;
+   struct media_v2_entity *entities;

The kernel seems to be moving to using __u64 instead of pointers in userspace- facing structures to avoid compat32 code.

Quoted 3 lines

We had such discussion at the MC summit. I don't object to change to __u64, but we need to reach a consensus

Just saw the email fly by. Using a __u64 to pass a pointer is generally the preferred method for most subsystems these days.

However, that means you probably want to extract the pointer from that using something like

static inline void __user *get_upointer(u64 arg)

{
	return (void __user *)(uintptr_t)arg;
}

This is the only way that I know that works on both 32-bit and 64-bit architectures as well as the oddball s390 compat mode (which you don't care about because there are no media devices on s390).

Arnd

author Acked-by Hans Verkuil
#62 lore raw

Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs

In reply to Mauro Carvalho Chehab

Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize new subdev entities as MEDIA_ENT_T_UNKNOWN.

drivers/media/media-device.c +6 -0
index 659507bce63f..134fe7510195 100644
@@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 {
 	int i;
 
+	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
+	    entity->type == MEDIA_ENT_T_UNKNOWN)
+		dev_warn(mdev->dev,
+			 "Entity type for entity %s was not initialized!\n",
+			 entity->name);
+
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
drivers/media/v4l2-core/v4l2-subdev.c +1 -1
index 60da43772de9..b3bcc8253182 100644
@@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops)
 	sd->host_priv = NULL;
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	sd->entity.name = sd->name;
-	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
 #endif
 }
 EXPORT_SYMBOL(v4l2_subdev_init);
include/uapi/linux/media.h +17 -0
index f8725b881a1d..3d6210095336 100644
@@ -42,6 +42,14 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/* Used values for media_entity_desc::type */
+
+/*
+ * Initial value to be used when a new entity is created
+ * Drivers should change it to something useful
+ */
+#define MEDIA_ENT_T_UNKNOWN	0x00000000
+
 /*
  * Base numbers for entity types
  *
@@ -75,6 +83,15 @@ struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
 
 /* V4L2 Sub-device entities */
+
+	/*
+	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
+	 * in order to preserve backward compatibility.
+	 * Drivers should change to the proper subdev type before
+	 * registering the entity.
+	 */
+#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
Signature · 1 line
2.4.3
maintainer
#63 lore raw

Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs

Hi Mauro,

Thank you for the patch.

In addition to my reply to Sakari's e-mail, please see below for a few small comments.

Quoted 42 lines · On Sunday 06 September 2015 09:02:58 Mauro Carvalho Chehab wrote:

Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize new subdev entities as MEDIA_ENT_T_UNKNOWN.

drivers/media/media-device.c +6 -0
index 659507bce63f..134fe7510195 100644
@@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct
 media_device *mdev, {
 	int i;
 
+	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
+	    entity->type == MEDIA_ENT_T_UNKNOWN)
+		dev_warn(mdev->dev,
+			 "Entity type for entity %s was not initialized!\n",
+			 entity->name);
+
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
(quoted diff) +0 -0

b/drivers/media/v4l2-core/v4l2-subdev.c index 60da43772de9..b3bcc8253182 100644

drivers/media/v4l2-core/v4l2-subdev.c +1 -1
@@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const
 struct v4l2_subdev_ops *ops) sd->host_priv = NULL;
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	sd->entity.name = sd->name;
-	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
 #endif
 }
 EXPORT_SYMBOL(v4l2_subdev_init);
include/uapi/linux/media.h +0 -0
index f8725b881a1d..3d6210095336 100644

include/uapi/linux/media.h struct media_device_info { · line 46

Quoted 5 lines
include/uapi/linux/media.h +2 -0
@@ -42,6 +42,14 @@ struct media_device_info {
 
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/* Used values for media_entity_desc::type */
+

You remove this a couple of patches later, is it worth adding it in the first place ?

include/uapi/linux/media.h struct media_device_info { · line 49

Quoted 3 lines
include/uapi/linux/media.h +3 -0
+/*
+ * Initial value to be used when a new entity is created
+ * Drivers should change it to something useful

As you warn when the value isn't change I'd say "Drivers must change...".

Quoted 7 lines
include/uapi/linux/media.h +3 -0
+ */
+#define MEDIA_ENT_T_UNKNOWN	0x00000000
+
 /*
  * Base numbers for entity types
  *

include/uapi/linux/media.h struct media_device_info { · line 92

Quoted 10 lines
include/uapi/linux/media.h +7 -0
@@ -75,6 +83,15 @@ struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
 
 /* V4L2 Sub-device entities */
+
+	/*
+	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
+	 * in order to preserve backward compatibility.
+	 * Drivers should change to the proper subdev type before
+	 * registering the entity.
+	 */

Leading tabs look weird here.

Quoted 5 lines
include/uapi/linux/media.h +2 -0
+#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
Signature · 3 lines
Regards,

Laurent Pinchart
#64 lore raw

Re: [PATCH v8 38/55] [media] v4l2-subdev: use MEDIA_ENT_T_UNKNOWN for new subdevs

Em Sun, 06 Dec 2015 03:37:59 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 51 lines

Hi Mauro,

Thank you for the patch.

In addition to my reply to Sakari's e-mail, please see below for a few small comments.

Quoted 43 lines · On Sunday 06 September 2015 09:02:58 Mauro Carvalho Chehab wrote:

Instead of abusing MEDIA_ENT_T_V4L2_SUBDEV, initialize new subdev entities as MEDIA_ENT_T_UNKNOWN.

drivers/media/media-device.c +6 -0
index 659507bce63f..134fe7510195 100644
@@ -435,6 +435,12 @@ int __must_check media_device_register_entity(struct
 media_device *mdev, {
 	int i;
 
+	if (entity->type == MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN ||
+	    entity->type == MEDIA_ENT_T_UNKNOWN)
+		dev_warn(mdev->dev,
+			 "Entity type for entity %s was not initialized!\n",
+			 entity->name);
+
 	/* Warn if we apparently re-register an entity */
 	WARN_ON(entity->graph_obj.mdev != NULL);
 	entity->graph_obj.mdev = mdev;
(quoted diff) +0 -0

b/drivers/media/v4l2-core/v4l2-subdev.c index 60da43772de9..b3bcc8253182 100644

drivers/media/v4l2-core/v4l2-subdev.c +1 -1
@@ -584,7 +584,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd, const
 struct v4l2_subdev_ops *ops) sd->host_priv = NULL;
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	sd->entity.name = sd->name;
-	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
+	sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN;
 #endif
 }
 EXPORT_SYMBOL(v4l2_subdev_init);
include/uapi/linux/media.h +0 -0
index f8725b881a1d..3d6210095336 100644
@@ -42,6 +42,14 @@ struct media_device_info {
 
Quoted 7 lines

include/uapi/linux/media.h struct media_device_info { · line 46

Quoted 4 lines
include/uapi/linux/media.h +2 -0
 #define MEDIA_ENT_ID_FLAG_NEXT		(1 << 31)
 
+/* Used values for media_entity_desc::type */
+

You remove this a couple of patches later, is it worth adding it in the first place ?

If you had come with that earlier, I would happily have it removed ;) Right now, I really want to avoid changes on the patches. Handling a 83 patch series, with two ~20 patch series depending on it (Shuah's ALSA patches and Sakari's internal entity numbering series) is not fun.

So, as this is already removed on some other patch, I'll let this hunk as-is.

Quoted 6 lines

include/uapi/linux/media.h struct media_device_info { · line 49

Quoted 4 lines
include/uapi/linux/media.h +3 -0
+/*
+ * Initial value to be used when a new entity is created
+ * Drivers should change it to something useful

As you warn when the value isn't change I'd say "Drivers must change...".

I'll fix this on a later patch.

Quoted 9 lines
Quoted 9 lines
include/uapi/linux/media.h +3 -0
+ */
+#define MEDIA_ENT_T_UNKNOWN	0x00000000
+
 /*
  * Base numbers for entity types
  *
@@ -75,6 +83,15 @@ struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SWRADIO	(MEDIA_ENT_T_V4L2_BASE + 6)
 
Quoted 10 lines

include/uapi/linux/media.h struct media_device_info { · line 92

Quoted 8 lines
include/uapi/linux/media.h +7 -0
 /* V4L2 Sub-device entities */
+
+	/*
+	 * Subdevs are initialized with MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN,
+	 * in order to preserve backward compatibility.
+	 * Drivers should change to the proper subdev type before
+	 * registering the entity.
+	 */

Leading tabs look weird here.

Ok, I'll remove the ident here. This hunk had to be conflict solved anyway, as we merged the MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN addition earlier. I'll do this specific change here, and hope to not cause context conflicts later - it will likely cause - as we renamed from ENT_T_foo to ENT_F_foo :( Let's hope git is smart enough here...

Quoted 7 lines
Quoted 6 lines
include/uapi/linux/media.h +2 -0
+#define MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN	MEDIA_ENT_T_V4L2_SUBDEV_BASE
+
 #define MEDIA_ENT_T_V4L2_SUBDEV_SENSOR	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 1)
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV_BASE + 3)
author Acked-by Hans Verkuil
#65 lore raw

Re: [PATCH v8 20/55] [media] media: make add link more generic

In reply to Mauro Carvalho Chehab

The media_entity_add_link() function takes an entity as an argument just to get the list head.

Make it more generic by changing the function argument to list_head.

No functional changes.

drivers/media/media-entity.c +4 -4
index d5efa0e2c88c..625b505e8496 100644
@@ -580,7 +580,7 @@ EXPORT_SYMBOL_GPL(media_entity_put);
  * Links management
  */
 
-static struct media_link *media_entity_add_link(struct media_entity *entity)
+static struct media_link *media_add_link(struct list_head *head)
 {
 	struct media_link *link;
 
@@ -588,7 +588,7 @@ static struct media_link *media_entity_add_link(struct media_entity *entity)
 	if (link == NULL)
 		return NULL;
 
-	list_add_tail(&link->list, &entity->links);
+	list_add_tail(&link->list, head);
 
 	return link;
 }
@@ -607,7 +607,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	BUG_ON(source_pad >= source->num_pads);
 	BUG_ON(sink_pad >= sink->num_pads);
 
-	link = media_entity_add_link(source);
+	link = media_add_link(&source->links);
 	if (link == NULL)
 		return -ENOMEM;
 
@@ -622,7 +622,7 @@ media_create_pad_link(struct media_entity *source, u16 source_pad,
 	/* Create the backlink. Backlinks are used to help graph traversal and
 	 * are not reported to userspace.
 	 */
-	backlink = media_entity_add_link(sink);
+	backlink = media_add_link(&sink->links);
 	if (backlink == NULL) {
 		__media_entity_remove_link(source, link);
 		return -ENOMEM;
Signature · 1 line
2.4.3
author Acked-by Hans Verkuil
#66 lore raw

Re: [PATCH v8 26/55] [media] media: add a linked list to track interfaces by mdev

In reply to Mauro Carvalho Chehab

The media device should list the interface objects, so add a linked list for those interfaces in struct media_device.

drivers/media/media-device.c +1 -0
index 3e649cacfc07..659507bce63f 100644
@@ -381,6 +381,7 @@ int __must_check __media_device_register(struct media_device *mdev,
 		return -EINVAL;
 
 	INIT_LIST_HEAD(&mdev->entities);
+	INIT_LIST_HEAD(&mdev->interfaces);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
 
drivers/media/media-entity.c +3 -0
index 74aaa5a5d5bc..d8038a53f945 100644
@@ -861,6 +861,8 @@ static void media_interface_init(struct media_device *mdev,
 	INIT_LIST_HEAD(&intf->links);
 
 	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
+
+	list_add_tail(&intf->list, &mdev->interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -889,6 +891,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
 	media_gobj_remove(&devnode->intf.graph_obj);
+	list_del(&devnode->intf.list);
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
include/media/media-device.h +2 -0
index 3b14394d5701..51807efa505b 100644
@@ -46,6 +46,7 @@ struct device;
  * @link_id:	Unique ID used on the last link registered
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
+ * @interfaces:	List of registered interfaces
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -77,6 +78,7 @@ struct media_device {
 	u32 intf_devnode_id;
 
 	struct list_head entities;
+	struct list_head interfaces;
 
 	/* Protects the entities list */
 	spinlock_t lock;
include/media/media-entity.h +3 -0
index f67c01419268..4e36b1f2b2d7 100644
@@ -156,6 +156,8 @@ struct media_entity {
  * struct media_intf_devnode - Define a Kernel API interface
  *
  * @graph_obj:		embedded graph object
+ * @list:		Linked list used to find other interfaces that belong
+ *			to the same media controller
  * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
@@ -164,6 +166,7 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
+	struct list_head		list;
 	struct list_head		links;
 	u32				type;
 	u32				flags;
Signature · 1 line
2.4.3
author Acked-by Hans Verkuil
#67 lore raw

Re: [PATCH v8 21/55] [media] media: make media_link more generic to handle interace links

In reply to Mauro Carvalho Chehab

By adding an union at media_link, we get for free a way to represent interface->entity links.

No need to change anything at the code, just at the internal header file.

include/media/media-entity.h +11 -5
index 7016f0619415..6015e996f213 100644
@@ -75,14 +75,20 @@ struct media_pipeline {
 struct media_link {
 	struct media_gobj graph_obj;
 	struct list_head list;
-	struct media_pad *source;	/* Source pad */
-	struct media_pad *sink;		/* Sink pad  */
+	union {
+		struct media_gobj *gobj0;
+		struct media_pad *source;
+	};
+	union {
+		struct media_gobj *gobj1;
+		struct media_pad *sink;
+	};
 	struct media_link *reverse;	/* Link in the reverse direction */
 	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
 };
 
 struct media_pad {
-	struct media_gobj graph_obj;
+	struct media_gobj graph_obj;	/* must be first field in struct */
 	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_*) */
@@ -105,7 +111,7 @@ struct media_entity_operations {
 };
 
 struct media_entity {
-	struct media_gobj graph_obj;
+	struct media_gobj graph_obj;	/* must be first field in struct */
 	struct list_head list;
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
@@ -119,7 +125,7 @@ struct media_entity {
 	u16 num_backlinks;		/* Number of backlinks */
 
 	struct media_pad *pads;		/* Pads array (num_pads objects) */
-	struct list_head links;		/* Links list */
+	struct list_head links;		/* Pad-to-pad links list */
 
 	const struct media_entity_operations *ops;	/* Entity operations */
 
Signature · 1 line
2.4.3
author Acked-by Hans Verkuil
#68 lore raw

Re: [PATCH v8 22/55] [media] media: make link debug printk more generic

In reply to Mauro Carvalho Chehab

Remove entity name from the link as this exists only if the object type is PAD on both link ends.

drivers/media/media-entity.c +5 -7
index 625b505e8496..f9c6c2a81903 100644
@@ -106,16 +106,14 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 		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",
+			"%s: id 0x%08x link#%d: %s#%d ==> %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),
+			gobj_type(media_type(link->gobj0)),
+			media_localid(link->gobj0),
 
-			link->sink->entity->name,
-			gobj_type(media_type(&link->sink->graph_obj)),
-			media_localid(&link->sink->graph_obj));
+			gobj_type(media_type(link->gobj1)),
+			media_localid(link->gobj1));
 		break;
 	}
 	case MEDIA_GRAPH_PAD:
Signature · 1 line
2.4.3
#69 lore raw

Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj

In reply to Mauro Carvalho Chehab

Let's control the topology changes inside the graph_object. So, move the addition and removal of interfaces/entities from the mdev lists to media_gobj_init() and media_gobj_remove().

The main reason is that mdev should have lists for all object types, as the new MC api will require to store objects in separate places.

drivers/media/media-device.c +1 -3
index 134fe7510195..ec98595b8a7a 100644
@@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
 	struct media_entity *entity;
 	struct media_entity *next;
 
-	list_for_each_entry_safe(entity, next, &mdev->entities, list)
+	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
 
 	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
@@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	spin_lock(&mdev->lock);
 	/* 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++)
@@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity *entity)
 	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);
 	entity->graph_obj.mdev = NULL;
 }
drivers/media/media-entity.c +12 -3
index 6ed5eef88593..cbb0604e81c1 100644
@@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
 		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
+		list_add_tail(&gobj->list, &mdev->entities);
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
@@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
 		break;
 	}
@@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	/* Remove the object from mdev list */
+	switch (media_type(gobj)) {
+	case MEDIA_GRAPH_ENTITY:
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_del(&gobj->list);
+		break;
+	default:
+		break;
+	}
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -864,8 +876,6 @@ static void media_interface_init(struct media_device *mdev,
 	INIT_LIST_HEAD(&intf->links);
 
 	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
-
-	list_add_tail(&intf->list, &mdev->interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -894,7 +904,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
 	media_gobj_remove(&devnode->intf.graph_obj);
-	list_del(&devnode->intf.list);
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
include/media/media-device.h +2 -2
index f23d686aaac6..85fa302047bd 100644
@@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct device *dev);
 
 /* Iterate over all entities. */
 #define media_device_for_each_entity(entity, mdev)			\
-	list_for_each_entry(entity, &(mdev)->entities, list)
+	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
 
 /* Iterate over all interfaces. */
 #define media_device_for_each_intf(intf, mdev)			\
-	list_for_each_entry(intf, &(mdev)->interfaces, list)
+	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
 
 #else
include/media/media-entity.h +1 -2
index 2d5ad40254b7..bc7eb6240795 100644
@@ -66,6 +66,7 @@ enum media_gobj_type {
 struct media_gobj {
 	struct media_device	*mdev;
 	u32			id;
+	struct list_head	list;
 };
 
 
@@ -114,7 +115,6 @@ struct media_entity_operations {
 
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	struct list_head list;
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
@@ -166,7 +166,6 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
-	struct list_head		list;
 	struct list_head		links;
 	u32				type;
 	u32				flags;
Signature · 1 line
2.4.3
Acked-by
#70 lore raw

Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj

Quoted 8 lines · Mauro Carvalho Chehab

Let's control the topology changes inside the graph_object. So, move the addition and removal of interfaces/entities from the mdev lists to media_gobj_init() and media_gobj_remove().

The main reason is that mdev should have lists for all object types, as the new MC api will require to store objects in separate places.

Quoted 131 lines
drivers/media/media-device.c +1 -3
index 134fe7510195..ec98595b8a7a 100644
@@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
 	struct media_entity *entity;
 	struct media_entity *next;
 
-	list_for_each_entry_safe(entity, next, &mdev->entities, list)
+	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
 
 	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
@@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct media_device *mdev,
 	spin_lock(&mdev->lock);
 	/* 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++)
@@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity *entity)
 	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);
 	entity->graph_obj.mdev = NULL;
 }
drivers/media/media-entity.c +12 -3
index 6ed5eef88593..cbb0604e81c1 100644
@@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
 		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
+		list_add_tail(&gobj->list, &mdev->entities);
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
@@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
 		break;
 	}
@@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	/* Remove the object from mdev list */
+	switch (media_type(gobj)) {
+	case MEDIA_GRAPH_ENTITY:
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_del(&gobj->list);
+		break;
+	default:
+		break;
+	}
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -864,8 +876,6 @@ static void media_interface_init(struct media_device *mdev,
 	INIT_LIST_HEAD(&intf->links);
 
 	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
-
-	list_add_tail(&intf->list, &mdev->interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -894,7 +904,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
 	media_gobj_remove(&devnode->intf.graph_obj);
-	list_del(&devnode->intf.list);
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
include/media/media-device.h +2 -2
index f23d686aaac6..85fa302047bd 100644
@@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct device *dev);
 
 /* Iterate over all entities. */
 #define media_device_for_each_entity(entity, mdev)			\
-	list_for_each_entry(entity, &(mdev)->entities, list)
+	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
 
 /* Iterate over all interfaces. */
 #define media_device_for_each_intf(intf, mdev)			\
-	list_for_each_entry(intf, &(mdev)->interfaces, list)
+	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
 
 #else
include/media/media-entity.h +1 -2
index 2d5ad40254b7..bc7eb6240795 100644
@@ -66,6 +66,7 @@ enum media_gobj_type {
 struct media_gobj {
 	struct media_device	*mdev;
 	u32			id;
+	struct list_head	list;
 };
 
 
@@ -114,7 +115,6 @@ struct media_entity_operations {
 
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	struct list_head list;
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
@@ -166,7 +166,6 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
-	struct list_head		list;
 	struct list_head		links;
 	u32				type;
 	u32				flags;
maintainer
#71 lore raw

Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj

In reply to Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

Quoted 59 lines · On Sunday 06 September 2015 09:03:06 Mauro Carvalho Chehab wrote:

Let's control the topology changes inside the graph_object. So, move the addition and removal of interfaces/entities from the mdev lists to media_gobj_init() and media_gobj_remove().

The main reason is that mdev should have lists for all object types, as the new MC api will require to store objects in separate places.

drivers/media/media-device.c +1 -3
index 134fe7510195..ec98595b8a7a 100644
@@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
 	struct media_entity *entity;
 	struct media_entity *next;
 
-	list_for_each_entry_safe(entity, next, &mdev->entities, list)
+	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
 
 	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
@@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct
 media_device *mdev, spin_lock(&mdev->lock);
 	/* 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++)
@@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity
 *entity) 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);
 	entity->graph_obj.mdev = NULL;
 }
drivers/media/media-entity.c +2 -0
index 6ed5eef88593..cbb0604e81c1 100644
@@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
 		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
+		list_add_tail(&gobj->list, &mdev->entities);
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
@@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
 		break;
 	}

drivers/media/media-entity.c void media_gobj_init(struct media_device *mdev, · line 203

Quoted 9 lines
drivers/media/media-entity.c +6 -0
@@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	/* Remove the object from mdev list */
+	switch (media_type(gobj)) {
+	case MEDIA_GRAPH_ENTITY:
+	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_del(&gobj->list);
+		break;

Type-specific handling in the graph object code doesn't seem right. I'd keep the list_del calls in the type-specific remove functions. Same for the list_add_tail calls above, unless we switch from per-type lists to a single graph objects list as I mentioned in a reply to another patch (and the more I think about it the more tempting it gets).

Quoted 71 lines
drivers/media/media-entity.c +4 -3
+	default:
+		break;
+	}
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -864,8 +876,6 @@ static void media_interface_init(struct media_device
 *mdev, INIT_LIST_HEAD(&intf->links);
 
 	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
-
-	list_add_tail(&intf->list, &mdev->interfaces);
 }
 
 /* Functions related to the media interface via device nodes */
@@ -894,7 +904,6 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
 	media_gobj_remove(&devnode->intf.graph_obj);
-	list_del(&devnode->intf.list);
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
include/media/media-device.h +2 -2
index f23d686aaac6..85fa302047bd 100644
@@ -111,11 +111,11 @@ struct media_device *media_device_find_devres(struct
 device *dev);
 
 /* Iterate over all entities. */
 #define media_device_for_each_entity(entity, mdev)			\
-	list_for_each_entry(entity, &(mdev)->entities, list)
+	list_for_each_entry(entity, &(mdev)->entities, graph_obj.list)
 
 /* Iterate over all interfaces. */
 #define media_device_for_each_intf(intf, mdev)			\
-	list_for_each_entry(intf, &(mdev)->interfaces, list)
+	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
 

#else

include/media/media-entity.h +1 -2
index 2d5ad40254b7..bc7eb6240795 100644
@@ -66,6 +66,7 @@ enum media_gobj_type {
 struct media_gobj {
 	struct media_device	*mdev;
 	u32			id;
+	struct list_head	list;
 };
 
 
@@ -114,7 +115,6 @@ struct media_entity_operations {
 
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	struct list_head list;
 	const char *name;		/* Entity name */
 	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
 	u32 revision;			/* Entity revision, driver specific */
@@ -166,7 +166,6 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
-	struct list_head		list;
 	struct list_head		links;
 	u32				type;
 	u32				flags;
Signature · 3 lines
Regards,

Laurent Pinchart
#72 lore raw

Re: [PATCH v8 46/55] [media] media: move mdev list init to gobj

Em Tue, 24 Nov 2015 00:32:49 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 71 lines

Hi Mauro,

Thank you for the patch.

Quoted 66 lines · On Sunday 06 September 2015 09:03:06 Mauro Carvalho Chehab wrote:

Let's control the topology changes inside the graph_object. So, move the addition and removal of interfaces/entities from the mdev lists to media_gobj_init() and media_gobj_remove().

The main reason is that mdev should have lists for all object types, as the new MC api will require to store objects in separate places.

drivers/media/media-device.c +1 -3
index 134fe7510195..ec98595b8a7a 100644
@@ -415,7 +415,7 @@ void media_device_unregister(struct media_device *mdev)
 	struct media_entity *entity;
 	struct media_entity *next;
 
-	list_for_each_entry_safe(entity, next, &mdev->entities, list)
+	list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
 		media_device_unregister_entity(entity);
 
 	device_remove_file(&mdev->devnode.dev, &dev_attr_model);
@@ -449,7 +449,6 @@ int __must_check media_device_register_entity(struct
 media_device *mdev, spin_lock(&mdev->lock);
 	/* 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++)
@@ -487,7 +486,6 @@ void media_device_unregister_entity(struct media_entity
 *entity) 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);
 	entity->graph_obj.mdev = NULL;
 }
drivers/media/media-entity.c +6 -0
index 6ed5eef88593..cbb0604e81c1 100644
@@ -170,6 +170,7 @@ void media_gobj_init(struct media_device *mdev,
 	switch (type) {
 	case MEDIA_GRAPH_ENTITY:
 		gobj->id = media_gobj_gen_id(type, ++mdev->entity_id);
+		list_add_tail(&gobj->list, &mdev->entities);
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
@@ -178,6 +179,7 @@ void media_gobj_init(struct media_device *mdev,
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
 		break;
 	}
@@ -193,6 +195,16 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	/* Remove the object from mdev list */
+	switch (media_type(gobj)) {
+	case MEDIA_GRAPH_ENTITY:
+	case MEDIA_GRAPH_INTF_DEVNODE:
Quoted 8 lines

drivers/media/media-entity.c void media_gobj_init(struct media_device *mdev, · line 203

Quoted 2 lines
drivers/media/media-entity.c +2 -0
+		list_del(&gobj->list);
+		break;

Type-specific handling in the graph object code doesn't seem right. I'd keep the list_del calls in the type-specific remove functions. Same for the list_add_tail calls above, unless we switch from per-type lists to a single graph objects list as I mentioned in a reply to another patch (and the more I think about it the more tempting it gets).

I commented about that already. IMHO, keeping everything needed to unregister a graph object is the way to go, as it saves troubles of having type-specific unregister functions for everything, and the state of the object removal will be sane after the end of calling this function.

Using a single graph object list decreases the performance, as already explained.

Regards,
Mauro

author Acked-by Hans Verkuil
#73 lore raw

Re: [PATCH v8 16/55] [media] media: Don't accept early-created links

In reply to Mauro Carvalho Chehab

Links are graph objects that represent the links of two already existing objects in the graph.

While with the current implementation, it is possible to create the links earlier, It doesn't make any sense to allow linking two objects when they are not both created.

So, remove the code that would be handling those early-created links and add a BUG_ON() to ensure that.

drivers/media/media-device.c +0 -7
index 138b18416460..0d85c6c28004 100644
@@ -443,13 +443,6 @@ 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,
drivers/media/media-entity.c +2 -0
index 27fce6224972..0926f08be981 100644
@@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
 			   enum media_gobj_type type,
 			   struct media_gobj *gobj)
 {
+	BUG_ON(!mdev);
+
 	gobj->mdev = mdev;
 
 	/* Create a per-type unique object ID */
Signature · 1 line
2.4.3
maintainer
#74 lore raw

Re: [PATCH v8 16/55] [media] media: Don't accept early-created links

Hi Mauro,

Thank you for the patch.

Quoted 37 lines · On Sunday 06 September 2015 09:02:47 Mauro Carvalho Chehab wrote:

Links are graph objects that represent the links of two already existing objects in the graph.

While with the current implementation, it is possible to create the links earlier, It doesn't make any sense to allow linking two objects when they are not both created.

So, remove the code that would be handling those early-created links and add a BUG_ON() to ensure that.

drivers/media/media-device.c +0 -7
index 138b18416460..0d85c6c28004 100644
@@ -443,13 +443,6 @@ 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++)
drivers/media/media-device.c +0 -0
 		media_gobj_init(mdev, MEDIA_GRAPH_PAD,
drivers/media/media-entity.c +0 -0
index 27fce6224972..0926f08be981 100644

drivers/media/media-entity.c void media_gobj_init(struct media_device *mdev, · line 165

Quoted 5 lines
drivers/media/media-entity.c +2 -0
@@ -161,6 +161,8 @@ void media_gobj_init(struct media_device *mdev,
 			   enum media_gobj_type type,
 			   struct media_gobj *gobj)
 {
+	BUG_ON(!mdev);
+

Please use a WARN_ON() and return (and possibly make the function return an int error code), we don't want to panic completely for this.

Quoted 3 lines
drivers/media/media-entity.c +0 -0
 	gobj->mdev = mdev;
 
 	/* Create a per-type unique object ID */
Signature · 3 lines
Regards,

Laurent Pinchart
author Acked-by Hans Verkuil
#75 lore raw

Re: [PATCH v8 47/55] [media] media-device: add pads and links to media_device

In reply to Mauro Carvalho Chehab

The MC next gen API sends objects to userspace grouped by their types.

In the case of pads and links, in order to improve performance and have a simpler code, the best is to store them also on separate linked lists at MC.

If we don't do that, we would need this kind of interaction to send data to userspace (code is in structured english):

for each entity:
for each pad:
store pads

for each entity:
for each link:
store link

for each interface:
for each link:
store link

With would require one nexted loop for pads and two nested loops for links. By using separate linked lists for them, just one loop would be enough.

drivers/media/media-device.c +2 -0
index ec98595b8a7a..5b2c9f7fcd45 100644
@@ -382,6 +382,8 @@ int __must_check __media_device_register(struct media_device *mdev,
 
 	INIT_LIST_HEAD(&mdev->entities);
 	INIT_LIST_HEAD(&mdev->interfaces);
+	INIT_LIST_HEAD(&mdev->pads);
+	INIT_LIST_HEAD(&mdev->links);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
 
drivers/media/media-entity.c +6 -11
index cbb0604e81c1..568553d41f5d 100644
@@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
+		list_add_tail(&gobj->list, &mdev->pads);
 		break;
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
+		list_add_tail(&gobj->list, &mdev->links);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
 	dev_dbg_obj(__func__, gobj);
@@ -195,17 +197,10 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	dev_dbg_obj(__func__, gobj);
+
 	/* Remove the object from mdev list */
-	switch (media_type(gobj)) {
-	case MEDIA_GRAPH_ENTITY:
-	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_del(&gobj->list);
-		break;
-	default:
-		break;
-	}
-
-	dev_dbg_obj(__func__, gobj);
+	list_del(&gobj->list);
 }
 
 /**
include/media/media-device.h +12 -0
index 85fa302047bd..0d1b9c687454 100644
@@ -47,6 +47,8 @@ struct device;
  * @intf_devnode_id: Unique ID used on the last interface devnode registered
  * @entities:	List of registered entities
  * @interfaces:	List of registered interfaces
+ * @pads:	List of registered pads
+ * @links:	List of registered links
  * @lock:	Entities list lock
  * @graph_mutex: Entities graph operation lock
  * @link_notify: Link state change notification callback
@@ -79,6 +81,8 @@ struct media_device {
 
 	struct list_head entities;
 	struct list_head interfaces;
+	struct list_head pads;
+	struct list_head links;
 
 	/* Protects the entities list */
 	spinlock_t lock;
@@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct device *dev);
 #define media_device_for_each_intf(intf, mdev)			\
 	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
+/* Iterate over all pads. */
+#define media_device_for_each_pad(pad, mdev)			\
+	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
+
+/* Iterate over all links. */
+#define media_device_for_each_link(link, mdev)			\
+	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
+
 
 #else
 static inline int media_device_register(struct media_device *mdev)
Signature · 1 line
2.4.3
maintainer
#76 lore raw

Re: [PATCH v8 47/55] [media] media-device: add pads and links to media_device

Hi Mauro,

Thank you for the patch.

Quoted 4 lines · On Sunday 06 September 2015 09:03:07 Mauro Carvalho Chehab wrote:

The MC next gen API sends objects to userspace grouped by their types.

In the case of pads and links, in order to improve performance

Are we sure it really improves performances ?

Quoted 2 lines

and have a simpler code, the best is to store them also on separate linked lists at MC.

Have you considered the approach of storing them in a single list of objects instead of per-type lists ? I wonder if it could be helpful. What bothers me here is that we violate layers by using the list field in the graph object structure to store it in lists specific to the individual graph object types. Such violations have proved to be bad ideas in most cases, even if I can't pinpoint why right now. It could of course also be an exception.

Quoted 11 lines

If we don't do that, we would need this kind of interaction to send data to userspace (code is in structured english):

for each entity:
for each pad:
store pads

for each entity:
for each link:
store link

Quoted 5 lines

for each interface:
for each link:
store link

With would require one nexted loop for pads and two nested

s/nexted loop/nested loop/

Quoted 99 lines

loops for links. By using separate linked lists for them, just one loop would be enough.

drivers/media/media-device.c +2 -0
index ec98595b8a7a..5b2c9f7fcd45 100644
@@ -382,6 +382,8 @@ int __must_check __media_device_register(struct
 media_device *mdev,
 
 	INIT_LIST_HEAD(&mdev->entities);
 	INIT_LIST_HEAD(&mdev->interfaces);
+	INIT_LIST_HEAD(&mdev->pads);
+	INIT_LIST_HEAD(&mdev->links);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
drivers/media/media-entity.c +6 -11
index cbb0604e81c1..568553d41f5d 100644
@@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
+		list_add_tail(&gobj->list, &mdev->pads);
 		break;
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
+		list_add_tail(&gobj->list, &mdev->links);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
 	dev_dbg_obj(__func__, gobj);
@@ -195,17 +197,10 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	dev_dbg_obj(__func__, gobj);
+
 	/* Remove the object from mdev list */
-	switch (media_type(gobj)) {
-	case MEDIA_GRAPH_ENTITY:
-	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_del(&gobj->list);
-		break;
-	default:
-		break;
-	}
-
-	dev_dbg_obj(__func__, gobj);
+	list_del(&gobj->list);
 }
 
 /**
include/media/media-device.h +0 -0
index 85fa302047bd..0d1b9c687454 100644
@@ -47,6 +47,8 @@ struct device;
  * @intf_devnode_id: Unique ID used on the last interface devnode

registered * @entities: List of registered entities
* @interfaces: List of registered interfaces
+ * @pads: List of registered pads
+ * @links: List of registered links
* @lock: Entities list lock
* @graph_mutex: Entities graph operation lock
* @link_notify: Link state change notification callback

include/media/media-device.h +10 -0
@@ -79,6 +81,8 @@ struct media_device {
 
 	struct list_head entities;
 	struct list_head interfaces;
+	struct list_head pads;
+	struct list_head links;
 
 	/* Protects the entities list */
 	spinlock_t lock;
@@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct
 device *dev); #define media_device_for_each_intf(intf, mdev)			\
 	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
+/* Iterate over all pads. */
+#define media_device_for_each_pad(pad, mdev)			\
+	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
+
+/* Iterate over all links. */
+#define media_device_for_each_link(link, mdev)			\
+	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
+
 
 #else
 static inline int media_device_register(struct media_device *mdev)
Signature · 3 lines
Regards,

Laurent Pinchart
#77 lore raw

Re: [PATCH v8 47/55] [media] media-device: add pads and links to media_device

Hi Laurent,

Em Tue, 24 Nov 2015 00:28:24 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 11 lines

Hi Mauro,

Thank you for the patch.

Quoted 4 lines · On Sunday 06 September 2015 09:03:07 Mauro Carvalho Chehab wrote:

The MC next gen API sends objects to userspace grouped by their types.

In the case of pads and links, in order to improve performance

Are we sure it really improves performances ?

Yes. The comment here describes what would be needed at __media_device_get_topology() to implement the logic that would retrieve the topology.

Assuming that we have:
e - number of entities
i - number of interfaces
p - number of pads
dl - number of data links
il - number of interface links

With the current code, the number of loop interactions is:

	e + i + p + 2 x (dl + il)

If we use, instead, a single list, the number of loop interactions would be:

	4 x (e + i + p + dl + il)

This is at least two times slower than the option I used.

If we use instead:

Quoted 11 lines
Quoted 11 lines

for each entity:
for each pad:
store pads

for each entity:
for each link:
store link

for each interface:
for each link:
store link

We would have:

	(e + p) + (e + dl + il) + (i + dl + il)

With is worse than the loop we're doing, as it will go twice each entity. Also, the logic of each loop interaction will be more complex. So, the time spent on each loop interaction will be bigger.

The only doubt I actually have is if we should have a separate list to distinguish data links and interface links, as this would improve it even further, reducing the number of loop interactions to:
e + i + p + dl + il

(with is the absolute minimum of interactions for it)

In any case, such change could be done latter, if we identify the need in the future.

Quoted 6 lines
Quoted 3 lines

and have a simpler code, the best is to store them also on separate linked lists at MC.

Have you considered the approach of storing them in a single list of objects instead of per-type lists ? I wonder if it could be helpful.

For the implementation of the __media_device_get_topology(), if we implement the userspace API in a way that we would mix different graph objects, e. g., if we define the API as something like:

struct media_v2_topology {
	__u32 topology_version;

	__u32 num_graph_objects;
	struct media_graph_object *obj;

	void *obj_properties;
};

Then it would make sense to have a single list, because we could just send objects to userspace on any order. However, as we need to split objects per their type, multiple lists can reduce up to 4 times the number of loop interactions when passing those data to userspace.

About the same 4x impact happens internally every time some driver or the core would need to use the object list to find for some specific object of a given type.

Quoted 5 lines

What bothers me
here is that we violate layers by using the list field in the graph object structure to store it in lists specific to the individual graph object types. Such violations have proved to be bad ideas in most cases, even if I can't pinpoint why right now. It could of course also be an exception.

I guess your review on patch 46/55 and 52/55 about bad layering violation are based on the above principle of avoiding to mix layers. If I understood well, in your view media_graph_init() should not do any type-specific code.

Well, on my view, we're actually implementing in C an optimized code for an object-oriented implementation for the media objects.

In that sense, media_graph_init() is actually the constructor of any graph object, and media_graph_remove() its destructor. While on C++ we would use some virtual methods for type-specific handling (and we could be doing that by adding some ops for the type-specific handling at object creation/removal, I opted to just fold such code inside those functions, as:
1) the type-specific handling is actually a very small logic with just a few lines per type;
2) the code will be smaller and simpler;
3) no need to add an "ops" field to be passed to the constructor and be used by the destructor.

So, I think we should handle this as an exception. If this proofs to be wrong, we can redesign it later, as changing it won't affect the uAPI.

Quoted 120 lines
Quoted 12 lines

If we don't do that, we would need this kind of interaction to send data to userspace (code is in structured english):

for each entity:
for each pad:
store pads

for each entity:
for each link:
store link

Quoted 5 lines

for each interface:
for each link:
store link

With would require one nexted loop for pads and two nested

s/nexted loop/nested loop/

Quoted 99 lines

loops for links. By using separate linked lists for them, just one loop would be enough.

drivers/media/media-device.c +2 -0
index ec98595b8a7a..5b2c9f7fcd45 100644
@@ -382,6 +382,8 @@ int __must_check __media_device_register(struct
 media_device *mdev,
 
 	INIT_LIST_HEAD(&mdev->entities);
 	INIT_LIST_HEAD(&mdev->interfaces);
+	INIT_LIST_HEAD(&mdev->pads);
+	INIT_LIST_HEAD(&mdev->links);
 	spin_lock_init(&mdev->lock);
 	mutex_init(&mdev->graph_mutex);
drivers/media/media-entity.c +6 -11
index cbb0604e81c1..568553d41f5d 100644
@@ -174,13 +174,15 @@ void media_gobj_init(struct media_device *mdev,
 		break;
 	case MEDIA_GRAPH_PAD:
 		gobj->id = media_gobj_gen_id(type, ++mdev->pad_id);
+		list_add_tail(&gobj->list, &mdev->pads);
 		break;
 	case MEDIA_GRAPH_LINK:
 		gobj->id = media_gobj_gen_id(type, ++mdev->link_id);
+		list_add_tail(&gobj->list, &mdev->links);
 		break;
 	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_add_tail(&gobj->list, &mdev->interfaces);
 		gobj->id = media_gobj_gen_id(type, ++mdev->intf_devnode_id);
+		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
 	dev_dbg_obj(__func__, gobj);
@@ -195,17 +197,10 @@ void media_gobj_init(struct media_device *mdev,
  */
 void media_gobj_remove(struct media_gobj *gobj)
 {
+	dev_dbg_obj(__func__, gobj);
+
 	/* Remove the object from mdev list */
-	switch (media_type(gobj)) {
-	case MEDIA_GRAPH_ENTITY:
-	case MEDIA_GRAPH_INTF_DEVNODE:
-		list_del(&gobj->list);
-		break;
-	default:
-		break;
-	}
-
-	dev_dbg_obj(__func__, gobj);
+	list_del(&gobj->list);
 }
 
 /**
include/media/media-device.h +0 -0
index 85fa302047bd..0d1b9c687454 100644
@@ -47,6 +47,8 @@ struct device;
  * @intf_devnode_id: Unique ID used on the last interface devnode

registered * @entities: List of registered entities
* @interfaces: List of registered interfaces
+ * @pads: List of registered pads
+ * @links: List of registered links
* @lock: Entities list lock
* @graph_mutex: Entities graph operation lock
* @link_notify: Link state change notification callback

include/media/media-device.h +10 -0
@@ -79,6 +81,8 @@ struct media_device {
 
 	struct list_head entities;
 	struct list_head interfaces;
+	struct list_head pads;
+	struct list_head links;
 
 	/* Protects the entities list */
 	spinlock_t lock;
@@ -117,6 +121,14 @@ struct media_device *media_device_find_devres(struct
 device *dev); #define media_device_for_each_intf(intf, mdev)			\
 	list_for_each_entry(intf, &(mdev)->interfaces, graph_obj.list)
 
+/* Iterate over all pads. */
+#define media_device_for_each_pad(pad, mdev)			\
+	list_for_each_entry(pad, &(mdev)->pads, graph_obj.list)
+
+/* Iterate over all links. */
+#define media_device_for_each_link(link, mdev)			\
+	list_for_each_entry(link, &(mdev)->links, graph_obj.list)
+
 
 #else
 static inline int media_device_register(struct media_device *mdev)
author Acked-by Hans Verkuil
#78 lore raw

Re: [PATCH v8 23/55] [media] media: add support to link interfaces and entities

In reply to Mauro Carvalho Chehab

Now that we have a new graph object called "interfaces", we need to be able to link them to the entities.

Add a linked list to the interfaces to allow them to be linked to the entities.

drivers/media/media-entity.c +38 -0
index f9c6c2a81903..8e17272936c9 100644
@@ -869,6 +869,7 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 
 	intf->type = type;
 	intf->flags = flags;
+	INIT_LIST_HEAD(&intf->links);
 
 	devnode->major = major;
 	devnode->minor = minor;
@@ -886,3 +887,40 @@ void media_devnode_remove(struct media_intf_devnode *devnode)
 	kfree(devnode);
 }
 EXPORT_SYMBOL_GPL(media_devnode_remove);
+
+struct media_link *media_create_intf_link(struct media_entity *entity,
+					    struct media_interface *intf,
+					    u32 flags)
+{
+	struct media_link *link;
+
+	link = media_add_link(&intf->links);
+	if (link == NULL)
+		return NULL;
+
+	link->intf = intf;
+	link->entity = entity;
+	link->flags = flags;
+
+	/* Initialize graph object embedded at the new link */
+	media_gobj_init(intf->graph_obj.mdev, MEDIA_GRAPH_LINK,
+			&link->graph_obj);
+
+	return link;
+}
+EXPORT_SYMBOL_GPL(media_create_intf_link);
+
+
+static void __media_remove_intf_link(struct media_link *link)
+{
+	media_gobj_remove(&link->graph_obj);
+	kfree(link);
+}
+
+void media_remove_intf_link(struct media_link *link)
+{
+	mutex_lock(&link->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_link(link);
+	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_link);
include/media/media-entity.h +9 -0
index 6015e996f213..f67c01419268 100644
@@ -78,10 +78,12 @@ struct media_link {
 	union {
 		struct media_gobj *gobj0;
 		struct media_pad *source;
+		struct media_interface *intf;
 	};
 	union {
 		struct media_gobj *gobj1;
 		struct media_pad *sink;
+		struct media_entity *entity;
 	};
 	struct media_link *reverse;	/* Link in the reverse direction */
 	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
@@ -154,6 +156,7 @@ struct media_entity {
  * struct media_intf_devnode - Define a Kernel API interface
  *
  * @graph_obj:		embedded graph object
+ * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
  *			MEDIA_INTF_T_*
@@ -161,6 +164,7 @@ struct media_entity {
  */
 struct media_interface {
 	struct media_gobj		graph_obj;
+	struct list_head		links;
 	u32				type;
 	u32				flags;
 };
@@ -283,6 +287,11 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 						u32 major, u32 minor,
 						gfp_t gfp_flags);
 void media_devnode_remove(struct media_intf_devnode *devnode);
+struct media_link *media_create_intf_link(struct media_entity *entity,
+					    struct media_interface *intf,
+					    u32 flags);
+void media_remove_intf_link(struct media_link *link);
+
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
 	 (entity)->ops->operation((entity) , ##args) : -ENOIOCTLCMD)
Signature · 1 line
2.4.3
author Acked-by Hans Verkuil
#79 lore raw

Re: [PATCH v8 24/55] [media] media-entity: add a helper function to create interface

In reply to Mauro Carvalho Chehab

As we'll be adding other interface types in the future, put the common interface create code on a separate function.

drivers/media/media-entity.c +14 -9
index 8e17272936c9..74aaa5a5d5bc 100644
@@ -851,6 +851,18 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad)
 EXPORT_SYMBOL_GPL(media_entity_remote_pad);
 
 
+static void media_interface_init(struct media_device *mdev,
+				 struct media_interface *intf,
+				 u32 gobj_type,
+				 u32 intf_type, u32 flags)
+{
+	intf->type = intf_type;
+	intf->flags = flags;
+	INIT_LIST_HEAD(&intf->links);
+
+	media_gobj_init(mdev, gobj_type, &intf->graph_obj);
+}
+
 /* Functions related to the media interface via device nodes */
 
 struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
@@ -859,23 +871,16 @@ struct media_intf_devnode *media_devnode_create(struct media_device *mdev,
 						gfp_t gfp_flags)
 {
 	struct media_intf_devnode *devnode;
-	struct media_interface *intf;
 
 	devnode = kzalloc(sizeof(*devnode), gfp_flags);
 	if (!devnode)
 		return NULL;
 
-	intf = &devnode->intf;
-
-	intf->type = type;
-	intf->flags = flags;
-	INIT_LIST_HEAD(&intf->links);
-
 	devnode->major = major;
 	devnode->minor = minor;
 
-	media_gobj_init(mdev, MEDIA_GRAPH_INTF_DEVNODE,
-		       &devnode->intf.graph_obj);
+	media_interface_init(mdev, &devnode->intf, MEDIA_GRAPH_INTF_DEVNODE,
+			     type, flags);
 
 	return devnode;
 }
Signature · 1 line
2.4.3
author Acked-by Hans Verkuil
#80 lore raw

Re: [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces

In reply to Mauro Carvalho Chehab

Just like we do with entities, use a similar macro for the interfaces loop.

drivers/media/dvb-core/dvbdev.c +2 -1
index 6babc688801b..f00f1a5f279c 100644
@@ -578,9 +578,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
-	list_for_each_entry(intf, &mdev->interfaces, list) {
+	media_device_for_each_intf(intf, mdev) {
 		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
 			media_create_intf_link(ca, intf, 0);
+
 		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
 			media_create_intf_link(tuner, intf, 0);
 
include/media/media-device.h +5 -0
index 51807efa505b..f23d686aaac6 100644
@@ -113,6 +113,11 @@ struct media_device *media_device_find_devres(struct device *dev);
 #define media_device_for_each_entity(entity, mdev)			\
 	list_for_each_entry(entity, &(mdev)->entities, list)
 
+/* Iterate over all interfaces. */
+#define media_device_for_each_intf(intf, mdev)			\
+	list_for_each_entry(intf, &(mdev)->interfaces, list)
+
+
 #else
 static inline int media_device_register(struct media_device *mdev)
 {
Signature · 1 line
2.4.3
maintainer
#81 lore raw

Re: [PATCH v8 45/55] [media] media: Use a macro to interate between all interfaces

Hi Mauro,

Thank you for the patch.

In the subject line, s/interate between all/iterate over all/

Quoted 11 lines · On Sunday 06 September 2015 09:03:05 Mauro Carvalho Chehab wrote:

Just like we do with entities, use a similar macro for the interfaces loop.

(quoted diff) +0 -0

b/drivers/media/dvb-core/dvbdev.c index 6babc688801b..f00f1a5f279c 100644

drivers/media/dvb-core/dvbdev.c void dvb_create_media_graph(struct dvb_adapter *adap) · line 580

Quoted 3 lines
drivers/media/dvb-core/dvbdev.c +0 -0
@@ -578,9 +578,10 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	}
 
 	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca 

*/

Quoted 13 lines
drivers/media/dvb-core/dvbdev.c +2 -1
-	list_for_each_entry(intf, &mdev->interfaces, list) {
+	media_device_for_each_intf(intf, mdev) {
 		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
 			media_create_intf_link(ca, intf, 0);
+
 		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
 			media_create_intf_link(tuner, intf, 0);
 
include/media/media-device.h +0 -0
index 51807efa505b..f23d686aaac6 100644

include/media/media-device.h struct media_device *media_device_find_devres(struct · line 120

Quoted 8 lines
include/media/media-device.h +5 -0
@@ -113,6 +113,11 @@ struct media_device *media_device_find_devres(struct
 device *dev); #define media_device_for_each_entity(entity, mdev)			\
 	list_for_each_entry(entity, &(mdev)->entities, list)
 
+/* Iterate over all interfaces. */
+#define media_device_for_each_intf(intf, mdev)			\
+	list_for_each_entry(intf, &(mdev)->interfaces, list)
+
+

One blank line should be enough.

Quoted 3 lines
include/media/media-device.h +0 -0
 #else
 static inline int media_device_register(struct media_device *mdev)
 {
Signature · 3 lines
Regards,

Laurent Pinchart
#82 lore raw

Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes

In reply to Mauro Carvalho Chehab

V4L2 device (and subdevice) nodes should create an interface, if the Media Controller support is enabled.

Please notice that radio devices should not create an entity, as radio input/output is either via wires or via ALSA.

drivers/media/v4l2-core/v4l2-dev.c +94 -18
index 44b330589787..07123dd569c4 100644
@@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
 	mutex_unlock(&videodev_lock);
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	if (v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV)
-		media_device_unregister_entity(&vdev->entity);
+	if (v4l2_dev->mdev) {
+		/* Remove interfaces and interface links */
+		media_devnode_remove(vdev->intf_devnode);
+		if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
+			media_device_unregister_entity(&vdev->entity);
+	}
 #endif
 
 	/* Do not call v4l2_device_put if there is no release callback set.
@@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device *vdev)
 			BASE_VIDIOC_PRIVATE);
 }
 
+
+static int video_register_media_controller(struct video_device *vdev, int type)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	u32 intf_type;
+	int ret;
+
+	if (!vdev->v4l2_dev->mdev)
+		return 0;
+
+	vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
+
+	switch (type) {
+	case VFL_TYPE_GRABBER:
+		intf_type = MEDIA_INTF_T_V4L_VIDEO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
+		break;
+	case VFL_TYPE_VBI:
+		intf_type = MEDIA_INTF_T_V4L_VBI;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
+		break;
+	case VFL_TYPE_SDR:
+		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
+		break;
+	case VFL_TYPE_RADIO:
+		intf_type = MEDIA_INTF_T_V4L_RADIO;
+		/*
+		 * Radio doesn't have an entity at the V4L2 side to represent
+		 * radio input or output. Instead, the audio input/output goes
+		 * via either physical wires or ALSA.
+		 */
+		break;
+	case VFL_TYPE_SUBDEV:
+		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
+		/* Entity will be created via v4l2_device_register_subdev() */
+		break;
+	default:
+		return 0;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		vdev->entity.name = vdev->name;
+
+		/* Needed just for backward compatibility with legacy MC API */
+		vdev->entity.info.dev.major = VIDEO_MAJOR;
+		vdev->entity.info.dev.minor = vdev->minor;
+
+		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
+						   &vdev->entity);
+		if (ret < 0) {
+			printk(KERN_WARNING
+				"%s: media_device_register_entity failed\n",
+				__func__);
+			return ret;
+		}
+	}
+
+	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
+						  intf_type,
+						  0, VIDEO_MAJOR,
+						  vdev->minor,
+						  GFP_KERNEL);
+	if (!vdev->intf_devnode) {
+		media_device_unregister_entity(&vdev->entity);
+		return -ENOMEM;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		struct media_link *link;
+
+		link = media_create_intf_link(&vdev->entity,
+					      &vdev->intf_devnode->intf, 0);
+		if (!link) {
+			media_devnode_remove(vdev->intf_devnode);
+			media_device_unregister_entity(&vdev->entity);
+			return -ENOMEM;
+		}
+	}
+
+	/* FIXME: how to create the other interface links? */
+
+#endif
+	return 0;
+}
+
 /**
  *	__video_register_device - register video4linux devices
  *	@vdev: video device structure we want to register
@@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
 	/* Increase v4l2_device refcount */
 	v4l2_device_get(vdev->v4l2_dev);
 
-#if defined(CONFIG_MEDIA_CONTROLLER)
 	/* Part 5: Register the entity. */
-	if (vdev->v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
-		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
-		vdev->entity.name = vdev->name;
-		vdev->entity.info.dev.major = VIDEO_MAJOR;
-		vdev->entity.info.dev.minor = vdev->minor;
-		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
-			&vdev->entity);
-		if (ret < 0)
-			printk(KERN_WARNING
-			       "%s: media_device_register_entity failed\n",
-			       __func__);
-	}
-#endif
+	ret = video_register_media_controller(vdev, type);
+
 	/* Part 6: Activate this minor. The char device can now be used. */
 	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
 
drivers/media/v4l2-core/v4l2-device.c +15 -1
index 5b0a30b9252b..e788a085ba96 100644
@@ -249,6 +249,17 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
 #if defined(CONFIG_MEDIA_CONTROLLER)
 		sd->entity.info.dev.major = VIDEO_MAJOR;
 		sd->entity.info.dev.minor = vdev->minor;
+
+		/* Interface is created by __video_register_device() */
+		if (vdev->v4l2_dev->mdev) {
+			struct media_link *link;
+
+			link = media_create_intf_link(&sd->entity,
+						      &vdev->intf_devnode->intf,
+						      0);
+			if (!link)
+				goto clean_up;
+		}
 #endif
 		sd->devnode = vdev;
 	}
@@ -285,7 +296,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
-		media_entity_remove_links(&sd->entity);
+		/*
+		 * No need to explicitly remove links, as both pads and
+		 * links are removed by the function below, in the right order
+		 */
 		media_device_unregister_entity(&sd->entity);
 	}
 #endif
include/media/v4l2-dev.h +1 -0
index acbcd2f5fe7f..eeabf20e87a6 100644
@@ -86,6 +86,7 @@ struct video_device
 {
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
+	struct media_intf_devnode *intf_devnode;
 #endif
 	/* device ops */
 	const struct v4l2_file_operations *fops;
Signature · 1 line
2.4.3
#83 lore raw

Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes

Quoted 133 lines · Mauro Carvalho Chehab

V4L2 device (and subdevice) nodes should create an interface, if the Media Controller support is enabled.

Please notice that radio devices should not create an entity, as radio input/output is either via wires or via ALSA.

drivers/media/v4l2-core/v4l2-dev.c +92 -10
index 44b330589787..07123dd569c4 100644
@@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
 	mutex_unlock(&videodev_lock);
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	if (v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV)
-		media_device_unregister_entity(&vdev->entity);
+	if (v4l2_dev->mdev) {
+		/* Remove interfaces and interface links */
+		media_devnode_remove(vdev->intf_devnode);
+		if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
+			media_device_unregister_entity(&vdev->entity);
+	}
 #endif
 
 	/* Do not call v4l2_device_put if there is no release callback set.
@@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device *vdev)
 			BASE_VIDIOC_PRIVATE);
 }
 
+
+static int video_register_media_controller(struct video_device *vdev, int type)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	u32 intf_type;
+	int ret;
+
+	if (!vdev->v4l2_dev->mdev)
+		return 0;
+
+	vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
+
+	switch (type) {
+	case VFL_TYPE_GRABBER:
+		intf_type = MEDIA_INTF_T_V4L_VIDEO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
+		break;
+	case VFL_TYPE_VBI:
+		intf_type = MEDIA_INTF_T_V4L_VBI;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
+		break;
+	case VFL_TYPE_SDR:
+		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
+		break;
+	case VFL_TYPE_RADIO:
+		intf_type = MEDIA_INTF_T_V4L_RADIO;
+		/*
+		 * Radio doesn't have an entity at the V4L2 side to represent
+		 * radio input or output. Instead, the audio input/output goes
+		 * via either physical wires or ALSA.
+		 */
+		break;
+	case VFL_TYPE_SUBDEV:
+		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
+		/* Entity will be created via v4l2_device_register_subdev() */
+		break;
+	default:
+		return 0;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		vdev->entity.name = vdev->name;
+
+		/* Needed just for backward compatibility with legacy MC API */
+		vdev->entity.info.dev.major = VIDEO_MAJOR;
+		vdev->entity.info.dev.minor = vdev->minor;
+
+		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
+						   &vdev->entity);
+		if (ret < 0) {
+			printk(KERN_WARNING
+				"%s: media_device_register_entity failed\n",
+				__func__);
+			return ret;
+		}
+	}
+
+	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
+						  intf_type,
+						  0, VIDEO_MAJOR,
+						  vdev->minor,
+						  GFP_KERNEL);
+	if (!vdev->intf_devnode) {
+		media_device_unregister_entity(&vdev->entity);
+		return -ENOMEM;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		struct media_link *link;
+
+		link = media_create_intf_link(&vdev->entity,
+					      &vdev->intf_devnode->intf, 0);
+		if (!link) {
+			media_devnode_remove(vdev->intf_devnode);
+			media_device_unregister_entity(&vdev->entity);
+			return -ENOMEM;
+		}
+	}
+
+	/* FIXME: how to create the other interface links? */
+
+#endif
+	return 0;
+}
+
 /**
  *	__video_register_device - register video4linux devices
  *	@vdev: video device structure we want to register
@@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
 	/* Increase v4l2_device refcount */
 	v4l2_device_get(vdev->v4l2_dev);
 
-#if defined(CONFIG_MEDIA_CONTROLLER)
 	/* Part 5: Register the entity. */
-	if (vdev->v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
-		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
-		vdev->entity.name = vdev->name;
-		vdev->entity.info.dev.major = VIDEO_MAJOR;
-		vdev->entity.info.dev.minor = vdev->minor;

drivers/media/v4l2-core/v4l2-dev.c int __video_register_device(struct video_device *vdev, int type, int nr, · line 1002

Quoted 10 lines
drivers/media/v4l2-core/v4l2-dev.c +2 -8
-		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
-			&vdev->entity);
-		if (ret < 0)
-			printk(KERN_WARNING
-			       "%s: media_device_register_entity failed\n",
-			       __func__);
-	}
-#endif
+	ret = video_register_media_controller(vdev, type);
+

This is weird. The 'ret' value is ignored. This was also the case in the original code, but I don't see why it is ignored. I think that if this fails, then an error should be returned. Otherwise you'll have an incomplete media graph.

Regards,

Hans

Quoted 50 lines
drivers/media/v4l2-core/v4l2-dev.c +0 -0
 	/* Part 6: Activate this minor. The char device can now be used. */
 	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
 
drivers/media/v4l2-core/v4l2-device.c +15 -1
index 5b0a30b9252b..e788a085ba96 100644
@@ -249,6 +249,17 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
 #if defined(CONFIG_MEDIA_CONTROLLER)
 		sd->entity.info.dev.major = VIDEO_MAJOR;
 		sd->entity.info.dev.minor = vdev->minor;
+
+		/* Interface is created by __video_register_device() */
+		if (vdev->v4l2_dev->mdev) {
+			struct media_link *link;
+
+			link = media_create_intf_link(&sd->entity,
+						      &vdev->intf_devnode->intf,
+						      0);
+			if (!link)
+				goto clean_up;
+		}
 #endif
 		sd->devnode = vdev;
 	}
@@ -285,7 +296,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
-		media_entity_remove_links(&sd->entity);
+		/*
+		 * No need to explicitly remove links, as both pads and
+		 * links are removed by the function below, in the right order
+		 */
 		media_device_unregister_entity(&sd->entity);
 	}
 #endif
include/media/v4l2-dev.h +1 -0
index acbcd2f5fe7f..eeabf20e87a6 100644
@@ -86,6 +86,7 @@ struct video_device
 {
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
+	struct media_intf_devnode *intf_devnode;
 #endif
 	/* device ops */
 	const struct v4l2_file_operations *fops;
maintainer
#84 lore raw

Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes

In reply to Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

Quoted 5 lines · On Sunday 06 September 2015 09:03:13 Mauro Carvalho Chehab wrote:

V4L2 device (and subdevice) nodes should create an interface, if the Media Controller support is enabled.

Please notice that radio devices should not create an entity, as radio input/output is either via wires or via ALSA.

I'd go one step further, video nodes should not create an entity, ever. This was one of the design principles behind the MC rework. We'll need to patch drivers to create DMA engine entity explicitly, possibly through a helper function (maybe a function to create and initialize a DMA engine entity based on a struct video_device). This can of course be done on a separate patch, but removing the entity field from struct video_device should be part of the series.

Quoted 24 lines
(quoted diff) +0 -0

b/drivers/media/v4l2-core/v4l2-dev.c index 44b330589787..07123dd569c4 100644

drivers/media/v4l2-core/v4l2-dev.c +6 -3
@@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
 	mutex_unlock(&videodev_lock);
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	if (v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV)
-		media_device_unregister_entity(&vdev->entity);
+	if (v4l2_dev->mdev) {
+		/* Remove interfaces and interface links */
+		media_devnode_remove(vdev->intf_devnode);
+		if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
+			media_device_unregister_entity(&vdev->entity);
+	}
 #endif
 
 	/* Do not call v4l2_device_put if there is no release callback set.

drivers/media/v4l2-core/v4l2-dev.c static void determine_valid_ioctls(struct video_device · line 719

Quoted 4 lines
drivers/media/v4l2-core/v4l2-dev.c +1 -0
@@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device
 *vdev) BASE_VIDIOC_PRIVATE);
 }
 
+

Extra blank line.

Quoted 71 lines
drivers/media/v4l2-core/v4l2-dev.c +70 -0
+static int video_register_media_controller(struct video_device *vdev, int
 type)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	u32 intf_type;
+	int ret;
+
+	if (!vdev->v4l2_dev->mdev)
+		return 0;
+
+	vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
+
+	switch (type) {
+	case VFL_TYPE_GRABBER:
+		intf_type = MEDIA_INTF_T_V4L_VIDEO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
+		break;
+	case VFL_TYPE_VBI:
+		intf_type = MEDIA_INTF_T_V4L_VBI;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
+		break;
+	case VFL_TYPE_SDR:
+		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
+		break;
+	case VFL_TYPE_RADIO:
+		intf_type = MEDIA_INTF_T_V4L_RADIO;
+		/*
+		 * Radio doesn't have an entity at the V4L2 side to represent
+		 * radio input or output. Instead, the audio input/output goes
+		 * via either physical wires or ALSA.
+		 */
+		break;
+	case VFL_TYPE_SUBDEV:
+		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
+		/* Entity will be created via v4l2_device_register_subdev() */
+		break;
+	default:
+		return 0;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		vdev->entity.name = vdev->name;
+
+		/* Needed just for backward compatibility with legacy MC API */
+		vdev->entity.info.dev.major = VIDEO_MAJOR;
+		vdev->entity.info.dev.minor = vdev->minor;
+
+		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
+						   &vdev->entity);
+		if (ret < 0) {
+			printk(KERN_WARNING
+				"%s: media_device_register_entity failed\n",
+				__func__);
+			return ret;
+		}
+	}
+
+	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
+						  intf_type,
+						  0, VIDEO_MAJOR,
+						  vdev->minor,
+						  GFP_KERNEL);
+	if (!vdev->intf_devnode) {
+		media_device_unregister_entity(&vdev->entity);
+		return -ENOMEM;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		struct media_link *link;
+

drivers/media/v4l2-core/v4l2-dev.c static void determine_valid_ioctls(struct video_device *vdev) · line 799

Quoted 10 lines
drivers/media/v4l2-core/v4l2-dev.c +10 -0
+		link = media_create_intf_link(&vdev->entity,
+					      &vdev->intf_devnode->intf, 0);
+		if (!link) {
+			media_devnode_remove(vdev->intf_devnode);
+			media_device_unregister_entity(&vdev->entity);
+			return -ENOMEM;
+		}
+	}
+
+	/* FIXME: how to create the other interface links? */

If they're needed (and I'm still not sure they are) they should be created by drivers, possibly with the help of helper functions.

Quoted 81 lines
drivers/media/v4l2-core/v4l2-dev.c +5 -0
+
+#endif
+	return 0;
+}
+
 /**
  *	__video_register_device - register video4linux devices

* @vdev: video device structure we want to register

drivers/media/v4l2-core/v4l2-dev.c +0 -0
@@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev,

int type, int nr, /* Increase v4l2_device refcount */

drivers/media/v4l2-core/v4l2-dev.c +2 -15
 	v4l2_device_get(vdev->v4l2_dev);
 
-#if defined(CONFIG_MEDIA_CONTROLLER)
 	/* Part 5: Register the entity. */
-	if (vdev->v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
-		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
-		vdev->entity.name = vdev->name;
-		vdev->entity.info.dev.major = VIDEO_MAJOR;
-		vdev->entity.info.dev.minor = vdev->minor;
-		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
-			&vdev->entity);
-		if (ret < 0)
-			printk(KERN_WARNING
-			       "%s: media_device_register_entity failed\n",
-			       __func__);
-	}
-#endif
+	ret = video_register_media_controller(vdev, type);
+
 	/* Part 6: Activate this minor. The char device can now be used. */
 	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
(quoted diff) +0 -0

b/drivers/media/v4l2-core/v4l2-device.c index 5b0a30b9252b..e788a085ba96 100644

drivers/media/v4l2-core/v4l2-device.c +15 -1
@@ -249,6 +249,17 @@ int v4l2_device_register_subdev_nodes(struct
 v4l2_device *v4l2_dev) #if defined(CONFIG_MEDIA_CONTROLLER)
 		sd->entity.info.dev.major = VIDEO_MAJOR;
 		sd->entity.info.dev.minor = vdev->minor;
+
+		/* Interface is created by __video_register_device() */
+		if (vdev->v4l2_dev->mdev) {
+			struct media_link *link;
+
+			link = media_create_intf_link(&sd->entity,
+						      &vdev->intf_devnode->intf,
+						      0);
+			if (!link)
+				goto clean_up;
+		}
 #endif
 		sd->devnode = vdev;
 	}
@@ -285,7 +296,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
 *sd)
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
-		media_entity_remove_links(&sd->entity);
+		/*
+		 * No need to explicitly remove links, as both pads and
+		 * links are removed by the function below, in the right order
+		 */
 		media_device_unregister_entity(&sd->entity);
 	}

#endif

include/media/v4l2-dev.h +1 -0
index acbcd2f5fe7f..eeabf20e87a6 100644
@@ -86,6 +86,7 @@ struct video_device
 {
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
+	struct media_intf_devnode *intf_devnode;
 #endif
 	/* device ops */
 	const struct v4l2_file_operations *fops;
Signature · 3 lines
Regards,

Laurent Pinchart
#85 lore raw

Re: [PATCH v8 53/55] [media] v4l2-core: create MC interfaces for devnodes

Em Mon, 23 Nov 2015 23:10:04 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 11 lines

Hi Mauro,

Thank you for the patch.

Quoted 5 lines · On Sunday 06 September 2015 09:03:13 Mauro Carvalho Chehab wrote:

V4L2 device (and subdevice) nodes should create an interface, if the Media Controller support is enabled.

Please notice that radio devices should not create an entity, as radio input/output is either via wires or via ALSA.

Quoted 7 lines

I'd go one step further, video nodes should not create an entity, ever. This was one of the design principles behind the MC rework. We'll need to patch drivers to create DMA engine entity explicitly, possibly through a helper function (maybe a function to create and initialize a DMA engine entity based on a struct video_device). This can of course be done on a separate patch, but removing the entity field from struct video_device should be part of the series.

Not sure what exactly you mean here.

There are two separate things happening with regards to device nodes that do stream I/O:

1) They may have a DMA engine somewhere at the hardware pipeline. On some drivers, like USB ones, the DMA engine is actually not responsible to deliver the data to userspace. This is also true on ALSA and DVB (right now). Also, eventually, some drivers may not have a DMA engine (they may eventually use PIO like some old sound cards);

2) The I/O interface to where the data stream is delivered. This is actually not a hardware interface, but a software implementation on Linux. Ok, on V4L2, this is typically associated with a DMA engine, but the actual interface is a buffer that could be obtained by one of the delivery methods: read()/write() sysctl, mmapped buffer and/or DMABUF.

IMHO, (2) would ideally be mapped as a media_interface, as this is not hardware, but linux software. However, such change won't be backward compatible. So, as agreed at the MC workshop, we're using a media entity for such I/O interface, calling its function as MEDIA_ENT_F_IO (as you may see at the review comments from the others, Shuah requested to actually split this function into one I/O function per type of interface, in order to be able to easily distinguish ALSA I/O from V4L2 I/O).

I agree that (1) should be driver-specific, as only the driver knows where the DMA engine is at the pipeline.

However, (2) should be created by the media core. So, I can't see any rationale to remove the entity field from struct video_device.

Quoted 199 lines
Quoted 25 lines
(quoted diff) +0 -0

b/drivers/media/v4l2-core/v4l2-dev.c index 44b330589787..07123dd569c4 100644

drivers/media/v4l2-core/v4l2-dev.c +6 -3
@@ -194,9 +194,12 @@ static void v4l2_device_release(struct device *cd)
 	mutex_unlock(&videodev_lock);
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
-	if (v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV)
-		media_device_unregister_entity(&vdev->entity);
+	if (v4l2_dev->mdev) {
+		/* Remove interfaces and interface links */
+		media_devnode_remove(vdev->intf_devnode);
+		if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN)
+			media_device_unregister_entity(&vdev->entity);
+	}
 #endif
 
 	/* Do not call v4l2_device_put if there is no release callback set.

drivers/media/v4l2-core/v4l2-dev.c static void determine_valid_ioctls(struct video_device · line 719

Quoted 4 lines
drivers/media/v4l2-core/v4l2-dev.c +1 -0
@@ -713,6 +716,92 @@ static void determine_valid_ioctls(struct video_device
 *vdev) BASE_VIDIOC_PRIVATE);
 }
 
+

Extra blank line.

Quoted 71 lines
drivers/media/v4l2-core/v4l2-dev.c +70 -0
+static int video_register_media_controller(struct video_device *vdev, int
 type)
+{
+#if defined(CONFIG_MEDIA_CONTROLLER)
+	u32 intf_type;
+	int ret;
+
+	if (!vdev->v4l2_dev->mdev)
+		return 0;
+
+	vdev->entity.type = MEDIA_ENT_T_UNKNOWN;
+
+	switch (type) {
+	case VFL_TYPE_GRABBER:
+		intf_type = MEDIA_INTF_T_V4L_VIDEO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
+		break;
+	case VFL_TYPE_VBI:
+		intf_type = MEDIA_INTF_T_V4L_VBI;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_VBI;
+		break;
+	case VFL_TYPE_SDR:
+		intf_type = MEDIA_INTF_T_V4L_SWRADIO;
+		vdev->entity.type = MEDIA_ENT_T_V4L2_SWRADIO;
+		break;
+	case VFL_TYPE_RADIO:
+		intf_type = MEDIA_INTF_T_V4L_RADIO;
+		/*
+		 * Radio doesn't have an entity at the V4L2 side to represent
+		 * radio input or output. Instead, the audio input/output goes
+		 * via either physical wires or ALSA.
+		 */
+		break;
+	case VFL_TYPE_SUBDEV:
+		intf_type = MEDIA_INTF_T_V4L_SUBDEV;
+		/* Entity will be created via v4l2_device_register_subdev() */
+		break;
+	default:
+		return 0;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		vdev->entity.name = vdev->name;
+
+		/* Needed just for backward compatibility with legacy MC API */
+		vdev->entity.info.dev.major = VIDEO_MAJOR;
+		vdev->entity.info.dev.minor = vdev->minor;
+
+		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
+						   &vdev->entity);
+		if (ret < 0) {
+			printk(KERN_WARNING
+				"%s: media_device_register_entity failed\n",
+				__func__);
+			return ret;
+		}
+	}
+
+	vdev->intf_devnode = media_devnode_create(vdev->v4l2_dev->mdev,
+						  intf_type,
+						  0, VIDEO_MAJOR,
+						  vdev->minor,
+						  GFP_KERNEL);
+	if (!vdev->intf_devnode) {
+		media_device_unregister_entity(&vdev->entity);
+		return -ENOMEM;
+	}
+
+	if (vdev->entity.type != MEDIA_ENT_T_UNKNOWN) {
+		struct media_link *link;
+

drivers/media/v4l2-core/v4l2-dev.c static void determine_valid_ioctls(struct video_device *vdev) · line 799

Quoted 10 lines
drivers/media/v4l2-core/v4l2-dev.c +10 -0
+		link = media_create_intf_link(&vdev->entity,
+					      &vdev->intf_devnode->intf, 0);
+		if (!link) {
+			media_devnode_remove(vdev->intf_devnode);
+			media_device_unregister_entity(&vdev->entity);
+			return -ENOMEM;
+		}
+	}
+
+	/* FIXME: how to create the other interface links? */

If they're needed (and I'm still not sure they are) they should be created by drivers, possibly with the help of helper functions.

Quoted 81 lines
drivers/media/v4l2-core/v4l2-dev.c +5 -0
+
+#endif
+	return 0;
+}
+
 /**
  *	__video_register_device - register video4linux devices

* @vdev: video device structure we want to register

drivers/media/v4l2-core/v4l2-dev.c +0 -0
@@ -908,22 +997,9 @@ int __video_register_device(struct video_device *vdev,

int type, int nr, /* Increase v4l2_device refcount */

drivers/media/v4l2-core/v4l2-dev.c +2 -15
 	v4l2_device_get(vdev->v4l2_dev);
 
-#if defined(CONFIG_MEDIA_CONTROLLER)
 	/* Part 5: Register the entity. */
-	if (vdev->v4l2_dev->mdev &&
-	    vdev->vfl_type != VFL_TYPE_SUBDEV) {
-		vdev->entity.type = MEDIA_ENT_T_V4L2_VIDEO;
-		vdev->entity.name = vdev->name;
-		vdev->entity.info.dev.major = VIDEO_MAJOR;
-		vdev->entity.info.dev.minor = vdev->minor;
-		ret = media_device_register_entity(vdev->v4l2_dev->mdev,
-			&vdev->entity);
-		if (ret < 0)
-			printk(KERN_WARNING
-			       "%s: media_device_register_entity failed\n",
-			       __func__);
-	}
-#endif
+	ret = video_register_media_controller(vdev, type);
+
 	/* Part 6: Activate this minor. The char device can now be used. */
 	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
(quoted diff) +0 -0

b/drivers/media/v4l2-core/v4l2-device.c index 5b0a30b9252b..e788a085ba96 100644

drivers/media/v4l2-core/v4l2-device.c +15 -1
@@ -249,6 +249,17 @@ int v4l2_device_register_subdev_nodes(struct
 v4l2_device *v4l2_dev) #if defined(CONFIG_MEDIA_CONTROLLER)
 		sd->entity.info.dev.major = VIDEO_MAJOR;
 		sd->entity.info.dev.minor = vdev->minor;
+
+		/* Interface is created by __video_register_device() */
+		if (vdev->v4l2_dev->mdev) {
+			struct media_link *link;
+
+			link = media_create_intf_link(&sd->entity,
+						      &vdev->intf_devnode->intf,
+						      0);
+			if (!link)
+				goto clean_up;
+		}
 #endif
 		sd->devnode = vdev;
 	}
@@ -285,7 +296,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev
 *sd)
 
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	if (v4l2_dev->mdev) {
-		media_entity_remove_links(&sd->entity);
+		/*
+		 * No need to explicitly remove links, as both pads and
+		 * links are removed by the function below, in the right order
+		 */
 		media_device_unregister_entity(&sd->entity);
 	}

#endif

include/media/v4l2-dev.h +1 -0
index acbcd2f5fe7f..eeabf20e87a6 100644
@@ -86,6 +86,7 @@ struct video_device
 {
 #if defined(CONFIG_MEDIA_CONTROLLER)
 	struct media_entity entity;
+	struct media_intf_devnode *intf_devnode;
 #endif
 	/* device ops */
 	const struct v4l2_file_operations *fops;
author Acked-by Hans Verkuil
#86 lore raw

Re: [PATCH v8 27/55] [media] dvbdev: add support for indirect interface links

In reply to Mauro Carvalho Chehab

Some interfaces indirectly control multiple entities. Add support for those.

drivers/media/dvb-core/dvbdev.c +11 -0
index 6bf61d42c017..ada0738d26f2 100644
@@ -441,6 +441,7 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 	struct media_device *mdev = adap->mdev;
 	struct media_entity *entity, *tuner = NULL, *fe = NULL;
 	struct media_entity *demux = NULL, *dvr = NULL, *ca = NULL;
+	struct media_interface *intf;
 
 	if (!mdev)
 		return;
@@ -476,6 +477,16 @@ void dvb_create_media_graph(struct dvb_adapter *adap)
 
 	if (demux && ca)
 		media_create_pad_link(demux, 1, ca, 0, MEDIA_LNK_FL_ENABLED);
+
+	/* Create indirect interface links for FE->tuner, DVR->demux and CA->ca */
+	list_for_each_entry(intf, &mdev->interfaces, list) {
+		if (intf->type == MEDIA_INTF_T_DVB_CA && ca)
+			media_create_intf_link(ca, intf, 0);
+		if (intf->type == MEDIA_INTF_T_DVB_FE && tuner)
+			media_create_intf_link(tuner, intf, 0);
+		if (intf->type == MEDIA_INTF_T_DVB_DVR && demux)
+			media_create_intf_link(demux, intf, 0);
+	}
 }
 EXPORT_SYMBOL_GPL(dvb_create_media_graph);
 #endif
Signature · 1 line
2.4.3
#87 lore raw

Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities

In reply to Mauro Carvalho Chehab

Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as the types are deprecated. We'll soon be adidng ALSA, but with a different entity namespace;
- improve the description of some entities.

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +21 -26
index 32a783635649..bc101516e372 100644
@@ -179,70 +179,65 @@
         <colspec colname="c2"/>
 	<tbody valign="top">
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
-	    <entry>Unknown device node</entry>
+	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry>
+	    <entry>Unknown entity. That generally indicates that
+	    a driver didn't initialize properly the entity, with is a Kernel bug</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
-	    <entry>V4L video, radio or vbi device node</entry>
+	    <entry>V4L video streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
-	    <entry>Frame buffer device node</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
+	    <entry>V4L VBI streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
-	    <entry>ALSA card</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
+	    <entry>V4L Sofware Digital Radio (SDR) streaming input or output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
-	    <entry>DVB frontend devnode</entry>
+	    <entry>DVB demodulator entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
-	    <entry>DVB demux devnode</entry>
+	    <entry>DVB demux entity. Could be implemented on hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
-	    <entry>DVB DVR devnode</entry>
+	    <entry>DVB Transport Stream output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
-	    <entry>DVB CAM devnode</entry>
+	    <entry>DVB Conditional Access module (CAM) entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
-	    <entry>DVB network devnode</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
-	    <entry>Unknown V4L sub-device</entry>
+	    <entry>DVB network ULE/MLE desencapsulation entity. Could be implemented on hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
-	    <entry>Video sensor</entry>
+	    <entry>Camera video sensor entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
-	    <entry>Flash controller</entry>
+	    <entry>Flash controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
-	    <entry>Lens controller</entry>
+	    <entry>Lens controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
-	    <entry>Video decoder, the basic function of the video decoder is to
-	    accept analogue video from a wide variety of sources such as
+	    <entry>Analog video decoder, the basic function of the video decoder
+	    is to accept analogue video from a wide variety of sources such as
 	    broadcast, DVD players, cameras and video cassette recorders, in
-	    either NTSC, PAL or HD format and still occasionally SECAM, separate
-	    it into its component parts, luminance and chrominance, and output
+	    either NTSC, PAL, SECAM or HD format, separating the stream
+	    into its component parts, luminance and chrominance, and output
 	    it in some digital video standard, with appropriate embedded timing
 	    signals.</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
-	    <entry>TV and/or radio tuner</entry>
+	    <entry>Digital TV, analog TV, radio and/or software radio tuner</entry>
 	  </row>
 	</tbody>
       </tgroup>
Signature · 1 line
2.4.3
#88 lore raw

Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities

Quoted 16 lines · Mauro Carvalho Chehab

Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as the types are deprecated. We'll soon be adidng ALSA, but with a different entity namespace;
- improve the description of some entities.

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -0
index 32a783635649..bc101516e372 100644

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml line 185

Quoted 9 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +3 -2
@@ -179,70 +179,65 @@
         <colspec colname="c2"/>
 	<tbody valign="top">
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
-	    <entry>Unknown device node</entry>
+	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry>
+	    <entry>Unknown entity. That generally indicates that
+	    a driver didn't initialize properly the entity, with is a Kernel bug</entry>
 	  </row>

I'm wondering: if userspace should never see an unknown entity, wouldn't it be better to move these UNKNOWN defines out of the public header to a kernel header and drop this from the documentation?

Quoted 6 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -2
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
-	    <entry>V4L video, radio or vbi device node</entry>
+	    <entry>V4L video streaming input or output entity</entry>
 	  </row>
-	  <row>

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml line 194

Quoted 10 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +4 -5
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
-	    <entry>Frame buffer device node</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
+	    <entry>V4L VBI streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
-	    <entry>ALSA card</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
+	    <entry>V4L Sofware Digital Radio (SDR) streaming input or output entity</entry>

s/Sofware/Software/

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml line 202

Quoted 10 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +2 -2
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
-	    <entry>DVB frontend devnode</entry>
+	    <entry>DVB demodulator entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
-	    <entry>DVB demux devnode</entry>
+	    <entry>DVB demux entity. Could be implemented on hardware or in Kernelspace</entry>

s/on/in/

Quoted 9 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -2
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
-	    <entry>DVB DVR devnode</entry>
+	    <entry>DVB Transport Stream output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
-	    <entry>DVB CAM devnode</entry>

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml line 214

Quoted 10 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +2 -5
+	    <entry>DVB Conditional Access module (CAM) entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
-	    <entry>DVB network devnode</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
-	    <entry>Unknown V4L sub-device</entry>
+	    <entry>DVB network ULE/MLE desencapsulation entity. Could be implemented on hardware or in Kernelspace</entry>

s/on/in/

Hmm, is desencapsulation correct? Could it be 'de-encapsulation' instead? It looks weird.

Quoted 38 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +8 -8
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
-	    <entry>Video sensor</entry>
+	    <entry>Camera video sensor entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
-	    <entry>Flash controller</entry>
+	    <entry>Flash controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
-	    <entry>Lens controller</entry>
+	    <entry>Lens controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
-	    <entry>Video decoder, the basic function of the video decoder is to
-	    accept analogue video from a wide variety of sources such as
+	    <entry>Analog video decoder, the basic function of the video decoder
+	    is to accept analogue video from a wide variety of sources such as
 	    broadcast, DVD players, cameras and video cassette recorders, in
-	    either NTSC, PAL or HD format and still occasionally SECAM, separate
-	    it into its component parts, luminance and chrominance, and output
+	    either NTSC, PAL, SECAM or HD format, separating the stream
+	    into its component parts, luminance and chrominance, and output
 	    it in some digital video standard, with appropriate embedded timing
 	    signals.</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
-	    <entry>TV and/or radio tuner</entry>
+	    <entry>Digital TV, analog TV, radio and/or software radio tuner</entry>
 	  </row>
 	</tbody>
       </tgroup>
maintainer
#89 lore raw

Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities

Hello,

Quoted 25 lines · On Friday 11 September 2015 15:13:30 Hans Verkuil wrote:
Quoted 24 lines · Mauro Carvalho Chehab

Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as the types are deprecated. We'll soon be adidng ALSA, but with a different entity namespace;
- improve the description of some entities.

(quoted diff) +0 -0

b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml index 32a783635649..bc101516e372 100644

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -2
@@ -179,70 +179,65 @@
         <colspec colname="c2"/>
 	<tbody valign="top">
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
-	    <entry>Unknown device node</entry>
+	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and

<constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry> +

Quoted 8 lines
Quoted 4 lines

<entry>Unknown entity. That generally indicates that

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -0
+	    a driver didn't initialize properly the entity, with is a Kernel

bug</entry>>
</row>

I'm wondering: if userspace should never see an unknown entity, wouldn't it be better to move these UNKNOWN defines out of the public header to a kernel header and drop this from the documentation?

And shouldn't the bug be caught in kernelspace before it reaches the user ?

Quoted 20 lines
Quoted 16 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +5 -7
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
-	    <entry>V4L video, radio or vbi device node</entry>
+	    <entry>V4L video streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
-	    <entry>Frame buffer device node</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
+	    <entry>V4L VBI streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
-	    <entry>ALSA card</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
+	    <entry>V4L Sofware Digital Radio (SDR) streaming input or output
Quoted 1 line

entity</entry>

s/Sofware/Software/

Quoted 11 lines
Quoted 11 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +2 -2
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
-	    <entry>DVB frontend devnode</entry>
+	    <entry>DVB demodulator entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
-	    <entry>DVB demux devnode</entry>
+	    <entry>DVB demux entity. Could be implemented on hardware or in

Kernelspace</entry>

s/Could be/Can be/

Quoted 15 lines

s/on/in/

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml line 212

Quoted 13 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +2 -2
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
-	    <entry>DVB DVR devnode</entry>
+	    <entry>DVB Transport Stream output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
-	    <entry>DVB CAM devnode</entry>
+	    <entry>DVB Conditional Access module (CAM) entity</entry>
 	  </row>
 	  <row>

<entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>

Quoted 7 lines
Quoted 7 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -5
-	    <entry>DVB network devnode</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
-	    <entry>Unknown V4L sub-device</entry>
+	    <entry>DVB network ULE/MLE desencapsulation entity. Could be

implemented on hardware or in Kernelspace</entry>

s/Could be/Can be/

Quoted 8 lines

s/on/in/

Hmm, is desencapsulation correct? Could it be 'de-encapsulation' instead? It looks weird.

Quoted 3 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -0
 	  </row>
 	  <row>

<entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>

Quoted 2 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml line 218

Quoted 2 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
-	    <entry>Video sensor</entry>
+	    <entry>Camera video sensor entity</entry>

s/video sensor/image sensor/

Quoted 5 lines
Quoted 5 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
-	    <entry>Flash controller</entry>
+	    <entry>Flash controller entity</entry>
Quoted 8 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml line 228

Quoted 8 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
-	    <entry>Lens controller</entry>
+	    <entry>Lens controller entity</entry>
 	  </row>
 	  <row>

<entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>

Quoted 1 line

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 1 line
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -1
-	    <entry>Video decoder, the basic function of the video decoder is 

to

Quoted 2 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 2 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
-	    accept analogue video from a wide variety of sources such as
+	    <entry>Analog video decoder, the basic function of the video 

decoder

Quoted 1 line

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 1 line
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -0
+	    is to accept analogue video from a wide variety of sources such 

as

Quoted 2 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 2 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -1
 	    broadcast, DVD players, cameras and video cassette recorders, in
-	    either NTSC, PAL or HD format and still occasionally SECAM, 

separate

Quoted 1 line

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 1 line
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -1
-	    it into its component parts, luminance and chrominance, and 

output

Quoted 3 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 3 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +2 -0
+	    either NTSC, PAL, SECAM or HD format, separating the stream
+	    into its component parts, luminance and chrominance, and output
 	    it in some digital video standard, with appropriate embedded 

timing

Quoted 1 line
Quoted 1 line

signals.</entry>

Does timing signals refer to synchronization signals ? They don't have to be embedded, do they ?

Quoted 9 lines
Quoted 9 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
-	    <entry>TV and/or radio tuner</entry>
+	    <entry>Digital TV, analog TV, radio and/or software radio

tuner</entry>>

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -0
 	  </row>
 	</tbody>
       </tgroup>
Signature · 3 lines
Regards,

Laurent Pinchart
#90 lore raw

Re: [PATCH v8 41/55] [media] DocBook: update descriptions for the media controller entities

Em Sun, 06 Dec 2015 03:00:57 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 37 lines

Hello,

Quoted 25 lines · On Friday 11 September 2015 15:13:30 Hans Verkuil wrote:
Quoted 24 lines · Mauro Carvalho Chehab

Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as the types are deprecated. We'll soon be adidng ALSA, but with a different entity namespace;
- improve the description of some entities.

(quoted diff) +0 -0

b/Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml index 32a783635649..bc101516e372 100644

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -2
@@ -179,70 +179,65 @@
         <colspec colname="c2"/>
 	<tbody valign="top">
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
-	    <entry>Unknown device node</entry>
+	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and

<constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry> +

Quoted 8 lines
Quoted 4 lines

<entry>Unknown entity. That generally indicates that

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -0
+	    a driver didn't initialize properly the entity, with is a Kernel

bug</entry>>
</row>

I'm wondering: if userspace should never see an unknown entity, wouldn't it be better to move these UNKNOWN defines out of the public header to a kernel header and drop this from the documentation?

Quoted 1 line

And shouldn't the bug be caught in kernelspace before it reaches the user ?

I don't like the idea of moving this to a Kernel header.

Yes, ideally, the user should never saw this, but IMHO, programs should address this somehow, instead of simply crashing if such value is found. Also, keeping this at documentation helps to inform developers that this value is invalid and should never be present on any driver.

It should be noticed that getting rid of MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN is not easy, and should be addressed on a separate patchset. It requires each driver maintainer to check and fix the non-initialized subdevices, and add new definitions at the public header. This will take a while, and such work is independent on the actual MC next gen patch series.

So, better to keep it documented there, at least while we're not able to enforce the Kernel do do a BUG_ON() or something similar if a driver doesn't fill the entity type/function.

Quoted 110 lines
Quoted 21 lines
Quoted 17 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +5 -7
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
-	    <entry>V4L video, radio or vbi device node</entry>
+	    <entry>V4L video streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
-	    <entry>Frame buffer device node</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
+	    <entry>V4L VBI streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
-	    <entry>ALSA card</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
+	    <entry>V4L Sofware Digital Radio (SDR) streaming input or output
Quoted 1 line

entity</entry>

s/Sofware/Software/

Quoted 11 lines
Quoted 11 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +2 -2
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
-	    <entry>DVB frontend devnode</entry>
+	    <entry>DVB demodulator entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
-	    <entry>DVB demux devnode</entry>
+	    <entry>DVB demux entity. Could be implemented on hardware or in

Kernelspace</entry>

s/Could be/Can be/

Quoted 15 lines

s/on/in/

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 13 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +2 -2
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
-	    <entry>DVB DVR devnode</entry>
+	    <entry>DVB Transport Stream output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
-	    <entry>DVB CAM devnode</entry>
+	    <entry>DVB Conditional Access module (CAM) entity</entry>
 	  </row>
 	  <row>

<entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>

Quoted 7 lines
Quoted 7 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -5
-	    <entry>DVB network devnode</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
-	    <entry>Unknown V4L sub-device</entry>
+	    <entry>DVB network ULE/MLE desencapsulation entity. Could be

implemented on hardware or in Kernelspace</entry>

s/Could be/Can be/

Quoted 8 lines

s/on/in/

Hmm, is desencapsulation correct? Could it be 'de-encapsulation' instead? It looks weird.

Quoted 3 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -0
 	  </row>
 	  <row>

<entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>

Quoted 2 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 2 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
-	    <entry>Video sensor</entry>
+	    <entry>Camera video sensor entity</entry>

s/video sensor/image sensor/

Quoted 5 lines
Quoted 5 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
-	    <entry>Flash controller</entry>
+	    <entry>Flash controller entity</entry>
Quoted 8 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 8 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
-	    <entry>Lens controller</entry>
+	    <entry>Lens controller entity</entry>
 	  </row>
 	  <row>

<entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>

Quoted 1 line

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 1 line
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -1
-	    <entry>Video decoder, the basic function of the video decoder is 

to

Quoted 2 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 2 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
-	    accept analogue video from a wide variety of sources such as
+	    <entry>Analog video decoder, the basic function of the video 

decoder

Quoted 1 line

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 1 line
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -0
+	    is to accept analogue video from a wide variety of sources such 

as

Quoted 2 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 2 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -1
 	    broadcast, DVD players, cameras and video cassette recorders, in
-	    either NTSC, PAL or HD format and still occasionally SECAM, 

separate

Quoted 1 line

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 1 line
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -1
-	    it into its component parts, luminance and chrominance, and 

output

Quoted 3 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 3 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +2 -0
+	    either NTSC, PAL, SECAM or HD format, separating the stream
+	    into its component parts, luminance and chrominance, and output
 	    it in some digital video standard, with appropriate embedded 

timing

Quoted 1 line
Quoted 1 line

signals.</entry>

Does timing signals refer to synchronization signals ? They don't have to be embedded, do they ?

Quoted 10 lines
Quoted 9 lines

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml

Quoted 9 lines
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +1 -1
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
-	    <entry>TV and/or radio tuner</entry>
+	    <entry>Digital TV, analog TV, radio and/or software radio

tuner</entry>>

Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +0 -0
 	  </row>
 	</tbody>
       </tgroup>

Changes done.

New patch follows.

Quoted 1 line

From 88a5f01638adaf0c5f0fe2dfb34b3a68a2997d8a Mon Sep 17 00:00:00 2001

From: Mauro Carvalho Chehab <[email protected]>
Date: Thu, 7 May 2015 22:12:40 -0300
Subject: [media] DocBook: update descriptions for the media controller
entities
Cc: Linux Media Mailing List <[email protected]>,
Mauro Carvalho Chehab <[email protected]>

Cleanup the media controller entities description:
- remove MEDIA_ENT_T_DEVNODE and MEDIA_ENT_T_V4L2_SUBDEV entity types, as they don't mean anything;
- add MEDIA_ENT_T_UNKNOWN with a proper description;
- remove ALSA and FB entity types. Those should not be used, as the types are deprecated. We'll soon be adidng ALSA, but with a different entity namespace;
- improve the description of some entities.

Change-Id I0db7672809b567e04a5f367ff6b31315f7b7be8a
---
 Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml |   49 +++++-------
 1 file changed, 22 insertions(+), 27 deletions(-)
Documentation/DocBook/media/v4l/media-ioc-enum-entities.xml +22 -27
@@ -179,70 +179,65 @@
         <colspec colname="c2"/>
 	<tbody valign="top">
 	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE</constant></entry>
-	    <entry>Unknown device node</entry>
+	    <entry><constant>MEDIA_ENT_T_UNKNOWN</constant> and <constant>MEDIA_ENT_T_V4L2_SUBDEV_UNKNOWN</constant></entry>
+	    <entry>Unknown entity. That generally indicates that
+	    a driver didn't initialize properly the entity, with is a Kernel bug</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_VIDEO</constant></entry>
-	    <entry>V4L video, radio or vbi device node</entry>
+	    <entry>V4L video streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_FB</constant></entry>
-	    <entry>Frame buffer device node</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_VBI</constant></entry>
+	    <entry>V4L VBI streaming input or output entity</entry>
 	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_DEVNODE_ALSA</constant></entry>
-	    <entry>ALSA card</entry>
+	    <entry><constant>MEDIA_ENT_T_V4L2_SWRADIO</constant></entry>
+	    <entry>V4L Software Digital Radio (SDR) streaming input or output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD</constant></entry>
-	    <entry>DVB frontend devnode</entry>
+	    <entry>DVB demodulator entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMUX</constant></entry>
-	    <entry>DVB demux devnode</entry>
+	    <entry>DVB demux entity. Can be implemented in hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_TSOUT</constant></entry>
-	    <entry>DVB DVR devnode</entry>
+	    <entry>DVB Transport Stream output entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_CA</constant></entry>
-	    <entry>DVB CAM devnode</entry>
+	    <entry>DVB Conditional Access module (CAM) entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_DVB_DEMOD_NET_DECAP</constant></entry>
-	    <entry>DVB network devnode</entry>
-	  </row>
-	  <row>
-	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV</constant></entry>
-	    <entry>Unknown V4L sub-device</entry>
+	    <entry>DVB network ULE/MLE de-encapsulation entity. Can be implemented in hardware or in Kernelspace</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_SENSOR</constant></entry>
-	    <entry>Video sensor</entry>
+	    <entry>Camera image sensor entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_FLASH</constant></entry>
-	    <entry>Flash controller</entry>
+	    <entry>Flash controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_LENS</constant></entry>
-	    <entry>Lens controller</entry>
+	    <entry>Lens controller entity</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_DECODER</constant></entry>
-	    <entry>Video decoder, the basic function of the video decoder is to
-	    accept analogue video from a wide variety of sources such as
+	    <entry>Analog video decoder, the basic function of the video decoder
+	    is to accept analogue video from a wide variety of sources such as
 	    broadcast, DVD players, cameras and video cassette recorders, in
-	    either NTSC, PAL or HD format and still occasionally SECAM, separate
-	    it into its component parts, luminance and chrominance, and output
-	    it in some digital video standard, with appropriate embedded timing
+	    either NTSC, PAL, SECAM or HD format, separating the stream
+	    into its component parts, luminance and chrominance, and output
+	    it in some digital video standard, with appropriate timing
 	    signals.</entry>
 	  </row>
 	  <row>
 	    <entry><constant>MEDIA_ENT_T_V4L2_SUBDEV_TUNER</constant></entry>
-	    <entry>TV and/or radio tuner</entry>
+	    <entry>Digital TV, analog TV, radio and/or software radio tuner</entry>
 	  </row>
 	</tbody>
       </tgroup>
#91 lore raw

Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg

In reply to Mauro Carvalho Chehab

Sometimes, it is important to see if the created pad is sink or source. Add info to track that.

drivers/media/media-entity.c +5 -2
index d8038a53f945..6ed5eef88593 100644
@@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 		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),
+			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
+			event_name, gobj->id,
+			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
+			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
+			media_localid(gobj),
 			pad->entity->name, pad->index);
 		break;
 	}
Signature · 1 line
2.4.3
Acked-by
#92 lore raw

Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg

Quoted 4 lines · Mauro Carvalho Chehab

Sometimes, it is important to see if the created pad is sink or source. Add info to track that.

Quoted 20 lines
drivers/media/media-entity.c +5 -2
index d8038a53f945..6ed5eef88593 100644
@@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct media_gobj *gobj)
 		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),
+			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
+			event_name, gobj->id,
+			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
+			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",
+			media_localid(gobj),
 			pad->entity->name, pad->index);
 		break;
 	}
maintainer
#93 lore raw

Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg

In reply to Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

Quoted 10 lines · On Sunday 06 September 2015 09:03:03 Mauro Carvalho Chehab wrote:

Sometimes, it is important to see if the created pad is sink or source. Add info to track that.

drivers/media/media-entity.c +0 -0
index d8038a53f945..6ed5eef88593 100644

drivers/media/media-entity.c static void dev_dbg_obj(const char *event_name, struct · line 127

Quoted 9 lines
drivers/media/media-entity.c +4 -2
@@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct
 media_gobj *gobj) 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),
+			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
+			event_name, gobj->id,
+			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
+			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",

I'm wondering if we really need the two leading spaces in " sink ", as a bidirectional pad would print " sink source pad" and mess up the alignment anyway.

Quoted 4 lines
drivers/media/media-entity.c +1 -0
+			media_localid(gobj),
 			pad->entity->name, pad->index);
 		break;
 	}
Signature · 3 lines
Regards,

Laurent Pinchart
#94 lore raw

Re: [PATCH v8 43/55] [media] media: report if a pad is sink or source at debug msg

Em Sun, 06 Dec 2015 02:53:57 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 17 lines

Hi Mauro,

Thank you for the patch.

Quoted 12 lines · On Sunday 06 September 2015 09:03:03 Mauro Carvalho Chehab wrote:

Sometimes, it is important to see if the created pad is sink or source. Add info to track that.

drivers/media/media-entity.c +0 -0
index d8038a53f945..6ed5eef88593 100644
@@ -121,8 +121,11 @@ static void dev_dbg_obj(const char *event_name,  struct
 media_gobj *gobj) struct media_pad *pad = gobj_to_pad(gobj);
 
Quoted 11 lines

drivers/media/media-entity.c static void dev_dbg_obj(const char *event_name, struct media_gobj *gobj) · line 127

Quoted 7 lines
drivers/media/media-entity.c +4 -2
 		dev_dbg(gobj->mdev->dev,
-			"%s: id 0x%08x pad#%d: '%s':%d\n",
-			event_name, gobj->id, media_localid(gobj),
+			"%s: id 0x%08x %s%spad#%d: '%s':%d\n",
+			event_name, gobj->id,
+			pad->flags & MEDIA_PAD_FL_SINK   ? "  sink " : "",
+			pad->flags & MEDIA_PAD_FL_SOURCE ? "source " : "",

I'm wondering if we really need the two leading spaces in " sink ", as a bidirectional pad would print " sink source pad" and mess up the alignment anyway.

Good point. Right now, we don't have any bidirectional pad. For now, this looks nicer and makes easier to check the logs. So, I prefer to keep it as-is for now.

We can change it later, when we add bidirectional pads.

Quoted 6 lines
Quoted 5 lines
drivers/media/media-entity.c +1 -0
+			media_localid(gobj),
 			pad->entity->name, pad->index);
 		break;
 	}
#95 lore raw

Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA

In reply to Mauro Carvalho Chehab

As we'll be removing entity subtypes from the Kernel, we need to provide a way for drivers and core to check if a given entity is represented by a V4L2 subdev or if it is an V4L2 I/O entity (typically with DMA).

include/media/media-entity.h +33 -0
index 4e36b1f2b2d7..220864319d21 100644
@@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id)
 	return id;
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_VIDEO:
+	case MEDIA_ENT_T_V4L2_VBI:
+	case MEDIA_ENT_T_V4L2_SWRADIO:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
+	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:
+		return true;
+
+	default:
+		return false;
+	}
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
 
Signature · 1 line
2.4.3
maintainer
#96 lore raw

Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA

Hi Mauro,

Thank you for the patch.

Quoted 31 lines · On Sunday 06 September 2015 09:02:57 Mauro Carvalho Chehab wrote:

As we'll be removing entity subtypes from the Kernel, we need to provide a way for drivers and core to check if a given entity is represented by a V4L2 subdev or if it is an V4L2 I/O entity (typically with DMA).

include/media/media-entity.h +16 -0
index 4e36b1f2b2d7..220864319d21 100644
@@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum
 media_gobj_type type, u32 local_id) return id;
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_VIDEO:
+	case MEDIA_ENT_T_V4L2_VBI:
+	case MEDIA_ENT_T_V4L2_SWRADIO:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)

include/media/media-entity.h static inline u32 media_gobj_gen_id(enum · line 248

Quoted 10 lines
include/media/media-entity.h +10 -0
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
+	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:

I'm sorry but this simply won't scale. We need a better way to determine the entity type, and this could be a valid use case to actually retain an entity type field separate from the function, at least inside the kernel.

Quoted 9 lines
include/media/media-entity.h +7 -0
+		return true;
+
+	default:
+		return false;
+	}
+}
+
 #define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
 #define MEDIA_ENTITY_ENUM_MAX_ID	64
Signature · 3 lines
Regards,

Laurent Pinchart
#97 lore raw

Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA

Em Sun, 06 Dec 2015 04:20:38 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 42 lines

Hi Mauro,

Thank you for the patch.

Quoted 37 lines · On Sunday 06 September 2015 09:02:57 Mauro Carvalho Chehab wrote:

As we'll be removing entity subtypes from the Kernel, we need to provide a way for drivers and core to check if a given entity is represented by a V4L2 subdev or if it is an V4L2 I/O entity (typically with DMA).

include/media/media-entity.h +22 -0
index 4e36b1f2b2d7..220864319d21 100644
@@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum
 media_gobj_type type, u32 local_id) return id;
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_VIDEO:
+	case MEDIA_ENT_T_V4L2_VBI:
+	case MEDIA_ENT_T_V4L2_SWRADIO:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
Quoted 8 lines

include/media/media-entity.h static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id) · line 248

Quoted 4 lines
include/media/media-entity.h +4 -0
+	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:

I'm sorry but this simply won't scale. We need a better way to determine the entity type, and this could be a valid use case to actually retain an entity type field separate from the function, at least inside the kernel.

As we're getting rid of a separate range for V4L2 subdevs, several drivers need some logic to identify if an entity is a subdev or not. So, no matter how we implement it, we need a is_media_entity_v4l2_subdev() function.

So, I guess you're discussing the actual implementation, not the need of such function.

With that regards, I'm not sure if this won't scale. The gcc compiler optimizer usually uses binary search on switches. So, O(log(n)). Even if we had 256 subdev types, that would mean 8 ifs. Doesn't seem too bad, specially since we have right now only 5 subdev types.

Ok, there's one thing bad on this: we need to update this function every time a new V4L2 subdev is added. So, it may be a maintainance nightmare, but I don't see any way to avoid the need of adding the subdevs at both UAPI and kernelspace.

I'm not opposed to change this to some other method that we would find. In any case, this is inside an inlined function. So, it is easy to replace the implementation to any other logic we find better. So, if you have a better idea, feel free to submit a followup patch optimizing it.

Regards,
Mauro

maintainer
#98 lore raw

Re: [PATCH v8 31/55] [media] media: add macros to check if subdev or V4L2 DMA

Hi Mauro,

Quoted 50 lines · On Tuesday 08 December 2015 13:41:00 Mauro Carvalho Chehab wrote:

Em Sun, 06 Dec 2015 04:20:38 +0200 Laurent Pinchart escreveu:

Quoted 40 lines · On Sunday 06 September 2015 09:02:57 Mauro Carvalho Chehab wrote:
Quoted 39 lines

As we'll be removing entity subtypes from the Kernel, we need to provide a way for drivers and core to check if a given entity is represented by a V4L2 subdev or if it is an V4L2 I/O entity (typically with DMA).

include/media/media-entity.h +22 -0
index 4e36b1f2b2d7..220864319d21 100644
@@ -220,6 +220,39 @@ static inline u32 media_gobj_gen_id(enum
 media_gobj_type type, u32 local_id) return id;
 
 }
 
+static inline bool is_media_entity_v4l2_io(struct media_entity *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_VIDEO:
+	case MEDIA_ENT_T_V4L2_VBI:
+	case MEDIA_ENT_T_V4L2_SWRADIO:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_media_entity_v4l2_subdev(struct media_entity
 *entity)
+{
+	if (!entity)
+		return false;
+
+	switch (entity->type) {
+	case MEDIA_ENT_T_V4L2_SUBDEV_SENSOR:
Quoted 8 lines

include/media/media-entity.h static inline u32 media_gobj_gen_id(enum media_gobj_type type, u32 local_id) · line 248

Quoted 4 lines
include/media/media-entity.h +4 -0
+	case MEDIA_ENT_T_V4L2_SUBDEV_FLASH:
+	case MEDIA_ENT_T_V4L2_SUBDEV_LENS:
+	case MEDIA_ENT_T_V4L2_SUBDEV_DECODER:
+	case MEDIA_ENT_T_V4L2_SUBDEV_TUNER:

I'm sorry but this simply won't scale. We need a better way to determine the entity type, and this could be a valid use case to actually retain an entity type field separate from the function, at least inside the kernel.

Quoted 6 lines

As we're getting rid of a separate range for V4L2 subdevs, several drivers need some logic to identify if an entity is a subdev or not. So, no matter how we implement it, we need a is_media_entity_v4l2_subdev() function.

So, I guess you're discussing the actual implementation, not the need of such function.

Correct. On a side note, though, the function should probably be moved to a V4L2-specific header file.

Quoted 9 lines

With that regards, I'm not sure if this won't scale. The gcc compiler optimizer usually uses binary search on switches. So, O(log(n)). Even if we had 256 subdev types, that would mean 8 ifs. Doesn't seem too bad, specially since we have right now only 5 subdev types.

Ok, there's one thing bad on this: we need to update this function every time a new V4L2 subdev is added. So, it may be a maintainance nightmare, but I don't see any way to avoid the need of adding the subdevs at both UAPI and kernelspace.

That's part of my concern, yes. I've tried to add video processing functions today and received a WARN_ON() as the is_media_entity_v4l2_subdev() function wasn't updated.

Quoted 5 lines

I'm not opposed to change this to some other method that we would find. In any case, this is inside an inlined function. So, it is easy to replace the implementation to any other logic we find better. So, if you have a better idea, feel free to submit a followup patch optimizing it.

I was hoping you would propose a solution, as you've introduced the problem :-) Any idea ?

Signature · 3 lines
Regards,

Laurent Pinchart
#99 lore raw

Re: [PATCH v8 48/55] [media] media_device: add a topology version field

In reply to Mauro Carvalho Chehab

Every time a graph object is added or removed, the version of the topology changes. That's a requirement for the new MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know that the topology has changed after a previous call to it.

drivers/media/media-entity.c +5 -0
index 568553d41f5d..064515f2ba9b 100644
@@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
 		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
+
+	mdev->topology_version++;
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
 {
 	dev_dbg_obj(__func__, gobj);
 
+	gobj->mdev->topology_version++;
+
 	/* Remove the object from mdev list */
 	list_del(&gobj->list);
 }
include/media/media-device.h +4 -0
index 0d1b9c687454..1b12774a9ab4 100644
@@ -41,6 +41,8 @@ struct device;
  * @bus_info:	Unique and stable device location identifier
  * @hw_revision: Hardware device revision
  * @driver_version: Device driver version
+ * @topology_version: Monotonic counter for storing the version of the graph
+ *		topology. Should be incremented each time the topology changes.
  * @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
@@ -74,6 +76,8 @@ struct media_device {
 	u32 hw_revision;
 	u32 driver_version;
 
+	u32 topology_version;
+
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
Signature · 1 line
2.4.3
Acked-by
#100 lore raw

Re: [PATCH v8 48/55] [media] media_device: add a topology version field

Quoted 6 lines · Mauro Carvalho Chehab

Every time a graph object is added or removed, the version of the topology changes. That's a requirement for the new MEDIA_IOC_G_TOPOLOGY, in order to allow userspace to know that the topology has changed after a previous call to it.

Quoted 47 lines
drivers/media/media-entity.c +5 -0
index 568553d41f5d..064515f2ba9b 100644
@@ -185,6 +185,9 @@ void media_gobj_init(struct media_device *mdev,
 		list_add_tail(&gobj->list, &mdev->interfaces);
 		break;
 	}
+
+	mdev->topology_version++;
+
 	dev_dbg_obj(__func__, gobj);
 }
 
@@ -199,6 +202,8 @@ void media_gobj_remove(struct media_gobj *gobj)
 {
 	dev_dbg_obj(__func__, gobj);
 
+	gobj->mdev->topology_version++;
+
 	/* Remove the object from mdev list */
 	list_del(&gobj->list);
 }
include/media/media-device.h +4 -0
index 0d1b9c687454..1b12774a9ab4 100644
@@ -41,6 +41,8 @@ struct device;
  * @bus_info:	Unique and stable device location identifier
  * @hw_revision: Hardware device revision
  * @driver_version: Device driver version
+ * @topology_version: Monotonic counter for storing the version of the graph
+ *		topology. Should be incremented each time the topology changes.
  * @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
@@ -74,6 +76,8 @@ struct media_device {
 	u32 hw_revision;
 	u32 driver_version;
 
+	u32 topology_version;
+
 	u32 entity_id;
 	u32 pad_id;
 	u32 link_id;
#101 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

In reply to Mauro Carvalho Chehab

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +158 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		if (i > topo->num_links) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 		mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}
@@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
 	case MEDIA_IOC_DEVICE_INFO:
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);
 
 	case MEDIA_IOC_ENUM_LINKS32:
Signature · 1 line
2.4.3
#102 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

Hi Mauro,

A few comments below.

Quoted 15 lines · Mauro Carvalho Chehab

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +2 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 246

Quoted 10 lines
drivers/media/media-device.c +10 -0
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;

I think i wants to be unsigned.

Quoted 68 lines
drivers/media/media-device.c +68 -0
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 324

Quoted 10 lines
drivers/media/media-device.c +10 -0
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;

How about the pad index? Shouldn't that be also passed to the user space for every pad?

Quoted 46 lines
drivers/media/media-device.c +46 -0
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		if (i > topo->num_links) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 380

Quoted 10 lines
drivers/media/media-device.c +10 -0
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));

You can return the result from copy_to_user() without assigning it to ret in between.

Quoted 29 lines
drivers/media/media-device.c +12 -0
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 		mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}
@@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
 	case MEDIA_IOC_DEVICE_INFO:
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);
 
 	case MEDIA_IOC_ENUM_LINKS32:
Signature · 4 lines
Regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#103 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

Em Tue, 8 Sep 2015 01:18:30 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

Hi Mauro,

A few comments below.

Thanks for review!

Quoted 15 lines · Mauro Carvalho Chehab
Quoted 13 lines

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +0 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
Quoted 14 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 246

Quoted 12 lines
drivers/media/media-device.c +12 -0
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;

I think i wants to be unsigned.

Yes, "i" can be unsigned. I'll change that.

Quoted 74 lines
Quoted 74 lines
drivers/media/media-device.c +73 -0
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
Quoted 8 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 324

Quoted 5 lines
drivers/media/media-device.c +5 -0
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;

How about the pad index? Shouldn't that be also passed to the user space for every pad?

We've agreed to not pass the pad index to userspace at the MC workshop.

There are two aspects here to consider:

a) to properly represent the topology (e. g. TOPOLOGY)

Writing the userspace code to support it, I didn't find any need to pass it to userspace, as the data links are connected via the PAD object ID.

The PAD index for userspace is just a number that it uses when generating the dot graph. See:

	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png

This was generated by this tool:
http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c

And no pad index was required at all. What the tool does is that it generates the pad numbers just when the --dot option is used, at the media_show_graphviz() function.

Also, please notice that having a pad index makes harder to support dynamic PAD addition/removal, as the pad index numberspace will be discontinued.

b) using the PAD index to setup a link.

As I argued with Hans on one of his reviews, I don't think that an index is always the best way to refer to a PAD.

See for example, the entity_1 on the au0828 (ATV decoder). It has 3 PADs:
- pad 0 - sink - receives an ATV signal [1]
- pad 1 - source - it outputs a Video stream
- pad 2 - source - it outputs a VBI stream

Pads 1 and 2 are not interchangeable, as they carry different types of data.

[1] Actually, to be honest, pad 0 there is also wrong. In a matter of fact, Composite, S-Video and Tuner interfaces are actually supported by 3 different PADs on the hardware. On some hardware, it is just a software configuration, but on others, different pins are used for each different input type. We just don't need to have all those details ATM on the Media Controller data flow, as the V4L2 input selection API at the /dev/video0 devnode hides those dirty details. Note however that, if we end by adding support for ATV decoder subdevice nodes, such level of detail may be required.

However some other ATV decoder could have mapped it on some different order, like:
- pad 0 - sink - receives an ATV signal
- pad 1 - source - it outputs a VBI stream
- pad 2 - source - it outputs a Video stream

Any (generic) application would need to check the properties of pads 1 and 2 in order to identify what of those pads has video and what pad has VBI. The pad index is meaningless.

Ok, there are cases where the pad index are meaningful. I guess that the best is to use properties to properly identify the pad, or add some strings to them.

Anyway, I guess this should be covered via the properties API.

Quoted 52 lines
Quoted 52 lines
drivers/media/media-device.c +51 -0
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		if (i > topo->num_links) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
Quoted 8 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 380

Quoted 5 lines
drivers/media/media-device.c +5 -0
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));

You can return the result from copy_to_user() without assigning it to ret in between.

True. Will change on the next version.

Quoted 28 lines
Quoted 28 lines
drivers/media/media-device.c +12 -0
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 		mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}
@@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
 	case MEDIA_IOC_DEVICE_INFO:
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);
 
Quoted 2 lines

drivers/media/media-device.c static long media_device_compat_ioctl(struct file *filp, unsigned int cmd, · line 475

Quoted 1 line
drivers/media/media-device.c +0 -0
 	case MEDIA_IOC_ENUM_LINKS32:

Regards,
Mauro

#104 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

Hi Mauro,

Quoted 8 lines · Mauro Carvalho Chehab

Em Tue, 8 Sep 2015 01:18:30 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

Hi Mauro,

A few comments below.

Thanks for review!

You're welcome!

Quoted 175 lines
Quoted 15 lines · Mauro Carvalho Chehab
Quoted 13 lines

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +0 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
Quoted 14 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 246

Quoted 12 lines
drivers/media/media-device.c +12 -0
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;

I think i wants to be unsigned.

Yes, "i" can be unsigned. I'll change that.

Quoted 74 lines
Quoted 74 lines
drivers/media/media-device.c +73 -0
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
Quoted 8 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 324

Quoted 5 lines
drivers/media/media-device.c +5 -0
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;

How about the pad index? Shouldn't that be also passed to the user space for every pad?

We've agreed to not pass the pad index to userspace at the MC workshop.

There are two aspects here to consider:

a) to properly represent the topology (e. g. TOPOLOGY)

Writing the userspace code to support it, I didn't find any need to pass it to userspace, as the data links are connected via the PAD object ID.

The PAD index for userspace is just a number that it uses when generating the dot graph. See:

	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png

This was generated by this tool:
http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c

And no pad index was required at all. What the tool does is that it generates the pad numbers just when the --dot option is used, at the media_show_graphviz() function.

Also, please notice that having a pad index makes harder to support dynamic PAD addition/removal, as the pad index numberspace will be discontinued.

b) using the PAD index to setup a link.

As I argued with Hans on one of his reviews, I don't think that an index is always the best way to refer to a PAD.

See for example, the entity_1 on the au0828 (ATV decoder). It has 3 PADs:
- pad 0 - sink - receives an ATV signal [1]
- pad 1 - source - it outputs a Video stream
- pad 2 - source - it outputs a VBI stream

Pads 1 and 2 are not interchangeable, as they carry different types of data.

[1] Actually, to be honest, pad 0 there is also wrong. In a matter of fact, Composite, S-Video and Tuner interfaces are actually supported by 3 different PADs on the hardware. On some hardware, it is just a software configuration, but on others, different pins are used for each different input type. We just don't need to have all those details ATM on the Media Controller data flow, as the V4L2 input selection API at the /dev/video0 devnode hides those dirty details. Note however that, if we end by adding support for ATV decoder subdevice nodes, such level of detail may be required.

However some other ATV decoder could have mapped it on some different order, like:
- pad 0 - sink - receives an ATV signal
- pad 1 - source - it outputs a VBI stream
- pad 2 - source - it outputs a Video stream

Any (generic) application would need to check the properties of pads 1 and 2 in order to identify what of those pads has video and what pad has VBI. The pad index is meaningless.

Quoted 5 lines

Ok, there are cases where the pad index are meaningful. I guess that the best is to use properties to properly identify the pad, or add some strings to them.

Anyway, I guess this should be covered via the properties API.

That's a good summary, however I believe we have to pay attention to the existing API in order not to break user space. The current expectation is that pad numbers start from zero, their range is contiguous and that they are also stable.

The documentation does not say all that, but that's what's currently offered. That's what I believe all hardware specific applications expect. Generic applications probably have no such limitations.

The pad index is indeed just a number but it's an important one. If we provide the pad ID (i.e. the graph object ID) to the user space, it has none of the three properties, and missing even one would be enough to break the user space.

Then, it indeed becomes a naming issue. Names can be stable even if the index wouldn't be. The user would convert the names to integers that may not be stable.

Do you have a use case for dynamically adding or removing pads --- wouldn't it take a change in hardware topology to do that? If it's software only, I'd definitely favour solutions that didn't involve changes in topology --- software changes are generally very fast, and changing the media device topology for that could also affect the device nodes, forcing the user space to wait for udev to create them. That's very inconvenient when you want to take a photo, for instance.

Signature · 4 lines
Best regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#105 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

Em Tue, 8 Sep 2015 10:26:29 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 195 lines

Hi Mauro,

Quoted 8 lines · Mauro Carvalho Chehab

Em Tue, 8 Sep 2015 01:18:30 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

Hi Mauro,

A few comments below.

Thanks for review!

You're welcome!

Quoted 175 lines
Quoted 15 lines · Mauro Carvalho Chehab
Quoted 13 lines

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +0 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
Quoted 14 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 246

Quoted 12 lines
drivers/media/media-device.c +12 -0
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;

I think i wants to be unsigned.

Yes, "i" can be unsigned. I'll change that.

Quoted 74 lines
Quoted 74 lines
drivers/media/media-device.c +73 -0
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
Quoted 8 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 324

Quoted 5 lines
drivers/media/media-device.c +5 -0
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;

How about the pad index? Shouldn't that be also passed to the user space for every pad?

We've agreed to not pass the pad index to userspace at the MC workshop.

There are two aspects here to consider:

a) to properly represent the topology (e. g. TOPOLOGY)

Writing the userspace code to support it, I didn't find any need to pass it to userspace, as the data links are connected via the PAD object ID.

The PAD index for userspace is just a number that it uses when generating the dot graph. See:

	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png

This was generated by this tool:
http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c

And no pad index was required at all. What the tool does is that it generates the pad numbers just when the --dot option is used, at the media_show_graphviz() function.

Also, please notice that having a pad index makes harder to support dynamic PAD addition/removal, as the pad index numberspace will be discontinued.

b) using the PAD index to setup a link.

As I argued with Hans on one of his reviews, I don't think that an index is always the best way to refer to a PAD.

See for example, the entity_1 on the au0828 (ATV decoder). It has 3 PADs:
- pad 0 - sink - receives an ATV signal [1]
- pad 1 - source - it outputs a Video stream
- pad 2 - source - it outputs a VBI stream

Pads 1 and 2 are not interchangeable, as they carry different types of data.

[1] Actually, to be honest, pad 0 there is also wrong. In a matter of fact, Composite, S-Video and Tuner interfaces are actually supported by 3 different PADs on the hardware. On some hardware, it is just a software configuration, but on others, different pins are used for each different input type. We just don't need to have all those details ATM on the Media Controller data flow, as the V4L2 input selection API at the /dev/video0 devnode hides those dirty details. Note however that, if we end by adding support for ATV decoder subdevice nodes, such level of detail may be required.

However some other ATV decoder could have mapped it on some different order, like:
- pad 0 - sink - receives an ATV signal
- pad 1 - source - it outputs a VBI stream
- pad 2 - source - it outputs a Video stream

Any (generic) application would need to check the properties of pads 1 and 2 in order to identify what of those pads has video and what pad has VBI. The pad index is meaningless.

Quoted 5 lines

Ok, there are cases where the pad index are meaningful. I guess that the best is to use properties to properly identify the pad, or add some strings to them.

Anyway, I guess this should be covered via the properties API.

Quoted 8 lines

That's a good summary, however I believe we have to pay attention to the existing API in order not to break user space. The current expectation is that pad numbers start from zero, their range is contiguous and that they are also stable.

The documentation does not say all that, but that's what's currently offered. That's what I believe all hardware specific applications expect. Generic applications probably have no such limitations.

That's true, but there are two situations here to consider:

1) existing drivers/applications:
- No dynamic support, so PAD numbers are stable. Index is provided via v1;

2) new drivers/applications:
- We need a way to provide stable equivalents to PAD indexes via v2.

Quoted 4 lines

The pad index is indeed just a number but it's an important one. If we provide the pad ID (i.e. the graph object ID) to the user space, it has none of the three properties, and missing even one would be enough to break the user space.

No userspace will be broken on v1 ioctls, as it will still be there.

Quoted 3 lines

Then, it indeed becomes a naming issue. Names can be stable even if the index wouldn't be. The user would convert the names to integers that may not be stable.

Yes, I guess a name is the best alternative here, as it fits both the cases where a simple number index is enough and cases where userspace need to use some other criteria to detect the PAD he needs.

Quoted 7 lines

Do you have a use case for dynamically adding or removing pads --- wouldn't it take a change in hardware topology to do that? If it's software only, I'd definitely favour solutions that didn't involve changes in topology --- software changes are generally very fast, and changing the media device topology for that could also affect the device nodes, forcing the user space to wait for udev to create them. That's very inconvenient when you want to take a photo, for instance.

I'm pretty sure we'll need dynamic pad addition/removal in some future, but they're not of the first use cases I want to address.

There are some hardware that allows to dynamically reconfigure it to provide more PADs. I've seen two different cases of that, at the DVB side:

1) One hardware with a fixed number of pads (like 4 sink pads and 40 source pads), where it is capable of being dynamically configured to become 4 independent hardware entities, each one with one sink pad and a number of source pads. So, it could start like 4 entities, with one sink and 10 sources. However, if user needs more than 10 sources, it can send a command to the hardware to get some unused PADs from the other entities;

2) Firmware or FPGA-based devices, where you can dynamically reconfigure the hardware any time. We have one such driver merged for 4.3 whose vendor is promising to release the FPGA code as an Open Source, in order to allow users to change the hardware in real time.

The first case could actually be handled by always creating 4 entities, each with 40 source pads, and adding a new flag to tell that a pad was not actually created yet, but this sounds hacky and would allocate 4 times more memory for the PADs than actually needed. Btw, the memory allocation is already a problem on one of the hardwares I know that uses this device, as the DVB core doesn't support dynamic filter reconfiguration neither. The amount of memory required there to handle each source PAD on a demux is not small, as one ringbuffer to handle the I/O transfer is needed for each PAD source. We're working to fix it at the DVB side, but having the DVB to use a different number of PADs than what's there at the MC would be really messy.

For the second case, I don't know any alternative but to support dynamic PAD changes.

Please notice that, on DVB, I don't see any usage for subdevs, so there's no need to wait for udev to create new devices to address those new entities/pads.

The second case, e. g. a Firmware/FPGA-based device can also work at the V4L2 side. I remember someone (from Intel - I guess) commenting about one such hardware on one of our media workshops, but it was for some hardware he was not allowed to upstream.

Yeah, assuming that someone would upstream such driver and we would need to find a solution, yeah, reconfiguration while taking a photo can be very inconvenient.

Perhaps the solution for such case would be to create the new pads/entities when the camera software would be loaded, and not when the user takes a photo.

I don't expect us to solve all issues related to dynamic PAD addition this year, but we should be sure that no API changes will be needed at G_TOPOLOGY when we add support for it, and I guess that the right thing here is to provide properties that would allow userspace to retrieve what's needed to uniquely identify a PAD on a stable manner. Eventually, some devices could just use an u32 pad_index properties, while others may use strings.

Regards,
Mauro

#106 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

Hi Mauro,

Quoted 207 lines · Mauro Carvalho Chehab

Em Tue, 8 Sep 2015 10:26:29 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 195 lines

Hi Mauro,

Quoted 8 lines · Mauro Carvalho Chehab

Em Tue, 8 Sep 2015 01:18:30 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

Hi Mauro,

A few comments below.

Thanks for review!

You're welcome!

Quoted 175 lines
Quoted 15 lines · Mauro Carvalho Chehab
Quoted 13 lines

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +0 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
Quoted 14 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 246

Quoted 12 lines
drivers/media/media-device.c +12 -0
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;

I think i wants to be unsigned.

Yes, "i" can be unsigned. I'll change that.

Quoted 74 lines
Quoted 74 lines
drivers/media/media-device.c +73 -0
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
Quoted 8 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 324

Quoted 5 lines
drivers/media/media-device.c +5 -0
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;

How about the pad index? Shouldn't that be also passed to the user space for every pad?

We've agreed to not pass the pad index to userspace at the MC workshop.

There are two aspects here to consider:

a) to properly represent the topology (e. g. TOPOLOGY)

Writing the userspace code to support it, I didn't find any need to pass it to userspace, as the data links are connected via the PAD object ID.

The PAD index for userspace is just a number that it uses when generating the dot graph. See:

	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png

This was generated by this tool:
http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c

And no pad index was required at all. What the tool does is that it generates the pad numbers just when the --dot option is used, at the media_show_graphviz() function.

Also, please notice that having a pad index makes harder to support dynamic PAD addition/removal, as the pad index numberspace will be discontinued.

b) using the PAD index to setup a link.

As I argued with Hans on one of his reviews, I don't think that an index is always the best way to refer to a PAD.

See for example, the entity_1 on the au0828 (ATV decoder). It has 3 PADs:
- pad 0 - sink - receives an ATV signal [1]
- pad 1 - source - it outputs a Video stream
- pad 2 - source - it outputs a VBI stream

Pads 1 and 2 are not interchangeable, as they carry different types of data.

[1] Actually, to be honest, pad 0 there is also wrong. In a matter of fact, Composite, S-Video and Tuner interfaces are actually supported by 3 different PADs on the hardware. On some hardware, it is just a software configuration, but on others, different pins are used for each different input type. We just don't need to have all those details ATM on the Media Controller data flow, as the V4L2 input selection API at the /dev/video0 devnode hides those dirty details. Note however that, if we end by adding support for ATV decoder subdevice nodes, such level of detail may be required.

However some other ATV decoder could have mapped it on some different order, like:
- pad 0 - sink - receives an ATV signal
- pad 1 - source - it outputs a VBI stream
- pad 2 - source - it outputs a Video stream

Any (generic) application would need to check the properties of pads 1 and 2 in order to identify what of those pads has video and what pad has VBI. The pad index is meaningless.

Quoted 5 lines

Ok, there are cases where the pad index are meaningful. I guess that the best is to use properties to properly identify the pad, or add some strings to them.

Anyway, I guess this should be covered via the properties API.

Quoted 8 lines

That's a good summary, however I believe we have to pay attention to the existing API in order not to break user space. The current expectation is that pad numbers start from zero, their range is contiguous and that they are also stable.

The documentation does not say all that, but that's what's currently offered. That's what I believe all hardware specific applications expect. Generic applications probably have no such limitations.

Quoted 5 lines

That's true, but there are two situations here to consider:

1) existing drivers/applications:
- No dynamic support, so PAD numbers are stable. Index is provided via v1;

Agreed, in such cases it's fine as long as the pad indices will be essentially defined by the driver --- as they used to.

Quoted 4 lines

2) new drivers/applications:
- We need a way to provide stable equivalents to PAD indexes via v2.

I propose to only add them once we have the use case. This could be through the property API. My hands are pretty full of other work at the moment but this does not seem urgent either, which is good.

I think that applications that are hardware specific would still often prefer hard-coding the pad number there, but instead use the new interface. Do you think we could guarantee the same pad number stability there, as long as no dynamic hardware changes affecting the pads are made? Such applications couldn't cope with those changes anyway.

Quoted 8 lines
Quoted 5 lines

The pad index is indeed just a number but it's an important one. If we provide the pad ID (i.e. the graph object ID) to the user space, it has none of the three properties, and missing even one would be enough to break the user space.

No userspace will be broken on v1 ioctls, as it will still be there.

Quoted 7 lines
Quoted 3 lines

Then, it indeed becomes a naming issue. Names can be stable even if the index wouldn't be. The user would convert the names to integers that may not be stable.

Yes, I guess a name is the best alternative here, as it fits both the cases where a simple number index is enough and cases where userspace need to use some other criteria to detect the PAD he needs.

I think the names would have to be entity specific. Otherwise we'll have the same entity naming problem there.

Quoted 16 lines
Quoted 8 lines

Do you have a use case for dynamically adding or removing pads --- wouldn't it take a change in hardware topology to do that? If it's software only, I'd definitely favour solutions that didn't involve changes in topology --- software changes are generally very fast, and changing the media device topology for that could also affect the device nodes, forcing the user space to wait for udev to create them. That's very inconvenient when you want to take a photo, for instance.

I'm pretty sure we'll need dynamic pad addition/removal in some future, but they're not of the first use cases I want to address.

There are some hardware that allows to dynamically reconfigure it to provide more PADs. I've seen two different cases of that, at the DVB side:

Quoted 7 lines

1) One hardware with a fixed number of pads (like 4 sink pads and 40 source pads), where it is capable of being dynamically configured to become 4 independent hardware entities, each one with one sink pad and a number of source pads. So, it could start like 4 entities, with one sink and 10 sources. However, if user needs more than 10 sources, it can send a command to the hardware to get some unused PADs from the other entities;

This is not completely unlike many CSI-2 receivers which can share the lanes found in the receiver block between different receivers, say dividing five receiver lanes in 4:1:0 or 2:2:1 configuration among three receivers depending on the connected sensors. Those are not shown to the user space at all.

Althrough that's configuration made in board design time whereas yours is runtime if I understand you correctly.

What are these 40 pads in your example? Is it a DVB demux or something else?

I'm not that much worried about the number alone, but if the pads are indistinguishable from each other, I'd look for other ways to expose (or avoid exposing) them to the user.

Quoted 6 lines

2) Firmware or FPGA-based devices, where you can dynamically reconfigure the hardware any time. We have one such driver merged for 4.3 whose vendor is promising to release the FPGA code as an Open Source, in order to allow users to change the hardware in real time.

If you replace the FPGA configuration with another, it's essentially a new piece of hardware which will require its own driver. Of course you could do that with some limitations, but you have to take it into account in the driver in that case.

Quoted 21 lines

The first case could actually be handled by always creating 4 entities, each with 40 source pads, and adding a new flag to tell that a pad was not actually created yet, but this sounds hacky and would allocate 4 times more memory for the PADs than actually needed. Btw, the memory allocation is already a problem on one of the hardwares I know that uses this device, as the DVB core doesn't support dynamic filter reconfiguration neither. The amount of memory required there to handle each source PAD on a demux is not small, as one ringbuffer to handle the I/O transfer is needed for each PAD source. We're working to fix it at the DVB side, but having the DVB to use a different number of PADs than what's there at the MC would be really messy.

For the second case, I don't know any alternative but to support dynamic PAD changes.

Please notice that, on DVB, I don't see any usage for subdevs, so there's no need to wait for udev to create new devices to address those new entities/pads.

Quoted 8 lines

The second case, e. g. a Firmware/FPGA-based device can also work at the V4L2 side. I remember someone (from Intel - I guess) commenting about one such hardware on one of our media workshops, but it was for some hardware he was not allowed to upstream.

Yeah, assuming that someone would upstream such driver and we would need to find a solution, yeah, reconfiguration while taking a photo can be very inconvenient.

Yes. As the "hardware topology" of such a device is essentially defined by software, I wouldn't try to represent it as hardware. There's a subtle but significant difference to FPGA devices: FPGAs are essentially hardware, albeit you can change the layout to whatever you like, whereas the devices running software require software frameworks to support the device on both sides (the CPU and the device firmware). They more resemble programmable GPUs in that sense: even if what the device does (computes) changes, the drivers do not (and should not).

Quoted 4 lines

Perhaps the solution for such case would be to create the new pads/entities when the camera software would be loaded, and not when the user takes a photo.

Quoted 8 lines

I don't expect us to solve all issues related to dynamic PAD addition this year, but we should be sure that no API changes will be needed at G_TOPOLOGY when we add support for it, and I guess that the right thing here is to provide properties that would allow userspace to retrieve what's needed to uniquely identify a PAD on a stable manner. Eventually, some devices could just use an u32 pad_index properties, while others may use strings.

New properties (such as the name) could be added later on without affecting the existing users that depend on the index.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
#107 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

Em Tue, 08 Sep 2015 16:34:59 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 210 lines

Hi Mauro,

Quoted 207 lines · Mauro Carvalho Chehab

Em Tue, 8 Sep 2015 10:26:29 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 203 lines

Hi Mauro,

Quoted 8 lines · Mauro Carvalho Chehab

Em Tue, 8 Sep 2015 01:18:30 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 3 lines

Hi Mauro,

A few comments below.

Thanks for review!

You're welcome!

Quoted 175 lines
Quoted 15 lines · Mauro Carvalho Chehab
Quoted 13 lines

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +0 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
Quoted 14 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 246

Quoted 12 lines
drivers/media/media-device.c +12 -0
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;

I think i wants to be unsigned.

Yes, "i" can be unsigned. I'll change that.

Quoted 74 lines
Quoted 74 lines
drivers/media/media-device.c +73 -0
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
Quoted 8 lines

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 324

Quoted 5 lines
drivers/media/media-device.c +5 -0
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;

How about the pad index? Shouldn't that be also passed to the user space for every pad?

We've agreed to not pass the pad index to userspace at the MC workshop.

There are two aspects here to consider:

a) to properly represent the topology (e. g. TOPOLOGY)

Writing the userspace code to support it, I didn't find any need to pass it to userspace, as the data links are connected via the PAD object ID.

The PAD index for userspace is just a number that it uses when generating the dot graph. See:

	https://mchehab.fedorapeople.org/mc-next-gen/au0828.png

This was generated by this tool:
http://git.linuxtv.org/cgit.cgi/mchehab/experimental-v4l-utils.git/tree/contrib/test/mc_nextgen_test.c

And no pad index was required at all. What the tool does is that it generates the pad numbers just when the --dot option is used, at the media_show_graphviz() function.

Also, please notice that having a pad index makes harder to support dynamic PAD addition/removal, as the pad index numberspace will be discontinued.

b) using the PAD index to setup a link.

As I argued with Hans on one of his reviews, I don't think that an index is always the best way to refer to a PAD.

See for example, the entity_1 on the au0828 (ATV decoder). It has 3 PADs:
- pad 0 - sink - receives an ATV signal [1]
- pad 1 - source - it outputs a Video stream
- pad 2 - source - it outputs a VBI stream

Pads 1 and 2 are not interchangeable, as they carry different types of data.

[1] Actually, to be honest, pad 0 there is also wrong. In a matter of fact, Composite, S-Video and Tuner interfaces are actually supported by 3 different PADs on the hardware. On some hardware, it is just a software configuration, but on others, different pins are used for each different input type. We just don't need to have all those details ATM on the Media Controller data flow, as the V4L2 input selection API at the /dev/video0 devnode hides those dirty details. Note however that, if we end by adding support for ATV decoder subdevice nodes, such level of detail may be required.

However some other ATV decoder could have mapped it on some different order, like:
- pad 0 - sink - receives an ATV signal
- pad 1 - source - it outputs a VBI stream
- pad 2 - source - it outputs a Video stream

Any (generic) application would need to check the properties of pads 1 and 2 in order to identify what of those pads has video and what pad has VBI. The pad index is meaningless.

Quoted 5 lines

Ok, there are cases where the pad index are meaningful. I guess that the best is to use properties to properly identify the pad, or add some strings to them.

Anyway, I guess this should be covered via the properties API.

That's a good summary, however I believe we have to pay attention to the existing API in order not to break user space. The current expectation is that pad numbers start from zero, their range is contiguous and that they are also stable.

The documentation does not say all that, but that's what's currently offered. That's what I believe all hardware specific applications expect. Generic applications probably have no such limitations.

Quoted 8 lines
Quoted 5 lines

That's true, but there are two situations here to consider:

1) existing drivers/applications:
- No dynamic support, so PAD numbers are stable. Index is provided via v1;

Agreed, in such cases it's fine as long as the pad indices will be essentially defined by the driver --- as they used to.

True. Well, the patches I made so far, meant for Kernel v4.4 don't change them. We need to ensure that newer patches will do changes on a backward compatible way.

Quoted 8 lines
Quoted 4 lines

2) new drivers/applications:
- We need a way to provide stable equivalents to PAD indexes via v2.

I propose to only add them once we have the use case. This could be through the property API. My hands are pretty full of other work at the moment but this does not seem urgent either, which is good.

Agreed.

Quoted 5 lines

I think that applications that are hardware specific would still often prefer hard-coding the pad number there, but instead use the new interface. Do you think we could guarantee the same pad number stability there, as long as no dynamic hardware changes affecting the pads are made? Such applications couldn't cope with those changes anyway.

I guess so. That will depend, of course, on how you'll be implementing the properties API ;)

I would map it as a series of PAD properties where the Kernelspace may opt to have the ones that makes sense, like:
- pad_index;
- pad_data_type;
- pad_name;
...

For simple devices (no dynamic support, all pads carry on the same type of data), it would just use pad index. More complex devices like hybrid TV ones would use, instead pad_data_type and pad_name.

Quoted 12 lines
Quoted 12 lines
Quoted 5 lines

The pad index is indeed just a number but it's an important one. If we provide the pad ID (i.e. the graph object ID) to the user space, it has none of the three properties, and missing even one would be enough to break the user space.

No userspace will be broken on v1 ioctls, as it will still be there.

Quoted 3 lines

Then, it indeed becomes a naming issue. Names can be stable even if the index wouldn't be. The user would convert the names to integers that may not be stable.

Quoted 6 lines
Quoted 3 lines

Yes, I guess a name is the best alternative here, as it fits both the cases where a simple number index is enough and cases where userspace need to use some other criteria to detect the PAD he needs.

I think the names would have to be entity specific. Otherwise we'll have the same entity naming problem there.

Agreed.

Quoted 25 lines
Quoted 17 lines
Quoted 9 lines

Do you have a use case for dynamically adding or removing pads --- wouldn't it take a change in hardware topology to do that? If it's software only, I'd definitely favour solutions that didn't involve changes in topology --- software changes are generally very fast, and changing the media device topology for that could also affect the device nodes, forcing the user space to wait for udev to create them. That's very inconvenient when you want to take a photo, for instance.

I'm pretty sure we'll need dynamic pad addition/removal in some future, but they're not of the first use cases I want to address.

There are some hardware that allows to dynamically reconfigure it to provide more PADs. I've seen two different cases of that, at the DVB side:

Quoted 7 lines

1) One hardware with a fixed number of pads (like 4 sink pads and 40 source pads), where it is capable of being dynamically configured to become 4 independent hardware entities, each one with one sink pad and a number of source pads. So, it could start like 4 entities, with one sink and 10 sources. However, if user needs more than 10 sources, it can send a command to the hardware to get some unused PADs from the other entities;

Quoted 8 lines

This is not completely unlike many CSI-2 receivers which can share the lanes found in the receiver block between different receivers, say dividing five receiver lanes in 4:1:0 or 2:2:1 configuration among three receivers depending on the connected sensors. Those are not shown to the user space at all.

Althrough that's configuration made in board design time whereas yours is runtime if I understand you correctly.

Yes, this is a runtime decision on the case I mentioned.

Quoted 2 lines

What are these 40 pads in your example? Is it a DVB demux or something else?

Yes, DVB demux.

As I explained on IRC, the DVB demux works by setting one filter per PAD. This filter has either the first 16 bytes of a DVB package or a set of PIDs.

For each packet a DVB demux receives, it checks the header against one of the filters there and outputs it to one (or more) output ports.

On a real case example for DVB-C (cable), one single physical channel has 17 logical channels inside, each with at least one audio and one video channel, and sometimes other PIDs for interactive contents. There are some PIDs there with the programming guide, CATV internet, interactive content and data channels for firmware upgrades.

Some of those channels:

[TNT]

	SERVICE_ID = 48
	VIDEO_PID = 336
	AUDIO_PID = 337 338 849
	PID_86 = 816
	FREQUENCY = 573000000

[Boomerang]

	SERVICE_ID = 57
	VIDEO_PID = 352
	AUDIO_PID = 353 354
	FREQUENCY = 573000000

[Cartoon]

	SERVICE_ID = 104
	VIDEO_PID = 320
	AUDIO_PID = 321 322
	PID_86 = 1840
	PID_05 = 3295
	FREQUENCY = 573000000

[Games]

	SERVICE_ID = 252
	PID_05 = 3047 3046 3045 3044 3042
	FREQUENCY = 573000000

[Soundtracks]

	SERVICE_ID = 342
	AUDIO_PID = 104
	PID_05 = 204
	FREQUENCY = 573000000

It is possible to record one (or more) logical channel(s) while some logical channel is being displayed, using just one frontend, as all those 17 channels are at the same frequency.

So, a typical usage would be an user that wants to listen to the TNT channel, record everything from Boomerang and only record audio and video from Cartoon. On such use case, the applications started by the user would be setting:

Demux output#0: filter PID 336 and route to GPU (DRM domain); Demux output#1: filter PID 337 (or all 3 audio pids) routing to the audio

		IP blocks (ALSA domain);

Demux output#2: filter PID 48 and route to ringbuffer#0 Demux output#3: filter PID 816 and route to ringbuffer #1 Demux output#4: filter PIDs 57, 352 to 354 and route to ringbuffer #2
ringbuffer#2 will be routed to disk by userspace app.
Demux output#5: filter PIDs 320 to 322 and route to ringbuffer #3
ringbuffer#3 will be routed to disk by userspace app.

Depending on the program, some of those outputs may need to be dynamically routed in runtime to a CA module, in order to decrypt the data. The applications should be able to do that, if needed.

There will be also some other filters set to get the programming guide, CATV, firmware upgrades, emergency broadcast messages (to announce events like earthquakes, tsunamis, and other calamity events at the area), etc. Those filters are configured by some other applications that are designed specifically to handle those stuff.

FYI, 40 there is just a random number. The actual number is usually a power of 2.

A cheap hardware has 16 or 32 such hardware filters on their demux. Hardware used on STB or TV sets typically have 64 or more filters. The software implementation usually has 256 filters (the number is actually defined by the driver, but most just use 256).

The way the DVB core works is that if all hardware filters at the demux are exhausted, it will implement software filtering/demux for the remaining filters.

Quoted 2 lines

I'm not that much worried about the number alone, but if the pads are indistinguishable from each other,

All pads work at the same way, but they're not indistinguishible. They map different ringbuffers used to do I/O via the read() interface (or, in the future, also via mmap and DMABUF), as explained above.

For this specific usecase, a pad index could make sense. Another way to expose it to userspace would be to expose the PID filter associated with the DEMUX port to userspace.

Quoted 2 lines

I'd look for other ways to expose (or
avoid exposing) them to the user.

Why avoid exposing? That would break the use case. As explained earlier, the user applications need to be able to dynamically route each output of the Demux to the right place, e. g. either to a hardware entity (a GPU, ALSA or CA entity) or to an output ringbuffer.

Am I understanding wrong or are you seriously proposing to fork the Media Controller? Why? This is no different from what the MC already does. We don't need a duplicated subsystem to do the same thing.

Quoted 11 lines
Quoted 6 lines

2) Firmware or FPGA-based devices, where you can dynamically reconfigure the hardware any time. We have one such driver merged for 4.3 whose vendor is promising to release the FPGA code as an Open Source, in order to allow users to change the hardware in real time.

If you replace the FPGA configuration with another, it's essentially a new piece of hardware which will require its own driver. Of course you could do that with some limitations, but you have to take it into account in the driver in that case.

Sure. It doesn't make much sense to change the FPGA configuration to turn a DVB device into a software radio while streaming. Yet, it could make sense to add more demux filters or CA entities in runtime, without stopping streaming.

Quoted 25 lines
Quoted 25 lines

The first case could actually be handled by always creating 4 entities, each with 40 source pads, and adding a new flag to tell that a pad was not actually created yet, but this sounds hacky and would allocate 4 times more memory for the PADs than actually needed. Btw, the memory allocation is already a problem on one of the hardwares I know that uses this device, as the DVB core doesn't support dynamic filter reconfiguration neither. The amount of memory required there to handle each source PAD on a demux is not small, as one ringbuffer to handle the I/O transfer is needed for each PAD source. We're working to fix it at the DVB side, but having the DVB to use a different number of PADs than what's there at the MC would be really messy.

For the second case, I don't know any alternative but to support dynamic PAD changes.

Please notice that, on DVB, I don't see any usage for subdevs, so there's no need to wait for udev to create new devices to address those new entities/pads.

The second case, e. g. a Firmware/FPGA-based device can also work at the V4L2 side. I remember someone (from Intel - I guess) commenting about one such hardware on one of our media workshops, but it was for some hardware he was not allowed to upstream.

Quoted 6 lines
Quoted 3 lines

Yeah, assuming that someone would upstream such driver and we would need to find a solution, yeah, reconfiguration while taking a photo can be very inconvenient.

Yes. As the "hardware topology" of such a device is essentially defined by software, I wouldn't try to represent it as hardware.

Well, we don't represent hardware at MC. We represent entities. Most DVB hardware nowadays actually have software embedded there somehow. Some allow changes in runtime, most don't. We don't and should not deny an entity to represent something that it is internally implemented by a FPGA or firmware. We also should not implement the pipelines using a different framework if the entities are implemented inside a FPGA or not.

Quoted 7 lines

There's a subtle but
significant difference to FPGA devices: FPGAs are essentially hardware, albeit you can change the layout to whatever you like, whereas the devices running software require software frameworks to support the device on both sides (the CPU and the device firmware). They more resemble programmable GPUs in that sense: even if what the device does (computes) changes, the drivers do not (and should not).

Sorry, didn't got what you're meaning here. Drivers/userspace should not change, but it should be aware of the changes, in order to do the right thing.

Quoted 13 lines
Quoted 4 lines

Perhaps the solution for such case would be to create the new pads/entities when the camera software would be loaded, and not when the user takes a photo.

Quoted 8 lines

I don't expect us to solve all issues related to dynamic PAD addition this year, but we should be sure that no API changes will be needed at G_TOPOLOGY when we add support for it, and I guess that the right thing here is to provide properties that would allow userspace to retrieve what's needed to uniquely identify a PAD on a stable manner. Eventually, some devices could just use an u32 pad_index properties, while others may use strings.

Quoted 2 lines

New properties (such as the name) could be added later on without affecting the existing users that depend on the index.

True, and this is also true for pad index.

We need to solve this before adding the SETUP_LINK_V2, and before start converting apps that sets links to use G_TOPOLOGY as such apps will need to be able to uniquely identify a PAD.

Regards,
Mauro

#108 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

In reply to Mauro Carvalho Chehab
Quoted 4 lines · Mauro Carvalho Chehab

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

Two comments:

Quoted 120 lines
drivers/media/media-device.c +111 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		if (i > topo->num_links) {
+			ret = -ENOSPC;
+			continue;
+		}
+

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 355

Quoted 10 lines
drivers/media/media-device.c +10 -0
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;

Why isn't this flag part of link->flags? I would expect that when an interface link is created the media core code will set this flag automatically.

It's a bit strange that this flag is set here. Or am I missing something?

Quoted 47 lines
drivers/media/media-device.c +36 -0
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 		mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}

drivers/media/media-device.c static long media_device_compat_ioctl(struct file *filp, unsigned int cmd, · line 473

Quoted 5 lines
drivers/media/media-device.c +1 -0
@@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
 	case MEDIA_IOC_DEVICE_INFO:
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);

This doesn't work: G_TOPOLOGY needs pointer conversion.

Regards,

Hans

Quoted 3 lines
drivers/media/media-device.c +0 -0
 	case MEDIA_IOC_ENUM_LINKS32:
 
#109 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

Em Fri, 11 Sep 2015 16:08:54 +0200
Hans Verkuil <[email protected]> escreveu:

Quoted 142 lines · Mauro Carvalho Chehab
Quoted 4 lines

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

Two comments:

Quoted 120 lines
drivers/media/media-device.c +111 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct media_device *mdev,
 	return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		if (i > topo->num_links) {
+			ret = -ENOSPC;
+			continue;
+		}
+

drivers/media/media-device.c static long media_device_setup_link(struct media_device *mdev, · line 355

Quoted 10 lines
drivers/media/media-device.c +10 -0
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;

Why isn't this flag part of link->flags? I would expect that when an interface link is created the media core code will set this flag automatically.

Quoted 1 line

It's a bit strange that this flag is set here. Or am I missing something?

Well, this is a flag for the userspace API. The Kernel doesn't need it.

I don't object to move it to be set when link gets created on some followup patch, if needed.

Quoted 47 lines
Quoted 47 lines
drivers/media/media-device.c +36 -0
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 		mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}
Quoted 8 lines

drivers/media/media-device.c static long media_device_compat_ioctl(struct file *filp, unsigned int cmd, · line 473

Quoted 6 lines
drivers/media/media-device.c +1 -0
@@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
 	case MEDIA_IOC_DEVICE_INFO:
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);

This doesn't work: G_TOPOLOGY needs pointer conversion.

True. I'll address this on a separate patch.

Quoted 13 lines

Regards,

Hans

drivers/media/media-device.c static long media_device_compat_ioctl(struct file *filp, unsigned int cmd, · line 475

Quoted 3 lines
drivers/media/media-device.c +0 -0
 	case MEDIA_IOC_ENUM_LINKS32:
 

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#110 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

In reply to Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

Sakari and Hans have made several comments on this and the previous version of the same patch and I generally agree with them. I'll thus review the next version.

Quoted 188 lines · On Sunday 06 September 2015 09:03:09 Mauro Carvalho Chehab wrote:

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +157 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct
 media_device *mdev, return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		if (i > topo->num_links) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp,
 unsigned int cmd, mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}
@@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp,

unsigned int cmd, case MEDIA_IOC_DEVICE_INFO:

drivers/media/media-device.c +1 -0
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);
 
 	case MEDIA_IOC_ENUM_LINKS32:
Signature · 3 lines
Regards,

Laurent Pinchart
#111 lore raw

Re: [PATCH v8 49/55] [media] media-device: add support for MEDIA_IOC_G_TOPOLOGY ioctl

Em Tue, 24 Nov 2015 00:04:02 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 7 lines

Hi Mauro,

Thank you for the patch.

Sakari and Hans have made several comments on this and the previous version of the same patch and I generally agree with them. I'll thus review the next version.

What next version? If I got it right, the issues that Sailus commented are related to future implementations, needed if/when we need to have dynamic PADs.

We're not adding support for dynamic PADs for now.

So, I don't have anything planned to change on this patch.

Regards,
Mauro

Quoted 191 lines · On Sunday 06 September 2015 09:03:09 Mauro Carvalho Chehab wrote:
Quoted 188 lines

Add support for the new MEDIA_IOC_G_TOPOLOGY ioctl, according with the RFC for the MC next generation.

drivers/media/media-device.c +157 -0
index 5b2c9f7fcd45..96a476eeb16e 100644
@@ -232,6 +232,156 @@ static long media_device_setup_link(struct
 media_device *mdev, return ret;
 }
 
+static long __media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology *topo)
+{
+	struct media_entity *entity;
+	struct media_interface *intf;
+	struct media_pad *pad;
+	struct media_link *link;
+	struct media_v2_entity uentity;
+	struct media_v2_interface uintf;
+	struct media_v2_pad upad;
+	struct media_v2_link ulink;
+	int ret = 0, i;
+
+	topo->topology_version = mdev->topology_version;
+
+	/* Get entities and number of entities */
+	i = 0;
+	media_device_for_each_entity(entity, mdev) {
+		i++;
+
+		if (ret || !topo->entities)
+			continue;
+
+		if (i > topo->num_entities) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		/* Copy fields to userspace struct if not error */
+		memset(&uentity, 0, sizeof(uentity));
+		uentity.id = entity->graph_obj.id;
+		strncpy(uentity.name, entity->name,
+			sizeof(uentity.name));
+
+		if (copy_to_user(&topo->entities[i - 1], &uentity, sizeof(uentity)))
+			ret = -EFAULT;
+	}
+	topo->num_entities = i;
+
+	/* Get interfaces and number of interfaces */
+	i = 0;
+	media_device_for_each_intf(intf, mdev) {
+		i++;
+
+		if (ret || !topo->interfaces)
+			continue;
+
+		if (i > topo->num_interfaces) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&uintf, 0, sizeof(uintf));
+
+		/* Copy intf fields to userspace struct */
+		uintf.id = intf->graph_obj.id;
+		uintf.intf_type = intf->type;
+		uintf.flags = intf->flags;
+
+		if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
+			struct media_intf_devnode *devnode;
+
+			devnode = intf_to_devnode(intf);
+
+			uintf.devnode.major = devnode->major;
+			uintf.devnode.minor = devnode->minor;
+		}
+
+		if (copy_to_user(&topo->interfaces[i - 1], &uintf, sizeof(uintf)))
+			ret = -EFAULT;
+	}
+	topo->num_interfaces = i;
+
+	/* Get pads and number of pads */
+	i = 0;
+	media_device_for_each_pad(pad, mdev) {
+		i++;
+
+		if (ret || !topo->pads)
+			continue;
+
+		if (i > topo->num_pads) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&upad, 0, sizeof(upad));
+
+		/* Copy pad fields to userspace struct */
+		upad.id = pad->graph_obj.id;
+		upad.entity_id = pad->entity->graph_obj.id;
+		upad.flags = pad->flags;
+
+		if (copy_to_user(&topo->pads[i - 1], &upad, sizeof(upad)))
+			ret = -EFAULT;
+	}
+	topo->num_pads = i;
+
+	/* Get links and number of links */
+	i = 0;
+	media_device_for_each_link(link, mdev) {
+		i++;
+
+		if (ret || !topo->links)
+			continue;
+
+		if (i > topo->num_links) {
+			ret = -ENOSPC;
+			continue;
+		}
+
+		memset(&ulink, 0, sizeof(ulink));
+
+		/* Copy link fields to userspace struct */
+		ulink.id = link->graph_obj.id;
+		ulink.source_id = link->gobj0->id;
+		ulink.sink_id = link->gobj1->id;
+		ulink.flags = link->flags;
+
+		if (media_type(link->gobj0) != MEDIA_GRAPH_PAD)
+			ulink.flags |= MEDIA_LNK_FL_INTERFACE_LINK;
+
+		if (copy_to_user(&topo->links[i - 1], &ulink, sizeof(ulink)))
+			ret = -EFAULT;
+	}
+	topo->num_links = i;
+
+	return ret;
+}
+
+static long media_device_get_topology(struct media_device *mdev,
+				      struct media_v2_topology __user *utopo)
+{
+	struct media_v2_topology ktopo;
+	int ret;
+
+	ret = copy_from_user(&ktopo, utopo, sizeof(ktopo));
+
+	if (ret < 0)
+		return ret;
+
+	ret = __media_device_get_topology(mdev, &ktopo);
+	if (ret < 0)
+		return ret;
+
+	ret = copy_to_user(utopo, &ktopo, sizeof(*utopo));
+
+	return ret;
+}
+
 static long media_device_ioctl(struct file *filp, unsigned int cmd,
 			       unsigned long arg)
 {
@@ -264,6 +414,13 @@ static long media_device_ioctl(struct file *filp,
 unsigned int cmd, mutex_unlock(&dev->graph_mutex);
 		break;
 
+	case MEDIA_IOC_G_TOPOLOGY:
+		mutex_lock(&dev->graph_mutex);
+		ret = media_device_get_topology(dev,
+				(struct media_v2_topology __user *)arg);
+		mutex_unlock(&dev->graph_mutex);
+		break;
+
 	default:
 		ret = -ENOIOCTLCMD;
 	}
@@ -312,6 +469,7 @@ static long media_device_compat_ioctl(struct file *filp,

unsigned int cmd, case MEDIA_IOC_DEVICE_INFO:

drivers/media/media-device.c +1 -0
 	case MEDIA_IOC_ENUM_ENTITIES:
 	case MEDIA_IOC_SETUP_LINK:
+	case MEDIA_IOC_G_TOPOLOGY:
 		return media_device_ioctl(filp, cmd, arg);
 
 	case MEDIA_IOC_ENUM_LINKS32:
author Acked-by Hans Verkuil
#112 lore raw

Re: [PATCH v8 50/55] [media] media-entity: unregister entity links

In reply to Mauro Carvalho Chehab

Add functions to explicitly unregister all entity links. This function is called automatically when an entity link is destroyed.

drivers/media/media-entity.c +23 -0
index 064515f2ba9b..a37ccd2edfd5 100644
@@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
+	media_remove_intf_links(&devnode->intf);
 	media_gobj_remove(&devnode->intf.graph_obj);
 	kfree(devnode);
 }
@@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
 	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_remove_intf_link);
+
+void __media_remove_intf_links(struct media_interface *intf)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &intf->links, list)
+		__media_remove_intf_link(link);
+
+}
+EXPORT_SYMBOL_GPL(__media_remove_intf_links);
+
+void media_remove_intf_links(struct media_interface *intf)
+{
+	/* Do nothing if the intf is not registered. */
+	if (intf->graph_obj.mdev == NULL)
+		return;
+
+	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_links(intf);
+	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_links);
include/media/media-entity.h +3 -0
index bc7eb6240795..ca4a4f23362f 100644
@@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct media_entity *entity,
 					    struct media_interface *intf,
 					    u32 flags);
 void media_remove_intf_link(struct media_link *link);
+void __media_remove_intf_links(struct media_interface *intf);
+void media_remove_intf_links(struct media_interface *intf);
+
 
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
Signature · 1 line
2.4.3
maintainer
#113 lore raw

Re: [PATCH v8 50/55] [media] media-entity: unregister entity links

Hi Mauro,

Thank you for the patch.

Quoted 23 lines · On Sunday 06 September 2015 09:03:10 Mauro Carvalho Chehab wrote:

Add functions to explicitly unregister all entity links. This function is called automatically when an entity link is destroyed.

drivers/media/media-entity.c +1 -0
index 064515f2ba9b..a37ccd2edfd5 100644
@@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
+	media_remove_intf_links(&devnode->intf);
 	media_gobj_remove(&devnode->intf.graph_obj);
 	kfree(devnode);
 }
@@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
 	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_remove_intf_link);

drivers/media/media-entity.c void media_remove_intf_link(struct media_link *link) · line 957

Quoted 10 lines
drivers/media/media-entity.c +10 -0
+
+void __media_remove_intf_links(struct media_interface *intf)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &intf->links, list)
+		__media_remove_intf_link(link);
+
+}
+EXPORT_SYMBOL_GPL(__media_remove_intf_links);

The only place where this function is used is in media_remove_intf_links() below. How about inlining it for now ?

drivers/media/media-entity.c void media_remove_intf_link(struct media_link *link) · line 969

Quoted 11 lines
drivers/media/media-entity.c +11 -0
+void media_remove_intf_links(struct media_interface *intf)
+{
+	/* Do nothing if the intf is not registered. */
+	if (intf->graph_obj.mdev == NULL)
+		return;
+
+	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_links(intf);
+	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_links);

As this function is exported it should be documented with kerneldoc.

Quoted 14 lines
include/media/media-entity.h +3 -0
index bc7eb6240795..ca4a4f23362f 100644
@@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct
 media_entity *entity, struct media_interface *intf,
 					    u32 flags);
 void media_remove_intf_link(struct media_link *link);
+void __media_remove_intf_links(struct media_interface *intf);
+void media_remove_intf_links(struct media_interface *intf);
+
 
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
Signature · 3 lines
Regards,

Laurent Pinchart
#114 lore raw

Re: [PATCH v8 50/55] [media] media-entity: unregister entity links

Em Mon, 23 Nov 2015 23:27:40 +0200
Laurent Pinchart <[email protected]> escreveu:

Quoted 42 lines

Hi Mauro,

Thank you for the patch.

Quoted 23 lines · On Sunday 06 September 2015 09:03:10 Mauro Carvalho Chehab wrote:

Add functions to explicitly unregister all entity links. This function is called automatically when an entity link is destroyed.

drivers/media/media-entity.c +1 -0
index 064515f2ba9b..a37ccd2edfd5 100644
@@ -903,6 +903,7 @@ EXPORT_SYMBOL_GPL(media_devnode_create);
 
 void media_devnode_remove(struct media_intf_devnode *devnode)
 {
+	media_remove_intf_links(&devnode->intf);
 	media_gobj_remove(&devnode->intf.graph_obj);
 	kfree(devnode);
 }
@@ -944,3 +945,25 @@ void media_remove_intf_link(struct media_link *link)
 	mutex_unlock(&link->graph_obj.mdev->graph_mutex);
 }
 EXPORT_SYMBOL_GPL(media_remove_intf_link);

drivers/media/media-entity.c void media_remove_intf_link(struct media_link *link) · line 957

Quoted 10 lines
drivers/media/media-entity.c +10 -0
+
+void __media_remove_intf_links(struct media_interface *intf)
+{
+	struct media_link *link, *tmp;
+
+	list_for_each_entry_safe(link, tmp, &intf->links, list)
+		__media_remove_intf_link(link);
+
+}
+EXPORT_SYMBOL_GPL(__media_remove_intf_links);

The only place where this function is used is in media_remove_intf_links() below. How about inlining it for now ?

Quoted 13 lines

drivers/media/media-entity.c void media_remove_intf_link(struct media_link *link) · line 969

Quoted 11 lines
drivers/media/media-entity.c +11 -0
+void media_remove_intf_links(struct media_interface *intf)
+{
+	/* Do nothing if the intf is not registered. */
+	if (intf->graph_obj.mdev == NULL)
+		return;
+
+	mutex_lock(&intf->graph_obj.mdev->graph_mutex);
+	__media_remove_intf_links(intf);
+	mutex_unlock(&intf->graph_obj.mdev->graph_mutex);
+}
+EXPORT_SYMBOL_GPL(media_remove_intf_links);

As this function is exported it should be documented with kerneldoc.

Will do both on a followup patch.

Quoted 16 lines
Quoted 15 lines
include/media/media-entity.h +3 -0
index bc7eb6240795..ca4a4f23362f 100644
@@ -318,6 +318,9 @@ struct media_link *media_create_intf_link(struct
 media_entity *entity, struct media_interface *intf,
 					    u32 flags);
 void media_remove_intf_link(struct media_link *link);
+void __media_remove_intf_links(struct media_interface *intf);
+void media_remove_intf_links(struct media_interface *intf);
+
 
 #define media_entity_call(entity, operation, args...)			\
 	(((entity)->ops && (entity)->ops->operation) ?			\
#115 lore raw

Re: [PATCH v8 55/55] [media] media-entity.h: document all the structs

In reply to Mauro Carvalho Chehab

Only a few structs are documented on kernel-doc-nano format (the ones added by the MC next gen patches).

Add a documentation for all structs, and ensure that they'll be producing the documentation at the Kernel's device driver DocBook.

include/media/media-entity.h +82 -28
index fb5f0e21f137..e1a89899deef 100644
@@ -55,11 +55,13 @@ enum media_gobj_type {
 /**
  * struct media_gobj - Define a graph object.
  *
+ * @mdev:	Pointer to the struct media_device that owns the 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").
+ * @list:	Linked list associated to one of the per-type mdev object lists
  *
  * All objects on the media graph should have this struct embedded
  */
@@ -73,6 +75,28 @@ struct media_gobj {
 struct media_pipeline {
 };
 
+/**
+ * struct media_link - Define a media link graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @list:	Linked list associated with an entity or an interface that
+ *		owns the link.
+ * @gobj0:	Part of an union. Used to get the pointer for the first
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the first object (gobj0) is
+ *		a pad. On such case, it represents the source pad.
+ * @intf:	Part of an union. Used only if the first object (gobj0) is
+ *		an interface.
+ * @gobj1:	Part of an union. Used to get the pointer for the second
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the second object (gobj0) is
+ *		a pad. On such case, it represents the sink pad.
+ * @entity:	Part of an union. Used only if the second object (gobj0) is
+ *		an entity.
+ * @reverse:	Pointer to the link for the reverse direction of a pad to pad
+ *		link.
+ * @flags:	Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)
+ */
 struct media_link {
 	struct media_gobj graph_obj;
 	struct list_head list;
@@ -86,15 +110,23 @@ struct media_link {
 		struct media_pad *sink;
 		struct media_entity *entity;
 	};
-	struct media_link *reverse;	/* Link in the reverse direction */
-	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
+	struct media_link *reverse;
+	unsigned long flags;
 };
 
+/**
+ * struct media_pad - Define a media pad graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @entity:	Entity where this object belongs
+ * @index:	Pad index in the entity pads array, numbered from 0 to n
+ * @flags:	Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
+ */
 struct media_pad {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	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_*) */
+	struct media_entity *entity;
+	u16 index;
+	unsigned long flags;
 };
 
 /**
@@ -113,51 +145,73 @@ struct media_entity_operations {
 	int (*link_validate)(struct media_link *link);
 };
 
+/**
+ * struct media_entity - Define a media entity graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data.
+ * @name:	Entity name.
+ * @type:	Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
+ * @revision:	Entity revision - OBSOLETE - should be removed soon.
+ * @flags:	Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
+ * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
+ * @num_pads:	Number of sink and source pads.
+ * @num_links:	Number of existing links, both enabled and disabled.
+ * @num_backlinks: Number of backlinks
+ * @pads:	Pads array with the size defined by @num_pads.
+ * @links:	Linked list for the data links.
+ * @ops:	Entity operations.
+ * @stream_count: Stream count for the entity.
+ * @use_count:	Use count for the entity.
+ * @pipe:	Pipeline this entity belongs to.
+ * @info:	Union with devnode information.  Kept just for backward
+ * 		compatibility.
+ * @major:	Devnode major number (zero if not applicable). Kept just
+ * 		for backward compatibility.
+ * @minor:	Devnode minor number (zero if not applicable). Kept just
+ * 		for backward compatibility.
+ *
+ * NOTE: @stream_count and @use_count reference counts must never be
+ * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
+ * can be used to detect reference count bugs that would make them negative.
+ */
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	const char *name;		/* Entity name */
-	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
-	u32 revision;			/* Entity revision, driver specific */
-	unsigned long flags;		/* Entity flags (MEDIA_ENT_FL_*) */
-	u32 group_id;			/* Entity group ID */
+	const char *name;
+	u32 type;
+	u32 revision;
+	unsigned long flags;
+	u32 group_id;
 
-	u16 num_pads;			/* Number of sink and source pads */
-	u16 num_links;			/* Number of existing links, both
-					 * enabled and disabled */
-	u16 num_backlinks;		/* Number of backlinks */
+	u16 num_pads;
+	u16 num_links;
+	u16 num_backlinks;
 
-	struct media_pad *pads;		/* Pads array (num_pads objects) */
-	struct list_head links;		/* Pad-to-pad links list */
+	struct media_pad *pads;
+	struct list_head links;
 
-	const struct media_entity_operations *ops;	/* Entity operations */
+	const struct media_entity_operations *ops;
 
 	/* Reference counts must never be negative, but are signed integers on
 	 * purpose: a simple WARN_ON(<0) check can be used to detect reference
 	 * count bugs that would make them negative.
 	 */
-	int stream_count;		/* Stream count for the entity. */
-	int use_count;			/* Use count for the entity. */
+	int stream_count;
+	int use_count;
 
-	struct media_pipeline *pipe;	/* Pipeline this entity belongs to. */
+	struct media_pipeline *pipe;
 
 	union {
-		/* Node specifications */
 		struct {
 			u32 major;
 			u32 minor;
 		} dev;
-
-		/* Sub-device specifications */
-		/* Nothing needed yet */
 	} info;
 };
 
 /**
- * struct media_interface - Define a Kernel API interface
+ * struct media_interface - Define a media interface graph object
  *
  * @graph_obj:		embedded graph object
- * @list:		Linked list used to find other interfaces that belong
- *			to the same media controller
  * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.
@@ -177,7 +231,7 @@ struct media_interface {
 };
 
 /**
- * struct media_intf_devnode - Define a Kernel API interface via a device node
+ * struct media_intf_devnode - Define a media interface via a device node
  *
  * @intf:	embedded interface object
  * @major:	Major number of a device node
Signature · 1 line
2.4.3
Acked-by
#116 lore raw

Re: [PATCH v8 55/55] [media] media-entity.h: document all the structs

Quoted 8 lines · Mauro Carvalho Chehab

Only a few structs are documented on kernel-doc-nano format (the ones added by the MC next gen patches).

Add a documentation for all structs, and ensure that they'll be producing the documentation at the Kernel's device driver DocBook.

After correcting some typos (see below):

Quoted 20 lines
include/media/media-entity.h +2 -0
index fb5f0e21f137..e1a89899deef 100644
@@ -55,11 +55,13 @@ enum media_gobj_type {
 /**
  * struct media_gobj - Define a graph object.
  *
+ * @mdev:	Pointer to the struct media_device that owns the 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").
+ * @list:	Linked list associated to one of the per-type mdev object lists
  *
  * All objects on the media graph should have this struct embedded
  */

include/media/media-entity.h struct media_gobj { · line 84

Quoted 10 lines
include/media/media-entity.h +7 -0
@@ -73,6 +75,28 @@ struct media_gobj {
 struct media_pipeline {
 };
 
+/**
+ * struct media_link - Define a media link graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @list:	Linked list associated with an entity or an interface that
+ *		owns the link.
+ * @gobj0:	Part of an union. Used to get the pointer for the first

s/an union/a union/ (in multiple places)

See: https://answers.yahoo.com/question/index?qid=20081006092816AAvPO9n

include/media/media-entity.h struct media_gobj { · line 87

Quoted 3 lines
include/media/media-entity.h +3 -0
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the first object (gobj0) is
+ *		a pad. On such case, it represents the source pad.

s/On such case/In that case/ (in multiple places)

include/media/media-entity.h struct media_gobj { · line 98

Quoted 11 lines
include/media/media-entity.h +11 -0
+ * @intf:	Part of an union. Used only if the first object (gobj0) is
+ *		an interface.
+ * @gobj1:	Part of an union. Used to get the pointer for the second
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the second object (gobj0) is
+ *		a pad. On such case, it represents the sink pad.
+ * @entity:	Part of an union. Used only if the second object (gobj0) is
+ *		an entity.
+ * @reverse:	Pointer to the link for the reverse direction of a pad to pad
+ *		link.
+ * @flags:	Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)

s/as defined at/as defined in/ (in multiple places)

Quoted 131 lines
include/media/media-entity.h +58 -27
+ */
 struct media_link {
 	struct media_gobj graph_obj;
 	struct list_head list;
@@ -86,15 +110,23 @@ struct media_link {
 		struct media_pad *sink;
 		struct media_entity *entity;
 	};
-	struct media_link *reverse;	/* Link in the reverse direction */
-	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
+	struct media_link *reverse;
+	unsigned long flags;
 };
 
+/**
+ * struct media_pad - Define a media pad graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @entity:	Entity where this object belongs
+ * @index:	Pad index in the entity pads array, numbered from 0 to n
+ * @flags:	Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
+ */
 struct media_pad {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	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_*) */
+	struct media_entity *entity;
+	u16 index;
+	unsigned long flags;
 };
 
 /**
@@ -113,51 +145,73 @@ struct media_entity_operations {
 	int (*link_validate)(struct media_link *link);
 };
 
+/**
+ * struct media_entity - Define a media entity graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data.
+ * @name:	Entity name.
+ * @type:	Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
+ * @revision:	Entity revision - OBSOLETE - should be removed soon.
+ * @flags:	Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
+ * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
+ * @num_pads:	Number of sink and source pads.
+ * @num_links:	Number of existing links, both enabled and disabled.
+ * @num_backlinks: Number of backlinks
+ * @pads:	Pads array with the size defined by @num_pads.
+ * @links:	Linked list for the data links.
+ * @ops:	Entity operations.
+ * @stream_count: Stream count for the entity.
+ * @use_count:	Use count for the entity.
+ * @pipe:	Pipeline this entity belongs to.
+ * @info:	Union with devnode information.  Kept just for backward
+ * 		compatibility.
+ * @major:	Devnode major number (zero if not applicable). Kept just
+ * 		for backward compatibility.
+ * @minor:	Devnode minor number (zero if not applicable). Kept just
+ * 		for backward compatibility.
+ *
+ * NOTE: @stream_count and @use_count reference counts must never be
+ * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
+ * can be used to detect reference count bugs that would make them negative.
+ */
 struct media_entity {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	const char *name;		/* Entity name */
-	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
-	u32 revision;			/* Entity revision, driver specific */
-	unsigned long flags;		/* Entity flags (MEDIA_ENT_FL_*) */
-	u32 group_id;			/* Entity group ID */
+	const char *name;
+	u32 type;
+	u32 revision;
+	unsigned long flags;
+	u32 group_id;
 
-	u16 num_pads;			/* Number of sink and source pads */
-	u16 num_links;			/* Number of existing links, both
-					 * enabled and disabled */
-	u16 num_backlinks;		/* Number of backlinks */
+	u16 num_pads;
+	u16 num_links;
+	u16 num_backlinks;
 
-	struct media_pad *pads;		/* Pads array (num_pads objects) */
-	struct list_head links;		/* Pad-to-pad links list */
+	struct media_pad *pads;
+	struct list_head links;
 
-	const struct media_entity_operations *ops;	/* Entity operations */
+	const struct media_entity_operations *ops;
 
 	/* Reference counts must never be negative, but are signed integers on
 	 * purpose: a simple WARN_ON(<0) check can be used to detect reference
 	 * count bugs that would make them negative.
 	 */
-	int stream_count;		/* Stream count for the entity. */
-	int use_count;			/* Use count for the entity. */
+	int stream_count;
+	int use_count;
 
-	struct media_pipeline *pipe;	/* Pipeline this entity belongs to. */
+	struct media_pipeline *pipe;
 
 	union {
-		/* Node specifications */
 		struct {
 			u32 major;
 			u32 minor;
 		} dev;
-
-		/* Sub-device specifications */
-		/* Nothing needed yet */
 	} info;
 };
 
 /**
- * struct media_interface - Define a Kernel API interface
+ * struct media_interface - Define a media interface graph object
  *
  * @graph_obj:		embedded graph object
- * @list:		Linked list used to find other interfaces that belong
- *			to the same media controller
  * @links:		List of links pointing to graph entities
  * @type:		Type of the interface as defined at the
  *			uapi/media/media.h header, e. g.

include/media/media-entity.h struct media_interface { · line 237

Quoted 8 lines
include/media/media-entity.h +1 -1
@@ -177,7 +231,7 @@ struct media_interface {
 };
 
 /**
- * struct media_intf_devnode - Define a Kernel API interface via a device node
+ * struct media_intf_devnode - Define a media interface via a device node
  *
  * @intf:	embedded interface object
  * @major:	Major number of a device node

Regards,

Hans

maintainer
#117 lore raw

Re: [PATCH v8 55/55] [media] media-entity.h: document all the structs

In reply to Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

Quoted 6 lines · On Sunday 06 September 2015 09:03:14 Mauro Carvalho Chehab wrote:

Only a few structs are documented on kernel-doc-nano format (the ones added by the MC next gen patches).

Add a documentation for all structs, and ensure that they'll be producing the documentation at the Kernel's device driver DocBook.

Very good idea ! Please see below for some spelling mistakes or other corrections in addition to the ones pointed out by Hans.

Quoted 7 lines
include/media/media-entity.h +0 -0
index fb5f0e21f137..e1a89899deef 100644

include/media/media-entity.h enum media_gobj_type { · line 64

Quoted 10 lines
include/media/media-entity.h +2 -0
@@ -55,11 +55,13 @@ enum media_gobj_type {
 /**
  * struct media_gobj - Define a graph object.
  *
+ * @mdev:	Pointer to the struct media_device that owns the 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").
+ * @list:	Linked list associated to one of the per-type mdev object lists

I'd say "List entry stored in one of the ..." (or "List head" if you prefer).

include/media/media-entity.h struct media_gobj { · line 79

Quoted 9 lines
include/media/media-entity.h +2 -0
  *
  * All objects on the media graph should have this struct embedded
  */
@@ -73,6 +75,28 @@ struct media_gobj {
 struct media_pipeline {
 };
 
+/**
+ * struct media_link - Define a media link graph object.

I think you can drop the "Define" and just say "A media link graph object". Or, rather, "A media graph link object" to mean "a link object part of a media graph".

Same comment for the other structures.

include/media/media-entity.h struct media_gobj { · line 92

Quoted 13 lines
include/media/media-entity.h +13 -0
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @list:	Linked list associated with an entity or an interface that
+ *		owns the link.
+ * @gobj0:	Part of an union. Used to get the pointer for the first
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the first object (gobj0) is
+ *		a pad. On such case, it represents the source pad.
+ * @intf:	Part of an union. Used only if the first object (gobj0) is
+ *		an interface.
+ * @gobj1:	Part of an union. Used to get the pointer for the second
+ *		graph_object of the link.
+ * @source:	Part of an union. Used only if the second object (gobj0) is

s/gobj0/gobj1/

include/media/media-entity.h struct media_gobj { · line 94

Quoted 2 lines
include/media/media-entity.h +2 -0
+ *		a pad. On such case, it represents the sink pad.
+ * @entity:	Part of an union. Used only if the second object (gobj0) is

Ditto.

include/media/media-entity.h struct media_gobj { · line 96

Quoted 2 lines
include/media/media-entity.h +2 -0
+ *		an entity.
+ * @reverse:	Pointer to the link for the reverse direction of a pad to 

pad

Quoted 11 lines
include/media/media-entity.h +3 -1
+ *		link.
+ * @flags:	Link flags, as defined at uapi/media.h (MEDIA_LNK_FL_*)
+ */
 struct media_link {
 	struct media_gobj graph_obj;
 	struct list_head list;
@@ -86,15 +110,23 @@ struct media_link {
 		struct media_pad *sink;
 		struct media_entity *entity;
 	};
-	struct media_link *reverse;	/* Link in the reverse direction */

include/media/media-entity.h struct media_link { · line 121

Quoted 10 lines
include/media/media-entity.h +7 -1
-	unsigned long flags;		/* Link flags (MEDIA_LNK_FL_*) */
+	struct media_link *reverse;
+	unsigned long flags;
 };
 
+/**
+ * struct media_pad - Define a media pad graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data
+ * @entity:	Entity where this object belongs

"Entity this pad belongs to"

Quoted 19 lines
include/media/media-entity.h +7 -3
+ * @index:	Pad index in the entity pads array, numbered from 0 to n
+ * @flags:	Pad flags, as defined at uapi/media.h (MEDIA_PAD_FL_*)
+ */
 struct media_pad {
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	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_*) */
+	struct media_entity *entity;
+	u16 index;
+	unsigned long flags;
 };
 
 /**
@@ -113,51 +145,73 @@ struct media_entity_operations {
 	int (*link_validate)(struct media_link *link);
 };
 
+/**

include/media/media-entity.h struct media_entity_operations { · line 158

Quoted 10 lines
include/media/media-entity.h +10 -0
+ * struct media_entity - Define a media entity graph object.
+ *
+ * @graph_obj:	Embedded structure containing the media object common data.
+ * @name:	Entity name.
+ * @type:	Entity type, as defined at uapi/media.h (MEDIA_ENT_T_*)
+ * @revision:	Entity revision - OBSOLETE - should be removed soon.
+ * @flags:	Entity flags, as defined at uapi/media.h (MEDIA_ENT_FL_*)
+ * @group_id:	Entity group ID - OBSOLETE - should be removed soon.
+ * @num_pads:	Number of sink and source pads.
+ * @num_links:	Number of existing links, both enabled and disabled.

I'd mention there that it includes the backlinks too as it's always clearly apparent.

"Total number of links, forward and back, enabled and disabled"

include/media/media-entity.h struct media_entity_operations { · line 161

Quoted 3 lines
include/media/media-entity.h +3 -0
+ * @num_backlinks: Number of backlinks
+ * @pads:	Pads array with the size defined by @num_pads.
+ * @links:	Linked list for the data links.

"List of data links" or "Linked list of data links" if you want to make it explicit that struct list_head is a linked list, but I think that should be known to the reader (and have the word link twice in the description for two different purpose can be slightly confusing).

include/media/media-entity.h struct media_entity_operations { · line 168

Quoted 7 lines
include/media/media-entity.h +7 -0
+ * @ops:	Entity operations.
+ * @stream_count: Stream count for the entity.
+ * @use_count:	Use count for the entity.
+ * @pipe:	Pipeline this entity belongs to.
+ * @info:	Union with devnode information.  Kept just for backward
+ * 		compatibility.
+ * @major:	Devnode major number (zero if not applicable). Kept just

Maybe s/@major/@dev.major/ (and the same for minor) ?

include/media/media-entity.h struct media_entity_operations { · line 171

Quoted 3 lines
include/media/media-entity.h +3 -0
+ * 		for backward compatibility.
+ * @minor:	Devnode minor number (zero if not applicable). Kept just
+ * 		for backward compatibility.

As this is an internal structure I think we should clean code up sooner than later and remove the major and minor fields. It will be confusing for driver authors otherwise. Same for the revision and group_id fields.

Quoted 55 lines
include/media/media-entity.h +3 -0
+ * NOTE: @stream_count and @use_count reference counts must never be
+ * negative, but are signed integers on purpose: a simple WARN_ON(<0) check
+ * can be used to detect reference count bugs that would make them

negative.
+ */
struct media_entity {

include/media/media-entity.h +14 -19
 	struct media_gobj graph_obj;	/* must be first field in struct */
-	const char *name;		/* Entity name */
-	u32 type;			/* Entity type (MEDIA_ENT_T_*) */
-	u32 revision;			/* Entity revision, driver specific */
-	unsigned long flags;		/* Entity flags (MEDIA_ENT_FL_*) */
-	u32 group_id;			/* Entity group ID */
+	const char *name;
+	u32 type;
+	u32 revision;
+	unsigned long flags;
+	u32 group_id;
 
-	u16 num_pads;			/* Number of sink and source pads */
-	u16 num_links;			/* Number of existing links, both
-					 * enabled and disabled */
-	u16 num_backlinks;		/* Number of backlinks */
+	u16 num_pads;
+	u16 num_links;
+	u16 num_backlinks;
 
-	struct media_pad *pads;		/* Pads array (num_pads objects) */
-	struct list_head links;		/* Pad-to-pad links list */
+	struct media_pad *pads;
+	struct list_head links;
 
-	const struct media_entity_operations *ops;	/* Entity operations */
+	const struct media_entity_operations *ops;
 
 	/* Reference counts must never be negative, but are signed integers on
 	 * purpose: a simple WARN_ON(<0) check can be used to detect reference
 	 * count bugs that would make them negative.
 	 */
-	int stream_count;		/* Stream count for the entity. */
-	int use_count;			/* Use count for the entity. */
+	int stream_count;
+	int use_count;
 
-	struct media_pipeline *pipe;	/* Pipeline this entity belongs to. */
+	struct media_pipeline *pipe;
 
 	union {
-		/* Node specifications */
 		struct {
 			u32 major;
 			u32 minor;
 		} dev;
-
-		/* Sub-device specifications */
-		/* Nothing needed yet */

include/media/media-entity.h struct media_entity_operations { · line 160

Quoted 10 lines
include/media/media-entity.h +1 -3
 	} info;
 };
 
 /**
- * struct media_interface - Define a Kernel API interface
+ * struct media_interface - Define a media interface graph object
  *
  * @graph_obj:		embedded graph object
- * @list:		Linked list used to find other interfaces that belong
- *			to the same media controller

Usual pet peeve of mine, this should be squashed with the patch that introduces struct media_interface. Same for the next chunk. I would actually move this patch before any patch that introduces a new structure, just to document the existing structures, and then add documentation for new structures in the patches that introduce them. That would be easier to review.

Quoted 12 lines

* @links: List of links pointing to graph entities
* @type: Type of the interface as defined at the
* uapi/media/media.h header, e. g.

include/media/media-entity.h +0 -1
@@ -177,7 +231,7 @@ struct media_interface {
 };
 
 /**
- * struct media_intf_devnode - Define a Kernel API interface via a device

node
+ * struct media_intf_devnode - Define a media interface via a device node
* @intf: embedded interface object
* @major: Major number of a device node

Signature · 3 lines
Regards,

Laurent Pinchart