Stop using alloc_ctx and just fill in the device pointer.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Cc: Scott Jiang <scott.jiang.linux@gmail.com>
Acked-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
 
        if (vq->num_buffers + *nbuffers < 3)
                *nbuffers = 3 - vq->num_buffers;
-       alloc_ctxs[0] = vpfe->alloc_ctx;
 
        if (*nplanes) {
                if (sizes[0] < size)
                goto probe_out;
 
        /* Initialize videobuf2 queue as per the buffer type */
-       vpfe->alloc_ctx = vb2_dma_contig_init_ctx(vpfe->pdev);
-       if (IS_ERR(vpfe->alloc_ctx)) {
-               vpfe_err(vpfe, "Failed to get the context\n");
-               err = PTR_ERR(vpfe->alloc_ctx);
-               goto probe_out;
-       }
-
        q = &vpfe->buffer_queue;
        q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ;
        q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        q->lock = &vpfe->lock;
        q->min_buffers_needed = 1;
+       q->dev = vpfe->pdev;
 
        err = vb2_queue_init(q);
        if (err) {
                vpfe_err(vpfe, "vb2_queue_init() failed\n");
-               vb2_dma_contig_cleanup_ctx(vpfe->alloc_ctx);
                goto probe_out;
        }
 
 
        struct v4l2_rect crop;
        /* Buffer queue used in video-buf */
        struct vb2_queue buffer_queue;
-       /* Allocator-specific contexts for each plane */
-       struct vb2_alloc_ctx *alloc_ctx;
        /* Queue of filled frames */
        struct list_head dma_queue;
        /* IRQ lock for DMA queue */
 
        struct bcap_buffer *cur_frm;
        /* buffer queue used in videobuf2 */
        struct vb2_queue buffer_queue;
-       /* allocator-specific contexts for each plane */
-       struct vb2_alloc_ctx *alloc_ctx;
        /* queue of filled frames */
        struct list_head dma_queue;
        /* used in videobuf2 callback */
 
        if (vq->num_buffers + *nbuffers < 2)
                *nbuffers = 2;
-       alloc_ctxs[0] = bcap_dev->alloc_ctx;
 
        if (*nplanes)
                return sizes[0] < bcap_dev->fmt.sizeimage ? -EINVAL : 0;
        }
        bcap_dev->ppi->priv = bcap_dev;
 
-       bcap_dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
-       if (IS_ERR(bcap_dev->alloc_ctx)) {
-               ret = PTR_ERR(bcap_dev->alloc_ctx);
-               goto err_free_ppi;
-       }
-
        vfd = &bcap_dev->video_dev;
        /* initialize field of video device */
        vfd->release            = video_device_release_empty;
        if (ret) {
                v4l2_err(pdev->dev.driver,
                                "Unable to register v4l2 device\n");
-               goto err_cleanup_ctx;
+               goto err_free_ppi;
        }
        v4l2_info(&bcap_dev->v4l2_dev, "v4l2 device registered\n");
 
        q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        q->lock = &bcap_dev->mutex;
        q->min_buffers_needed = 1;
+       q->dev = &pdev->dev;
 
        ret = vb2_queue_init(q);
        if (ret)
        v4l2_ctrl_handler_free(&bcap_dev->ctrl_handler);
 err_unreg_v4l2:
        v4l2_device_unregister(&bcap_dev->v4l2_dev);
-err_cleanup_ctx:
-       vb2_dma_contig_cleanup_ctx(bcap_dev->alloc_ctx);
 err_free_ppi:
        ppi_delete_instance(bcap_dev->ppi);
 err_free_dev:
        video_unregister_device(&bcap_dev->video_dev);
        v4l2_ctrl_handler_free(&bcap_dev->ctrl_handler);
        v4l2_device_unregister(v4l2_dev);
-       vb2_dma_contig_cleanup_ctx(bcap_dev->alloc_ctx);
        ppi_delete_instance(bcap_dev->ppi);
        kfree(bcap_dev);
        return 0;
 
        *nplanes = 1;
        sizes[0] = size;
 
-       /* Set to vb2-dma-contig allocator context, ignored by vb2-vmalloc */
-       alloc_ctxs[0] = ctx->dev->alloc_ctx;
-
        v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
                 "get %d buffer(s) of size %d each.\n", *nbuffers, size);
 
         * that videobuf2 will keep the value of bytesused intact.
         */
        vq->allow_zero_bytesused = 1;
+       vq->dev = &ctx->dev->plat_dev->dev;
 
        return vb2_queue_init(vq);
 }
        if (ret < 0)
                goto put_pm;
 
-       dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
-       if (IS_ERR(dev->alloc_ctx)) {
-               v4l2_err(&dev->v4l2_dev, "Failed to alloc vb2 context\n");
-               goto put_pm;
-       }
-
        dev->m2m_dev = v4l2_m2m_init(&coda_m2m_ops);
        if (IS_ERR(dev->m2m_dev)) {
                v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n");
-               goto rel_ctx;
+               goto put_pm;
        }
 
        for (i = 0; i < dev->devtype->num_vdevs; i++) {
        while (--i >= 0)
                video_unregister_device(&dev->vfd[i]);
        v4l2_m2m_release(dev->m2m_dev);
-rel_ctx:
-       vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
 put_pm:
        pm_runtime_put_sync(&pdev->dev);
 }
        if (dev->m2m_dev)
                v4l2_m2m_release(dev->m2m_dev);
        pm_runtime_disable(&pdev->dev);
-       if (dev->alloc_ctx)
-               vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
        v4l2_device_unregister(&dev->v4l2_dev);
        destroy_workqueue(dev->workqueue);
        if (dev->iram.vaddr)
 
        struct mutex            coda_mutex;
        struct workqueue_struct *workqueue;
        struct v4l2_m2m_dev     *m2m_dev;
-       struct vb2_alloc_ctx    *alloc_ctx;
        struct list_head        instances;
        unsigned long           instance_mask;
        struct dentry           *debugfs_root;
 
        /* Store number of buffers allocated in numbuffer member */
        if (vq->num_buffers + *nbuffers < VPBE_DEFAULT_NUM_BUFS)
                *nbuffers = VPBE_DEFAULT_NUM_BUFS - vq->num_buffers;
-       alloc_ctxs[0] = layer->alloc_ctx;
 
        if (*nplanes)
                return sizes[0] < layer->pix_fmt.sizeimage ? -EINVAL : 0;
                q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
                q->min_buffers_needed = 1;
                q->lock = &disp_dev->dev[i]->opslock;
+               q->dev = disp_dev->vpbe_dev->pdev;
                err = vb2_queue_init(q);
                if (err) {
                        v4l2_err(v4l2_dev, "vb2_queue_init() failed\n");
                        goto probe_out;
                }
 
-               disp_dev->dev[i]->alloc_ctx =
-                       vb2_dma_contig_init_ctx(disp_dev->vpbe_dev->pdev);
-               if (IS_ERR(disp_dev->dev[i]->alloc_ctx)) {
-                       v4l2_err(v4l2_dev, "Failed to get the context\n");
-                       err = PTR_ERR(disp_dev->dev[i]->alloc_ctx);
-                       goto probe_out;
-               }
-
                INIT_LIST_HEAD(&disp_dev->dev[i]->dma_queue);
 
                if (register_device(disp_dev->dev[i], disp_dev, pdev)) {
        for (k = 0; k < VPBE_DISPLAY_MAX_DEVICES; k++) {
                /* Unregister video device */
                if (disp_dev->dev[k] != NULL) {
-                       vb2_dma_contig_cleanup_ctx(disp_dev->dev[k]->alloc_ctx);
                        video_unregister_device(&disp_dev->dev[k]->video_dev);
                        kfree(disp_dev->dev[k]);
                }
        for (i = 0; i < VPBE_DISPLAY_MAX_DEVICES; i++) {
                /* Get the pointer to the layer object */
                vpbe_display_layer = disp_dev->dev[i];
-               vb2_dma_contig_cleanup_ctx(vpbe_display_layer->alloc_ctx);
                /* Unregister video device */
                video_unregister_device(&vpbe_display_layer->video_dev);
 
 
 
        *nplanes = 1;
        sizes[0] = size;
-       alloc_ctxs[0] = common->alloc_ctx;
 
        /* Calculate the offset for Y and C data in the buffer */
        vpif_calculate_offsets(ch);
                q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
                q->min_buffers_needed = 1;
                q->lock = &common->lock;
+               q->dev = vpif_dev;
 
                err = vb2_queue_init(q);
                if (err) {
                        goto probe_out;
                }
 
-               common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
-               if (IS_ERR(common->alloc_ctx)) {
-                       vpif_err("Failed to get the context\n");
-                       err = PTR_ERR(common->alloc_ctx);
-                       goto probe_out;
-               }
-
                INIT_LIST_HEAD(&common->dma_queue);
 
                /* Initialize the video_device structure */
                /* Get the pointer to the channel object */
                ch = vpif_obj.dev[k];
                common = &ch->common[k];
-               vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
                /* Unregister video device */
                video_unregister_device(&ch->video_dev);
        }
                /* Get the pointer to the channel object */
                ch = vpif_obj.dev[i];
                common = &ch->common[VPIF_VIDEO_INDEX];
-               vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
                /* Unregister video device */
                video_unregister_device(&ch->video_dev);
                kfree(vpif_obj.dev[i]);
 
        struct v4l2_format fmt;
        /* Buffer queue used in video-buf */
        struct vb2_queue buffer_queue;
-       /* allocator-specific contexts for each plane */
-       struct vb2_alloc_ctx *alloc_ctx;
        /* Queue of filled frames */
        struct list_head dma_queue;
        /* Used in video-buf */
 
 
        *nplanes = 1;
        sizes[0] = size;
-       alloc_ctxs[0] = common->alloc_ctx;
 
        /* Calculate the offset for Y and C data  in the buffer */
        vpif_calculate_offsets(ch);
                q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
                q->min_buffers_needed = 1;
                q->lock = &common->lock;
+               q->dev = vpif_dev;
                err = vb2_queue_init(q);
                if (err) {
                        vpif_err("vpif_display: vb2_queue_init() failed\n");
                        goto probe_out;
                }
 
-               common->alloc_ctx = vb2_dma_contig_init_ctx(vpif_dev);
-               if (IS_ERR(common->alloc_ctx)) {
-                       vpif_err("Failed to get the context\n");
-                       err = PTR_ERR(common->alloc_ctx);
-                       goto probe_out;
-               }
-
                INIT_LIST_HEAD(&common->dma_queue);
 
                /* register video device */
        for (k = 0; k < j; k++) {
                ch = vpif_obj.dev[k];
                common = &ch->common[k];
-               vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
                video_unregister_device(&ch->video_dev);
        }
        return err;
                /* Get the pointer to the channel object */
                ch = vpif_obj.dev[i];
                common = &ch->common[VPIF_VIDEO_INDEX];
-               vb2_dma_contig_cleanup_ctx(common->alloc_ctx);
                /* Unregister video device */
                video_unregister_device(&ch->video_dev);
                kfree(vpif_obj.dev[i]);
 
        struct v4l2_format fmt;                 /* Used to store the format */
        struct vb2_queue buffer_queue;          /* Buffer queue used in
                                                 * video-buf */
-       /* allocator-specific contexts for each plane */
-       struct vb2_alloc_ctx *alloc_ctx;
 
        struct list_head dma_queue;             /* Queue of filled frames */
        spinlock_t irqlock;                     /* Used in video-buf */
 
 {
        struct rvin_dev *vin = vb2_get_drv_priv(vq);
 
-       alloc_ctxs[0] = vin->alloc_ctx;
        /* Make sure the image size is large enough. */
        if (*nplanes)
                return sizes[0] < vin->format.sizeimage ? -EINVAL : 0;
 
 void rvin_dma_remove(struct rvin_dev *vin)
 {
-       if (!IS_ERR_OR_NULL(vin->alloc_ctx))
-               vb2_dma_contig_cleanup_ctx(vin->alloc_ctx);
-
        mutex_destroy(&vin->lock);
 
        v4l2_device_unregister(&vin->v4l2_dev);
                vin->queue_buf[i] = NULL;
 
        /* buffer queue */
-       vin->alloc_ctx = vb2_dma_contig_init_ctx(vin->dev);
-       if (IS_ERR(vin->alloc_ctx)) {
-               ret = PTR_ERR(vin->alloc_ctx);
-               goto error;
-       }
-
        q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        q->io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF;
        q->lock = &vin->lock;
        q->mem_ops = &vb2_dma_contig_memops;
        q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        q->min_buffers_needed = 2;
+       q->dev = vin->dev;
 
        ret = vb2_queue_init(q);
        if (ret < 0) {
 
  *
  * @lock:              protects @queue
  * @queue:             vb2 buffers queue
- * @alloc_ctx:         allocation context for the vb2 @queue
  *
  * @qlock:             protects @queue_buf, @buf_list, @continuous, @sequence
  *                     @state
 
        struct mutex lock;
        struct vb2_queue queue;
-       struct vb2_alloc_ctx *alloc_ctx;
 
        spinlock_t qlock;
        struct vb2_v4l2_buffer *queue_buf[HW_BUFFER_NUM];
 
         * Buffer queue used in video-buf
         */
        struct vb2_queue buffer_queue;
-       /* allocator-specific contexts for each plane */
-       struct vb2_alloc_ctx *alloc_ctx;
        /* Queue of filled frames */
        struct list_head dma_queue;
        /* Used in video-buf */