media: mc: entity: Add media_entity_pipeline() to access the media pipeline
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Wed, 31 Aug 2022 14:13:31 +0000 (16:13 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Sat, 24 Sep 2022 07:12:35 +0000 (09:12 +0200)
Replace direct access to the pipe field in drivers with a new helper
function. This will allow easier refactoring of media pipeline handling
in the MC core behind the scenes without affecting drivers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
13 files changed:
drivers/media/mc/mc-entity.c
drivers/media/platform/renesas/rcar-vin/rcar-core.c
drivers/media/platform/renesas/rcar-vin/rcar-dma.c
drivers/media/platform/ti/omap3isp/isp.c
drivers/media/platform/ti/omap3isp/ispvideo.c
drivers/media/platform/ti/omap3isp/ispvideo.h
drivers/media/platform/xilinx/xilinx-dma.c
drivers/media/platform/xilinx/xilinx-dma.h
drivers/staging/media/imx/imx-media-utils.c
drivers/staging/media/omap4iss/iss.c
drivers/staging/media/omap4iss/iss_video.c
drivers/staging/media/omap4iss/iss_video.h
include/media/media-entity.h

index c5c66befed0f25e3c5938f65ef02fd7486dd0ef0..7fb97c6dc897a91c4cf800439630182b7b105428 100644 (file)
@@ -994,6 +994,12 @@ int media_entity_get_fwnode_pad(struct media_entity *entity,
 }
 EXPORT_SYMBOL_GPL(media_entity_get_fwnode_pad);
 
+struct media_pipeline *media_entity_pipeline(struct media_entity *entity)
+{
+       return entity->pipe;
+}
+EXPORT_SYMBOL_GPL(media_entity_pipeline);
+
 static void media_interface_init(struct media_device *mdev,
                                 struct media_interface *intf,
                                 u32 gobj_type,
index 968a74234e929cdcfea2132db0ef1391b092cf03..2f7daa853ed8b69c4e7cf70670182a66f859c5dd 100644 (file)
@@ -786,9 +786,8 @@ static int rvin_csi2_link_notify(struct media_link *link, u32 flags,
                return 0;
 
        /*
-        * Don't allow link changes if any entity in the graph is
-        * streaming, modifying the CHSEL register fields can disrupt
-        * running streams.
+        * Don't allow link changes if any stream in the graph is active as
+        * modifying the CHSEL register fields can disrupt running streams.
         */
        media_device_for_each_entity(entity, &group->mdev)
                if (media_entity_is_streaming(entity))
index 8d37fbdc266a0c6a023a15cd094a4aea950278ca..e72bc6fa049f40cb22b4042720128f35a78c90ce 100644 (file)
@@ -1281,7 +1281,7 @@ static int rvin_set_stream(struct rvin_dev *vin, int on)
         */
        mdev = vin->vdev.entity.graph_obj.mdev;
        mutex_lock(&mdev->graph_mutex);
-       pipe = sd->entity.pipe ? sd->entity.pipe : &vin->vdev.pipe;
+       pipe = media_entity_pipeline(&sd->entity) ? : &vin->vdev.pipe;
        ret = __media_pipeline_start(&vin->vdev.entity, pipe);
        mutex_unlock(&mdev->graph_mutex);
        if (ret)
index a6052df9bb19e33fa9d80e504c01fd440b617f59..24d2383400b0a0a86827c3bd553c77fd33be20cb 100644 (file)
@@ -937,10 +937,8 @@ static int isp_pipeline_is_last(struct media_entity *me)
        struct isp_pipeline *pipe;
        struct media_pad *pad;
 
-       if (!me->pipe)
-               return 0;
        pipe = to_isp_pipeline(me);
-       if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED)
+       if (!pipe || pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED)
                return 0;
        pad = media_pad_remote_pad_first(&pipe->output->pad);
        return pad->entity == me;
index cc9a97d5d5051dddce82981e2fe1fc1bc4d7776e..2e7f90603a5a8c1d02628c1ec77db7a6bd2227a0 100644 (file)
@@ -1093,8 +1093,7 @@ isp_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
        /* Start streaming on the pipeline. No link touching an entity in the
         * pipeline can be activated or deactivated once streaming is started.
         */
-       pipe = video->video.entity.pipe
-            ? to_isp_pipeline(&video->video.entity) : &video->pipe;
+       pipe = to_isp_pipeline(&video->video.entity) ? : &video->pipe;
 
        ret = media_entity_enum_init(&pipe->ent_enum, &video->isp->media_dev);
        if (ret)
index a0908670c0cf39b40251f996ca973baa31c767cf..1d23df576e6b35f01d8b49a96a0acf1772c2e2c2 100644 (file)
@@ -99,8 +99,15 @@ struct isp_pipeline {
        unsigned int external_width;
 };
 
-#define to_isp_pipeline(__e) \
-       container_of((__e)->pipe, struct isp_pipeline, pipe)
+static inline struct isp_pipeline *to_isp_pipeline(struct media_entity *entity)
+{
+       struct media_pipeline *pipe = media_entity_pipeline(entity);
+
+       if (!pipe)
+               return NULL;
+
+       return container_of(pipe, struct isp_pipeline, pipe);
+}
 
 static inline int isp_pipeline_ready(struct isp_pipeline *pipe)
 {
index 2d1ef7a25c338ec42a79d24ce76323f9d26a39e9..3a4d62be0f2776c6e83c0bb326772d35b6a09fc7 100644 (file)
@@ -402,8 +402,7 @@ static int xvip_dma_start_streaming(struct vb2_queue *vq, unsigned int count)
         * Use the pipeline object embedded in the first DMA object that starts
         * streaming.
         */
-       pipe = dma->video.entity.pipe
-            ? to_xvip_pipeline(&dma->video.entity) : &dma->pipe;
+       pipe = to_xvip_pipeline(&dma->video.entity) ? : &dma->pipe;
 
        ret = media_pipeline_start(&dma->video.entity, &pipe->pipe);
        if (ret < 0)
index 2378bdae57aea0384db823b2ed2ef6fc9ca62e7e..3ea10f6b0bb9b6bb7841f07dbf38d8a4f48ec2e8 100644 (file)
@@ -47,7 +47,12 @@ struct xvip_pipeline {
 
 static inline struct xvip_pipeline *to_xvip_pipeline(struct media_entity *e)
 {
-       return container_of(e->pipe, struct xvip_pipeline, pipe);
+       struct media_pipeline *pipe = media_entity_pipeline(e);
+
+       if (!pipe)
+               return NULL;
+
+       return container_of(pipe, struct xvip_pipeline, pipe);
 }
 
 /**
index 294c808b2ebe145f478be7fce100017c50a845e8..e9a3c6d2c66fbe85b546312641a993d2a97fea16 100644 (file)
@@ -871,7 +871,7 @@ int imx_media_pipeline_set_stream(struct imx_media_dev *imxmd,
                        __media_pipeline_stop(entity);
        } else {
                v4l2_subdev_call(sd, video, s_stream, 0);
-               if (entity->pipe)
+               if (media_entity_pipeline(entity))
                        __media_pipeline_stop(entity);
        }
 
index 28aacda0f5a7db12f58253b4c930a575d80f1807..fa2a36d829d3d48847a4925959c61e6726bfa5cd 100644 (file)
@@ -548,10 +548,8 @@ static int iss_pipeline_is_last(struct media_entity *me)
        struct iss_pipeline *pipe;
        struct media_pad *pad;
 
-       if (!me->pipe)
-               return 0;
        pipe = to_iss_pipeline(me);
-       if (pipe->stream_state == ISS_PIPELINE_STREAM_STOPPED)
+       if (!pipe || pipe->stream_state == ISS_PIPELINE_STREAM_STOPPED)
                return 0;
        pad = media_pad_remote_pad_first(&pipe->output->pad);
        return pad->entity == me;
index 842509dcfedff53915473378511b3196ae006c5f..7967a42a3ffac3952f1bfbf13183c0129594b2fb 100644 (file)
@@ -870,8 +870,7 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
         * Start streaming on the pipeline. No link touching an entity in the
         * pipeline can be activated or deactivated once streaming is started.
         */
-       pipe = entity->pipe
-            ? to_iss_pipeline(entity) : &video->pipe;
+       pipe = to_iss_pipeline(&video->video.entity) ? : &video->pipe;
        pipe->external = NULL;
        pipe->external_rate = 0;
        pipe->external_bpp = 0;
index 526281bf005139154ab282f9966cae5808ebbc05..ca2d5edb6261a13920717d102786aefa71d8d92f 100644 (file)
@@ -90,8 +90,15 @@ struct iss_pipeline {
        int external_bpp;
 };
 
-#define to_iss_pipeline(__e) \
-       container_of((__e)->pipe, struct iss_pipeline, pipe)
+static inline struct iss_pipeline *to_iss_pipeline(struct media_entity *entity)
+{
+       struct media_pipeline *pipe = media_entity_pipeline(entity);
+
+       if (!pipe)
+               return NULL;
+
+       return container_of(pipe, struct iss_pipeline, pipe);
+}
 
 static inline int iss_pipeline_ready(struct iss_pipeline *pipe)
 {
index 1030e45e8ee64972293c3547252dff7b2398a4c1..aaf276f765cf0ef51dd2cd8cfcb489d2c491a658 100644 (file)
@@ -948,6 +948,24 @@ static inline bool media_entity_is_streaming(const struct media_entity *entity)
        return entity->pipe;
 }
 
+/**
+ * media_entity_pipeline - Get the media pipeline an entity is part of
+ * @entity: The entity
+ *
+ * This function returns the media pipeline that an entity has been associated
+ * with when constructing the pipeline with media_pipeline_start(). The pointer
+ * remains valid until media_pipeline_stop() is called.
+ *
+ * In general, entities can be part of multiple pipelines, when carrying
+ * multiple streams (either on different pads, or on the same pad using
+ * multiplexed streams). This function is to be used only for entities that
+ * do not support multiple pipelines.
+ *
+ * Return: The media_pipeline the entity is part of, or NULL if the entity is
+ * not part of any pipeline.
+ */
+struct media_pipeline *media_entity_pipeline(struct media_entity *entity);
+
 /**
  * media_entity_get_fwnode_pad - Get pad number from fwnode
  *