Stop using alloc_ctx and just fill in the device pointer.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
        if (*num_planes) {
                if (*num_planes != fmt->memplanes)
                        return -EINVAL;
-               for (i = 0; i < *num_planes; i++) {
+               for (i = 0; i < *num_planes; i++)
                        if (sizes[i] < (wh * fmt->depth[i]) / 8)
                                return -EINVAL;
-                       allocators[i] = ctx->fimc_dev->alloc_ctx;
-               }
                return 0;
        }
 
                        sizes[i] = frame->payload[i];
                else
                        sizes[i] = max_t(u32, size, frame->payload[i]);
-
-               allocators[i] = ctx->fimc_dev->alloc_ctx;
        }
 
        return 0;
        q->buf_struct_size = sizeof(struct fimc_vid_buffer);
        q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        q->lock = &fimc->lock;
+       q->dev = &fimc->pdev->dev;
 
        ret = vb2_queue_init(q);
        if (ret)
 
                        goto err_sd;
        }
 
-       /* Initialize contiguous memory allocator */
        vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
-       fimc->alloc_ctx = vb2_dma_contig_init_ctx(dev);
-       if (IS_ERR(fimc->alloc_ctx)) {
-               ret = PTR_ERR(fimc->alloc_ctx);
-               goto err_gclk;
-       }
 
        dev_dbg(dev, "FIMC.%d registered successfully\n", fimc->id);
        return 0;
 
-err_gclk:
-       if (!pm_runtime_enabled(dev))
-               clk_disable(fimc->clock[CLK_GATE]);
 err_sd:
        fimc_unregister_capture_subdev(fimc);
 err_sclk:
        pm_runtime_set_suspended(&pdev->dev);
 
        fimc_unregister_capture_subdev(fimc);
-       vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
        vb2_dma_contig_clear_max_seg_size(&pdev->dev);
 
        clk_disable(fimc->clock[CLK_BUS]);
 
  */
 struct fimc_vid_cap {
        struct fimc_ctx                 *ctx;
-       struct vb2_alloc_ctx            *alloc_ctx;
        struct v4l2_subdev              subdev;
        struct exynos_video_entity      ve;
        struct media_pad                vd_pad;
  * @m2m:       memory-to-memory V4L2 device information
  * @vid_cap:   camera capture device information
  * @state:     flags used to synchronize m2m and capture mode operation
- * @alloc_ctx: videobuf2 memory allocator context
  * @pipeline:  fimc video capture pipeline data structure
  */
 struct fimc_dev {
        struct fimc_m2m_device          m2m;
        struct fimc_vid_cap             vid_cap;
        unsigned long                   state;
-       struct vb2_alloc_ctx            *alloc_ctx;
 };
 
 /**
 
        if (ret < 0)
                return ret;
 
-       /* Initialize memory allocator context for the ISP DMA. */
-       is->isp.alloc_ctx = is->alloc_ctx;
-
        for_each_compatible_node(i2c_bus, NULL, FIMC_IS_I2C_COMPATIBLE) {
                for_each_available_child_of_node(i2c_bus, child) {
                        ret = fimc_is_parse_sensor_config(is, index, child);
                goto err_pm;
 
        vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
-       is->alloc_ctx = vb2_dma_contig_init_ctx(dev);
-       if (IS_ERR(is->alloc_ctx)) {
-               ret = PTR_ERR(is->alloc_ctx);
-               goto err_pm;
-       }
        /*
         * Register FIMC-IS V4L2 subdevs to this driver. The video nodes
         * will be created within the subdev's registered() callback.
         */
        ret = fimc_is_register_subdevs(is);
        if (ret < 0)
-               goto err_vb;
+               goto err_pm;
 
        ret = fimc_is_debugfs_create(is);
        if (ret < 0)
        fimc_is_debugfs_remove(is);
 err_sd:
        fimc_is_unregister_subdevs(is);
-err_vb:
-       vb2_dma_contig_cleanup_ctx(is->alloc_ctx);
 err_pm:
        if (!pm_runtime_enabled(dev))
                fimc_is_runtime_suspend(dev);
                fimc_is_runtime_suspend(dev);
        free_irq(is->irq, is);
        fimc_is_unregister_subdevs(is);
-       vb2_dma_contig_cleanup_ctx(is->alloc_ctx);
        vb2_dma_contig_clear_max_seg_size(dev);
        fimc_is_put_clocks(is);
        fimc_is_debugfs_remove(is);
 
  * @pdev: pointer to FIMC-IS platform device
  * @pctrl: pointer to pinctrl structure for this device
  * @v4l2_dev: pointer to top the level v4l2_device
- * @alloc_ctx: videobuf2 memory allocator context
  * @lock: mutex serializing video device and the subdev operations
  * @slock: spinlock protecting this data structure and the hw registers
  * @clocks: FIMC-LITE gate clock
        struct fimc_is_sensor           sensor[FIMC_IS_SENSORS_NUM];
        struct fimc_is_setfile          setfile;
 
-       struct vb2_alloc_ctx            *alloc_ctx;
        struct v4l2_ctrl_handler        ctrl_handler;
 
        struct mutex                    lock;
 
        if (*num_planes) {
                if (*num_planes != fmt->memplanes)
                        return -EINVAL;
-               for (i = 0; i < *num_planes; i++) {
+               for (i = 0; i < *num_planes; i++)
                        if (sizes[i] < (wh * fmt->depth[i]) / 8)
                                return -EINVAL;
-                       allocators[i] = isp->alloc_ctx;
-               }
                return 0;
        }
 
        *num_planes = fmt->memplanes;
 
-       for (i = 0; i < fmt->memplanes; i++) {
+       for (i = 0; i < fmt->memplanes; i++)
                sizes[i] = (wh * fmt->depth[i]) / 8;
-               allocators[i] = isp->alloc_ctx;
-       }
 
        return 0;
 }
        q->drv_priv = isp;
        q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        q->lock = &isp->video_lock;
+       q->dev = &isp->pdev->dev;
 
        ret = vb2_queue_init(q);
        if (ret < 0)
 
 /**
  * struct fimc_isp - FIMC-IS ISP data structure
  * @pdev: pointer to FIMC-IS platform device
- * @alloc_ctx: videobuf2 memory allocator context
  * @subdev: ISP v4l2_subdev
  * @subdev_pads: the ISP subdev media pads
  * @test_pattern: test pattern controls
  */
 struct fimc_isp {
        struct platform_device          *pdev;
-       struct vb2_alloc_ctx            *alloc_ctx;
        struct v4l2_subdev              subdev;
        struct media_pad                subdev_pads[FIMC_ISP_SD_PADS_NUM];
        struct v4l2_mbus_framefmt       src_fmt;
 
        if (*num_planes) {
                if (*num_planes != fmt->memplanes)
                        return -EINVAL;
-               for (i = 0; i < *num_planes; i++) {
+               for (i = 0; i < *num_planes; i++)
                        if (sizes[i] < (wh * fmt->depth[i]) / 8)
                                return -EINVAL;
-                       allocators[i] = fimc->alloc_ctx;
-               }
                return 0;
        }
 
        *num_planes = fmt->memplanes;
 
-       for (i = 0; i < fmt->memplanes; i++) {
+       for (i = 0; i < fmt->memplanes; i++)
                sizes[i] = (wh * fmt->depth[i]) / 8;
-               allocators[i] = fimc->alloc_ctx;
-       }
 
        return 0;
 }
        q->drv_priv = fimc;
        q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        q->lock = &fimc->lock;
+       q->dev = &fimc->pdev->dev;
 
        ret = vb2_queue_init(q);
        if (ret < 0)
        }
 
        vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
-       fimc->alloc_ctx = vb2_dma_contig_init_ctx(dev);
-       if (IS_ERR(fimc->alloc_ctx)) {
-               ret = PTR_ERR(fimc->alloc_ctx);
-               goto err_clk_dis;
-       }
 
        fimc_lite_set_default_config(fimc);
 
                fimc->index);
        return 0;
 
-err_clk_dis:
-       if (!pm_runtime_enabled(dev))
-               clk_disable(fimc->clock);
 err_sd:
        fimc_lite_unregister_capture_subdev(fimc);
 err_clk_put:
        pm_runtime_disable(dev);
        pm_runtime_set_suspended(dev);
        fimc_lite_unregister_capture_subdev(fimc);
-       vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx);
        vb2_dma_contig_clear_max_seg_size(dev);
        fimc_lite_clk_put(fimc);
 
 
  * @ve: exynos video device entity structure
  * @v4l2_dev: pointer to top the level v4l2_device
  * @fh: v4l2 file handle
- * @alloc_ctx: videobuf2 memory allocator context
  * @subdev: FIMC-LITE subdev
  * @vd_pad: media (sink) pad for the capture video node
  * @subdev_pads: the subdev media pads
        struct exynos_video_entity ve;
        struct v4l2_device      *v4l2_dev;
        struct v4l2_fh          fh;
-       struct vb2_alloc_ctx    *alloc_ctx;
        struct v4l2_subdev      subdev;
        struct media_pad        vd_pad;
        struct media_pad        subdev_pads[FLITE_SD_PADS_NUM];
 
                return -EINVAL;
 
        *num_planes = f->fmt->memplanes;
-       for (i = 0; i < f->fmt->memplanes; i++) {
+       for (i = 0; i < f->fmt->memplanes; i++)
                sizes[i] = f->payload[i];
-               allocators[i] = ctx->fimc_dev->alloc_ctx;
-       }
        return 0;
 }
 
        src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
        src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
        src_vq->lock = &ctx->fimc_dev->lock;
+       src_vq->dev = &ctx->fimc_dev->pdev->dev;
 
        ret = vb2_queue_init(src_vq);
        if (ret)
        dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
        dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
        dst_vq->lock = &ctx->fimc_dev->lock;
+       dst_vq->dev = &ctx->fimc_dev->pdev->dev;
 
        return vb2_queue_init(dst_vq);
 }
 
        }
 
        vb2_dma_contig_set_max_seg_size(dev->mem_dev_l, DMA_BIT_MASK(32));
-       dev->alloc_ctx[0] = vb2_dma_contig_init_ctx(dev->mem_dev_l);
-       if (IS_ERR(dev->alloc_ctx[0])) {
-               ret = PTR_ERR(dev->alloc_ctx[0]);
-               goto err_res;
-       }
        vb2_dma_contig_set_max_seg_size(dev->mem_dev_r, DMA_BIT_MASK(32));
-       dev->alloc_ctx[1] = vb2_dma_contig_init_ctx(dev->mem_dev_r);
-       if (IS_ERR(dev->alloc_ctx[1])) {
-               ret = PTR_ERR(dev->alloc_ctx[1]);
-               goto err_mem_init_ctx_1;
-       }
 
        mutex_init(&dev->mfc_mutex);
 
        ret = s5p_mfc_alloc_firmware(dev);
        if (ret)
-               goto err_alloc_fw;
+               goto err_res;
 
        ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
        if (ret)
        v4l2_device_unregister(&dev->v4l2_dev);
 err_v4l2_dev_reg:
        s5p_mfc_release_firmware(dev);
-err_alloc_fw:
-       vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]);
-err_mem_init_ctx_1:
-       vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
 err_res:
        s5p_mfc_final_pm(dev);
 err_dma:
        video_device_release(dev->vfd_dec);
        v4l2_device_unregister(&dev->v4l2_dev);
        s5p_mfc_release_firmware(dev);
-       vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
-       vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]);
        s5p_mfc_unconfigure_dma_memory(dev);
        vb2_dma_contig_clear_max_seg_size(dev->mem_dev_l);
        vb2_dma_contig_clear_max_seg_size(dev->mem_dev_r);
 
  * @watchdog_cnt:      counter for the watchdog
  * @watchdog_workqueue:        workqueue for the watchdog
  * @watchdog_work:     worker for the watchdog
- * @alloc_ctx:         videobuf2 allocator contexts for two memory banks
  * @enter_suspend:     flag set when entering suspend
  * @ctx_buf:           common context memory (MFCv6)
  * @warn_start:                hardware error code from which warnings start
        struct timer_list watchdog_timer;
        struct workqueue_struct *watchdog_workqueue;
        struct work_struct watchdog_work;
-       void *alloc_ctx[2];
        unsigned long enter_suspend;
 
        struct s5p_mfc_priv_buf ctx_buf;
 
                psize[1] = ctx->chroma_size;
 
                if (IS_MFCV6_PLUS(dev))
-                       allocators[0] =
-                               ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
+                       allocators[0] = &ctx->dev->mem_dev_l;
                else
-                       allocators[0] =
-                               ctx->dev->alloc_ctx[MFC_BANK2_ALLOC_CTX];
-               allocators[1] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
+                       allocators[0] = &ctx->dev->mem_dev_r;
+               allocators[1] = &ctx->dev->mem_dev_l;
        } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE &&
                   ctx->state == MFCINST_INIT) {
                psize[0] = ctx->dec_src_buf_size;
-               allocators[0] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
+               allocators[0] = &ctx->dev->mem_dev_l;
        } else {
                mfc_err("This video node is dedicated to decoding. Decoding not initialized\n");
                return -EINVAL;
 
                if (*buf_count > MFC_MAX_BUFFERS)
                        *buf_count = MFC_MAX_BUFFERS;
                psize[0] = ctx->enc_dst_buf_size;
-               allocators[0] = ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
+               allocators[0] = &ctx->dev->mem_dev_l;
        } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
                if (ctx->src_fmt)
                        *plane_count = ctx->src_fmt->num_planes;
                psize[1] = ctx->chroma_size;
 
                if (IS_MFCV6_PLUS(dev)) {
-                       allocators[0] =
-                               ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
-                       allocators[1] =
-                               ctx->dev->alloc_ctx[MFC_BANK1_ALLOC_CTX];
+                       allocators[0] = &ctx->dev->mem_dev_l;
+                       allocators[1] = &ctx->dev->mem_dev_l;
                } else {
-                       allocators[0] =
-                               ctx->dev->alloc_ctx[MFC_BANK2_ALLOC_CTX];
-                       allocators[1] =
-                               ctx->dev->alloc_ctx[MFC_BANK2_ALLOC_CTX];
+                       allocators[0] = &ctx->dev->mem_dev_r;
+                       allocators[1] = &ctx->dev->mem_dev_r;
                }
        } else {
                mfc_err("invalid queue type: %d\n", vq->type);