Stop using alloc_ctx and just fill in the device pointer.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Mikhail Ulyanov <mikhail.ulyanov@cogentembedded.com>
Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Cc: Jonathan Corbet <corbet@lwn.net>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
        struct dma_chan         *dma_chan;
 
        struct v4l2_m2m_dev     *m2m_dev;
-       struct vb2_alloc_ctx    *alloc_ctx;
 };
 
 struct deinterlace_ctx {
        *nbuffers = count;
        sizes[0] = size;
 
-       alloc_ctxs[0] = ctx->dev->alloc_ctx;
-
        dprintk(ctx->dev, "get %d buffer(s) of size %d each.\n", count, size);
 
        return 0;
        src_vq->ops = &deinterlace_qops;
        src_vq->mem_ops = &vb2_dma_contig_memops;
        src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
+       src_vq->dev = ctx->dev->v4l2_dev.dev;
        q_data[V4L2_M2M_SRC].fmt = &formats[0];
        q_data[V4L2_M2M_SRC].width = 640;
        q_data[V4L2_M2M_SRC].height = 480;
        dst_vq->ops = &deinterlace_qops;
        dst_vq->mem_ops = &vb2_dma_contig_memops;
        dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
+       dst_vq->dev = ctx->dev->v4l2_dev.dev;
        q_data[V4L2_M2M_DST].fmt = &formats[0];
        q_data[V4L2_M2M_DST].width = 640;
        q_data[V4L2_M2M_DST].height = 480;
 
        platform_set_drvdata(pdev, pcdev);
 
-       pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
-       if (IS_ERR(pcdev->alloc_ctx)) {
-               v4l2_err(&pcdev->v4l2_dev, "Failed to alloc vb2 context\n");
-               ret = PTR_ERR(pcdev->alloc_ctx);
-               goto err_ctx;
-       }
-
        pcdev->m2m_dev = v4l2_m2m_init(&m2m_ops);
        if (IS_ERR(pcdev->m2m_dev)) {
                v4l2_err(&pcdev->v4l2_dev, "Failed to init mem2mem device\n");
 
 err_m2m:
        video_unregister_device(&pcdev->vfd);
-err_ctx:
-       vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
 unreg_dev:
        v4l2_device_unregister(&pcdev->v4l2_dev);
 rel_dma:
        v4l2_m2m_release(pcdev->m2m_dev);
        video_unregister_device(&pcdev->vfd);
        v4l2_device_unregister(&pcdev->v4l2_dev);
-       vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
        dma_release_channel(pcdev->dma_chan);
 
        return 0;
 
 
        if (*nbufs < minbufs)
                *nbufs = minbufs;
-       if (cam->buffer_mode == B_DMA_contig)
-               alloc_ctxs[0] = cam->vb_alloc_ctx;
-       else if (cam->buffer_mode == B_DMA_sg)
-               alloc_ctxs[0] = cam->vb_alloc_ctx_sg;
 
        if (*num_planes)
                return sizes[0] < size ? -EINVAL : 0;
        vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ;
        vq->buf_struct_size = sizeof(struct mcam_vb_buffer);
+       vq->dev = cam->dev;
        INIT_LIST_HEAD(&cam->buffers);
        switch (cam->buffer_mode) {
        case B_DMA_contig:
                vq->mem_ops = &vb2_dma_contig_memops;
                cam->dma_setup = mcam_ctlr_dma_contig;
                cam->frame_complete = mcam_dma_contig_done;
-               cam->vb_alloc_ctx = vb2_dma_contig_init_ctx(cam->dev);
-               if (IS_ERR(cam->vb_alloc_ctx))
-                       return PTR_ERR(cam->vb_alloc_ctx);
 #endif
                break;
        case B_DMA_sg:
                vq->mem_ops = &vb2_dma_sg_memops;
                cam->dma_setup = mcam_ctlr_dma_sg;
                cam->frame_complete = mcam_dma_sg_done;
-               cam->vb_alloc_ctx_sg = vb2_dma_sg_init_ctx(cam->dev);
-               if (IS_ERR(cam->vb_alloc_ctx_sg))
-                       return PTR_ERR(cam->vb_alloc_ctx_sg);
 #endif
                break;
        case B_vmalloc:
        return vb2_queue_init(vq);
 }
 
-static void mcam_cleanup_vb2(struct mcam_camera *cam)
-{
-#ifdef MCAM_MODE_DMA_CONTIG
-       if (cam->buffer_mode == B_DMA_contig)
-               vb2_dma_contig_cleanup_ctx(cam->vb_alloc_ctx);
-#endif
-#ifdef MCAM_MODE_DMA_SG
-       if (cam->buffer_mode == B_DMA_sg)
-               vb2_dma_sg_cleanup_ctx(cam->vb_alloc_ctx_sg);
-#endif
-}
-
 
 /* ---------------------------------------------------------------------- */
 /*
                cam_warn(cam, "Removing a device with users!\n");
                mcam_ctlr_power_down(cam);
        }
-       mcam_cleanup_vb2(cam);
        if (cam->buffer_mode == B_vmalloc)
                mcam_free_dma_bufs(cam);
        video_unregister_device(&cam->vdev);
 
 
        /* DMA buffers - DMA modes */
        struct mcam_vb_buffer *vb_bufs[MAX_DMA_BUFS];
-       struct vb2_alloc_ctx *vb_alloc_ctx;
-       struct vb2_alloc_ctx *vb_alloc_ctx_sg;
 
        /* Mode-specific ops, set at open time */
        void (*dma_setup)(struct mcam_camera *cam);
 
        struct clk              *clk_emma_ahb, *clk_emma_ipg;
 
        struct v4l2_m2m_dev     *m2m_dev;
-       struct vb2_alloc_ctx    *alloc_ctx;
 };
 
 struct emmaprp_ctx {
        *nbuffers = count;
        sizes[0] = size;
 
-       alloc_ctxs[0] = ctx->dev->alloc_ctx;
-
        dprintk(ctx->dev, "get %d buffer(s) of size %d each.\n", count, size);
 
        return 0;
        src_vq->ops = &emmaprp_qops;
        src_vq->mem_ops = &vb2_dma_contig_memops;
        src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
+       src_vq->dev = ctx->dev->v4l2_dev.dev;
 
        ret = vb2_queue_init(src_vq);
        if (ret)
        dst_vq->ops = &emmaprp_qops;
        dst_vq->mem_ops = &vb2_dma_contig_memops;
        dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
+       dst_vq->dev = ctx->dev->v4l2_dev.dev;
 
        return vb2_queue_init(dst_vq);
 }
        if (ret)
                goto rel_vdev;
 
-       pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
-       if (IS_ERR(pcdev->alloc_ctx)) {
-               v4l2_err(&pcdev->v4l2_dev, "Failed to alloc vb2 context\n");
-               ret = PTR_ERR(pcdev->alloc_ctx);
-               goto rel_vdev;
-       }
-
        pcdev->m2m_dev = v4l2_m2m_init(&m2m_ops);
        if (IS_ERR(pcdev->m2m_dev)) {
                v4l2_err(&pcdev->v4l2_dev, "Failed to init mem2mem device\n");
                ret = PTR_ERR(pcdev->m2m_dev);
-               goto rel_ctx;
+               goto rel_vdev;
        }
 
        ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
 
 rel_m2m:
        v4l2_m2m_release(pcdev->m2m_dev);
-rel_ctx:
-       vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
 rel_vdev:
        video_device_release(vfd);
 unreg_dev:
 
        video_unregister_device(pcdev->vfd);
        v4l2_m2m_release(pcdev->m2m_dev);
-       vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
        v4l2_device_unregister(&pcdev->v4l2_dev);
        mutex_destroy(&pcdev->dev_mutex);
 
 
        if (sizes[0] == 0)
                return -EINVAL;
 
-       alloc_ctxs[0] = video->alloc_ctx;
-
        *count = min(*count, video->capture_mem / PAGE_ALIGN(sizes[0]));
 
        return 0;
        queue->mem_ops = &vb2_dma_contig_memops;
        queue->buf_struct_size = sizeof(struct isp_buffer);
        queue->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+       queue->dev = video->isp->dev;
 
        ret = vb2_queue_init(&handle->queue);
        if (ret < 0) {
                return -EINVAL;
        }
 
-       video->alloc_ctx = vb2_dma_contig_init_ctx(video->isp->dev);
-       if (IS_ERR(video->alloc_ctx))
-               return PTR_ERR(video->alloc_ctx);
-
        ret = media_entity_pads_init(&video->video.entity, 1, &video->pad);
-       if (ret < 0) {
-               vb2_dma_contig_cleanup_ctx(video->alloc_ctx);
+       if (ret < 0)
                return ret;
-       }
 
        mutex_init(&video->mutex);
        atomic_set(&video->active, 0);
 
 void omap3isp_video_cleanup(struct isp_video *video)
 {
-       vb2_dma_contig_cleanup_ctx(video->alloc_ctx);
        media_entity_cleanup(&video->video.entity);
        mutex_destroy(&video->queue_lock);
        mutex_destroy(&video->stream_lock);
 
        bool error;
 
        /* Video buffers queue */
-       void *alloc_ctx;
        struct vb2_queue *queue;
        struct mutex queue_lock;        /* protects the queue */
        spinlock_t irqlock;             /* protects dmaqueue */
 
  * @irq: JPEG IP irq
  * @clk: JPEG IP clock
  * @dev: JPEG IP struct device
- * @alloc_ctx: videobuf2 memory allocator's context
  * @ref_count: reference counter
  */
 struct jpu {
        unsigned int            irq;
        struct clk              *clk;
        struct device           *dev;
-       void                    *alloc_ctx;
        int                     ref_count;
 };
 
 
                        if (sizes[i] < q_size)
                                return -EINVAL;
-                       alloc_ctxs[i] = ctx->jpu->alloc_ctx;
                }
                return 0;
        }
 
        *nplanes = q_data->format.num_planes;
 
-       for (i = 0; i < *nplanes; i++) {
+       for (i = 0; i < *nplanes; i++)
                sizes[i] = q_data->format.plane_fmt[i].sizeimage;
-               alloc_ctxs[i] = ctx->jpu->alloc_ctx;
-       }
 
        return 0;
 }
        src_vq->mem_ops = &vb2_dma_contig_memops;
        src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
        src_vq->lock = &ctx->jpu->mutex;
+       src_vq->dev = ctx->jpu->v4l2_dev.dev;
 
        ret = vb2_queue_init(src_vq);
        if (ret)
        dst_vq->mem_ops = &vb2_dma_contig_memops;
        dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
        dst_vq->lock = &ctx->jpu->mutex;
+       dst_vq->dev = ctx->jpu->v4l2_dev.dev;
 
        return vb2_queue_init(dst_vq);
 }
                goto device_register_rollback;
        }
 
-       jpu->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
-       if (IS_ERR(jpu->alloc_ctx)) {
-               v4l2_err(&jpu->v4l2_dev, "Failed to init memory allocator\n");
-               ret = PTR_ERR(jpu->alloc_ctx);
-               goto m2m_init_rollback;
-       }
-
        /* fill in qantization and Huffman tables for encoder */
        for (i = 0; i < JPU_MAX_QUALITY; i++)
                jpu_generate_hdr(i, (unsigned char *)jpeg_hdrs[i]);
        ret = video_register_device(&jpu->vfd_encoder, VFL_TYPE_GRABBER, -1);
        if (ret) {
                v4l2_err(&jpu->v4l2_dev, "Failed to register video device\n");
-               goto vb2_allocator_rollback;
+               goto m2m_init_rollback;
        }
 
        video_set_drvdata(&jpu->vfd_encoder, jpu);
 enc_vdev_register_rollback:
        video_unregister_device(&jpu->vfd_encoder);
 
-vb2_allocator_rollback:
-       vb2_dma_contig_cleanup_ctx(jpu->alloc_ctx);
-
 m2m_init_rollback:
        v4l2_m2m_release(jpu->m2m_dev);
 
 
        video_unregister_device(&jpu->vfd_decoder);
        video_unregister_device(&jpu->vfd_encoder);
-       vb2_dma_contig_cleanup_ctx(jpu->alloc_ctx);
        v4l2_m2m_release(jpu->m2m_dev);
        v4l2_device_unregister(&jpu->v4l2_dev);
 
 
        struct sh_veu_file *output;
        struct mutex fop_lock;
        void __iomem *base;
-       struct vb2_alloc_ctx *alloc_ctx;
        spinlock_t lock;
        bool is_2h;
        unsigned int xaction;
                *nbuffers = count;
        }
 
-       if (*nplanes) {
-               alloc_ctxs[0] = veu->alloc_ctx;
+       if (*nplanes)
                return sizes[0] < size ? -EINVAL : 0;
-       }
 
        *nplanes = 1;
        sizes[0] = size;
-       alloc_ctxs[0] = veu->alloc_ctx;
 
        dev_dbg(veu->dev, "get %d buffer(s) of size %d each.\n", count, size);
 
        src_vq->mem_ops = &vb2_dma_contig_memops;
        src_vq->lock = &veu->fop_lock;
        src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
+       src_vq->dev = veu->v4l2_dev.dev;
 
        ret = vb2_queue_init(src_vq);
        if (ret < 0)
        dst_vq->mem_ops = &vb2_dma_contig_memops;
        dst_vq->lock = &veu->fop_lock;
        dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
+       dst_vq->dev = veu->v4l2_dev.dev;
 
        return vb2_queue_init(dst_vq);
 }
 
        vdev = &veu->vdev;
 
-       veu->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
-       if (IS_ERR(veu->alloc_ctx)) {
-               ret = PTR_ERR(veu->alloc_ctx);
-               goto einitctx;
-       }
-
        *vdev = sh_veu_videodev;
        vdev->v4l2_dev = &veu->v4l2_dev;
        spin_lock_init(&veu->lock);
        pm_runtime_disable(&pdev->dev);
        v4l2_m2m_release(veu->m2m_dev);
 em2minit:
-       vb2_dma_contig_cleanup_ctx(veu->alloc_ctx);
-einitctx:
        v4l2_device_unregister(&veu->v4l2_dev);
        return ret;
 }
        video_unregister_device(&veu->vdev);
        pm_runtime_disable(&pdev->dev);
        v4l2_m2m_release(veu->m2m_dev);
-       vb2_dma_contig_cleanup_ctx(veu->alloc_ctx);
        v4l2_device_unregister(&veu->v4l2_dev);
 
        return 0;
 
        v4l2_std_id std;
        int pix_idx;
        struct vb2_queue queue;
-       struct vb2_alloc_ctx *alloc_ctx;
        struct sh_vou_buffer *active;
        enum sh_vou_status status;
        unsigned sequence;
 
        dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
 
-       alloc_ctxs[0] = vou_dev->alloc_ctx;
        if (*nplanes)
                return sizes[0] < pix->height * bytes_per_line ? -EINVAL : 0;
        *nplanes = 1;
        q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        q->min_buffers_needed = 2;
        q->lock = &vou_dev->fop_lock;
+       q->dev = &pdev->dev;
        ret = vb2_queue_init(q);
        if (ret)
-               goto einitctx;
+               goto ei2cgadap;
 
-       vou_dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
-       if (IS_ERR(vou_dev->alloc_ctx)) {
-               dev_err(&pdev->dev, "Can't allocate buffer context");
-               ret = PTR_ERR(vou_dev->alloc_ctx);
-               goto einitctx;
-       }
        vdev->queue = q;
        INIT_LIST_HEAD(&vou_dev->buf_list);
 
 ereset:
        i2c_put_adapter(i2c_adap);
 ei2cgadap:
-       vb2_dma_contig_cleanup_ctx(vou_dev->alloc_ctx);
-einitctx:
        pm_runtime_disable(&pdev->dev);
        v4l2_device_unregister(&vou_dev->v4l2_dev);
        return ret;
        pm_runtime_disable(&pdev->dev);
        video_unregister_device(&vou_dev->vdev);
        i2c_put_adapter(client->adapter);
-       vb2_dma_contig_cleanup_ctx(vou_dev->alloc_ctx);
        v4l2_device_unregister(&vou_dev->v4l2_dev);
        return 0;
 }