diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2016-04-15 09:15:05 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-07-08 14:45:07 -0300 |
commit | 36c0f8b32c4bd4f668cedfba6d97afaa84f055fb (patch) | |
tree | fb65309d392241a0ae6733346b38145be971274f /drivers/media/v4l2-core | |
parent | 2548fee63d9eb43299dacd0ca30dd9d8f407d795 (diff) | |
download | linux-36c0f8b32c4bd4f668cedfba6d97afaa84f055fb.tar.gz linux-36c0f8b32c4bd4f668cedfba6d97afaa84f055fb.tar.bz2 linux-36c0f8b32c4bd4f668cedfba6d97afaa84f055fb.zip |
[media] vb2: replace void *alloc_ctxs by struct device *alloc_devs
Make this a proper typed array. Drop the old allocate context code since
that is no longer used.
Note that the memops functions now get a struct device pointer instead of
the struct device ** that was there initially (actually a void pointer to
a struct containing only a struct device pointer).
This code is now a lot cleaner.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/v4l2-core')
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-core.c | 18 | ||||
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-dma-contig.c | 39 | ||||
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-dma-sg.c | 42 | ||||
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-vmalloc.c | 6 |
4 files changed, 24 insertions, 81 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index aabb03e406f0..0b9e71e48ddb 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -207,7 +207,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) unsigned long size = PAGE_ALIGN(vb->planes[plane].length); mem_priv = call_ptr_memop(vb, alloc, - q->alloc_ctx[plane] ? : &q->dev, + q->alloc_devs[plane] ? : q->dev, q->dma_attrs, size, dma_dir, q->gfp_flags); if (IS_ERR_OR_NULL(mem_priv)) goto free; @@ -738,7 +738,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, */ num_buffers = min_t(unsigned int, *count, VB2_MAX_FRAME); num_buffers = max_t(unsigned int, num_buffers, q->min_buffers_needed); - memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); + memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); q->memory = memory; /* @@ -746,7 +746,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * Driver also sets the size and allocator context for each plane. */ ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, - plane_sizes, q->alloc_ctx); + plane_sizes, q->alloc_devs); if (ret) return ret; @@ -779,7 +779,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, num_planes = 0; ret = call_qop(q, queue_setup, q, &num_buffers, - &num_planes, plane_sizes, q->alloc_ctx); + &num_planes, plane_sizes, q->alloc_devs); if (!ret && allocated_buffers < num_buffers) ret = -ENOMEM; @@ -845,7 +845,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, } if (!q->num_buffers) { - memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx)); + memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); q->memory = memory; q->waiting_for_buffers = !q->is_output; } @@ -862,7 +862,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * buffer and their sizes are acceptable */ ret = call_qop(q, queue_setup, q, &num_buffers, - &num_planes, plane_sizes, q->alloc_ctx); + &num_planes, plane_sizes, q->alloc_devs); if (ret) return ret; @@ -885,7 +885,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * queue driver has set up */ ret = call_qop(q, queue_setup, q, &num_buffers, - &num_planes, plane_sizes, q->alloc_ctx); + &num_planes, plane_sizes, q->alloc_devs); if (!ret && allocated_buffers < num_buffers) ret = -ENOMEM; @@ -1133,7 +1133,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const void *pb) /* Acquire each plane's memory */ mem_priv = call_ptr_memop(vb, get_userptr, - q->alloc_ctx[plane] ? : &q->dev, + q->alloc_devs[plane] ? : q->dev, planes[plane].m.userptr, planes[plane].length, dma_dir); if (IS_ERR_OR_NULL(mem_priv)) { @@ -1258,7 +1258,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const void *pb) /* Acquire each plane's memory */ mem_priv = call_ptr_memop(vb, attach_dmabuf, - q->alloc_ctx[plane] ? : &q->dev, + q->alloc_devs[plane] ? : q->dev, dbuf, planes[plane].length, dma_dir); if (IS_ERR(mem_priv)) { dprintk(1, "failed to attach dmabuf\n"); diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index a7825c62ad88..863f658a3fa1 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -21,10 +21,6 @@ #include <media/videobuf2-dma-contig.h> #include <media/videobuf2-memops.h> -struct vb2_dc_conf { - struct device *dev; -}; - struct vb2_dc_buf { struct device *dev; void *vaddr; @@ -139,12 +135,10 @@ static void vb2_dc_put(void *buf_priv) kfree(buf); } -static void *vb2_dc_alloc(void *alloc_ctx, const struct dma_attrs *attrs, +static void *vb2_dc_alloc(struct device *dev, const struct dma_attrs *attrs, unsigned long size, enum dma_data_direction dma_dir, gfp_t gfp_flags) { - struct vb2_dc_conf *conf = alloc_ctx; - struct device *dev = conf->dev; struct vb2_dc_buf *buf; buf = kzalloc(sizeof *buf, GFP_KERNEL); @@ -479,10 +473,9 @@ static inline dma_addr_t vb2_dc_pfn_to_dma(struct device *dev, unsigned long pfn } #endif -static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr, +static void *vb2_dc_get_userptr(struct device *dev, unsigned long vaddr, unsigned long size, enum dma_data_direction dma_dir) { - struct vb2_dc_conf *conf = alloc_ctx; struct vb2_dc_buf *buf; struct frame_vector *vec; unsigned long offset; @@ -510,7 +503,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr, if (!buf) return ERR_PTR(-ENOMEM); - buf->dev = conf->dev; + buf->dev = dev; buf->dma_dir = dma_dir; offset = vaddr & ~PAGE_MASK; @@ -677,10 +670,9 @@ static void vb2_dc_detach_dmabuf(void *mem_priv) kfree(buf); } -static void *vb2_dc_attach_dmabuf(void *alloc_ctx, struct dma_buf *dbuf, +static void *vb2_dc_attach_dmabuf(struct device *dev, struct dma_buf *dbuf, unsigned long size, enum dma_data_direction dma_dir) { - struct vb2_dc_conf *conf = alloc_ctx; struct vb2_dc_buf *buf; struct dma_buf_attachment *dba; @@ -691,7 +683,7 @@ static void *vb2_dc_attach_dmabuf(void *alloc_ctx, struct dma_buf *dbuf, if (!buf) return ERR_PTR(-ENOMEM); - buf->dev = conf->dev; + buf->dev = dev; /* create attachment for the dmabuf with the user device */ dba = dma_buf_attach(dbuf, buf->dev); if (IS_ERR(dba)) { @@ -730,27 +722,6 @@ const struct vb2_mem_ops vb2_dma_contig_memops = { }; EXPORT_SYMBOL_GPL(vb2_dma_contig_memops); -void *vb2_dma_contig_init_ctx(struct device *dev) -{ - struct vb2_dc_conf *conf; - - conf = kzalloc(sizeof *conf, GFP_KERNEL); - if (!conf) - return ERR_PTR(-ENOMEM); - - conf->dev = dev; - - return conf; -} -EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx); - -void vb2_dma_contig_cleanup_ctx(void *alloc_ctx) -{ - if (!IS_ERR_OR_NULL(alloc_ctx)) - kfree(alloc_ctx); -} -EXPORT_SYMBOL_GPL(vb2_dma_contig_cleanup_ctx); - /** * vb2_dma_contig_set_max_seg_size() - configure DMA max segment size * @dev: device for configuring DMA parameters diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c index e7153f708ade..a39db8a6db7a 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c @@ -30,10 +30,6 @@ module_param(debug, int, 0644); printk(KERN_DEBUG "vb2-dma-sg: " fmt, ## arg); \ } while (0) -struct vb2_dma_sg_conf { - struct device *dev; -}; - struct vb2_dma_sg_buf { struct device *dev; void *vaddr; @@ -99,11 +95,10 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf, return 0; } -static void *vb2_dma_sg_alloc(void *alloc_ctx, const struct dma_attrs *dma_attrs, +static void *vb2_dma_sg_alloc(struct device *dev, const struct dma_attrs *dma_attrs, unsigned long size, enum dma_data_direction dma_dir, gfp_t gfp_flags) { - struct vb2_dma_sg_conf *conf = alloc_ctx; struct vb2_dma_sg_buf *buf; struct sg_table *sgt; int ret; @@ -112,7 +107,7 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, const struct dma_attrs *dma_attrs dma_set_attr(DMA_ATTR_SKIP_CPU_SYNC, &attrs); - if (WARN_ON(alloc_ctx == NULL)) + if (WARN_ON(dev == NULL)) return NULL; buf = kzalloc(sizeof *buf, GFP_KERNEL); if (!buf) @@ -141,7 +136,7 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, const struct dma_attrs *dma_attrs goto fail_table_alloc; /* Prevent the device from being released while the buffer is used */ - buf->dev = get_device(conf->dev); + buf->dev = get_device(dev); sgt = &buf->sg_table; /* @@ -227,11 +222,10 @@ static void vb2_dma_sg_finish(void *buf_priv) dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); } -static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr, +static void *vb2_dma_sg_get_userptr(struct device *dev, unsigned long vaddr, unsigned long size, enum dma_data_direction dma_dir) { - struct vb2_dma_sg_conf *conf = alloc_ctx; struct vb2_dma_sg_buf *buf; struct sg_table *sgt; DEFINE_DMA_ATTRS(attrs); @@ -243,7 +237,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, unsigned long vaddr, return NULL; buf->vaddr = NULL; - buf->dev = conf->dev; + buf->dev = dev; buf->dma_dir = dma_dir; buf->offset = vaddr & ~PAGE_MASK; buf->size = size; @@ -617,10 +611,9 @@ static void vb2_dma_sg_detach_dmabuf(void *mem_priv) kfree(buf); } -static void *vb2_dma_sg_attach_dmabuf(void *alloc_ctx, struct dma_buf *dbuf, +static void *vb2_dma_sg_attach_dmabuf(struct device *dev, struct dma_buf *dbuf, unsigned long size, enum dma_data_direction dma_dir) { - struct vb2_dma_sg_conf *conf = alloc_ctx; struct vb2_dma_sg_buf *buf; struct dma_buf_attachment *dba; @@ -631,7 +624,7 @@ static void *vb2_dma_sg_attach_dmabuf(void *alloc_ctx, struct dma_buf *dbuf, if (!buf) return ERR_PTR(-ENOMEM); - buf->dev = conf->dev; + buf->dev = dev; /* create attachment for the dmabuf with the user device */ dba = dma_buf_attach(dbuf, buf->dev); if (IS_ERR(dba)) { @@ -673,27 +666,6 @@ const struct vb2_mem_ops vb2_dma_sg_memops = { }; EXPORT_SYMBOL_GPL(vb2_dma_sg_memops); -void *vb2_dma_sg_init_ctx(struct device *dev) -{ - struct vb2_dma_sg_conf *conf; - - conf = kzalloc(sizeof(*conf), GFP_KERNEL); - if (!conf) - return ERR_PTR(-ENOMEM); - - conf->dev = dev; - - return conf; -} -EXPORT_SYMBOL_GPL(vb2_dma_sg_init_ctx); - -void vb2_dma_sg_cleanup_ctx(void *alloc_ctx) -{ - if (!IS_ERR_OR_NULL(alloc_ctx)) - kfree(alloc_ctx); -} -EXPORT_SYMBOL_GPL(vb2_dma_sg_cleanup_ctx); - MODULE_DESCRIPTION("dma scatter/gather memory handling routines for videobuf2"); MODULE_AUTHOR("Andrzej Pietrasiewicz"); MODULE_LICENSE("GPL"); diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c index fb94c80e9aa8..7e8a07ed8d82 100644 --- a/drivers/media/v4l2-core/videobuf2-vmalloc.c +++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c @@ -33,7 +33,7 @@ struct vb2_vmalloc_buf { static void vb2_vmalloc_put(void *buf_priv); -static void *vb2_vmalloc_alloc(void *alloc_ctx, const struct dma_attrs *attrs, +static void *vb2_vmalloc_alloc(struct device *dev, const struct dma_attrs *attrs, unsigned long size, enum dma_data_direction dma_dir, gfp_t gfp_flags) { @@ -70,7 +70,7 @@ static void vb2_vmalloc_put(void *buf_priv) } } -static void *vb2_vmalloc_get_userptr(void *alloc_ctx, unsigned long vaddr, +static void *vb2_vmalloc_get_userptr(struct device *dev, unsigned long vaddr, unsigned long size, enum dma_data_direction dma_dir) { @@ -404,7 +404,7 @@ static void vb2_vmalloc_detach_dmabuf(void *mem_priv) kfree(buf); } -static void *vb2_vmalloc_attach_dmabuf(void *alloc_ctx, struct dma_buf *dbuf, +static void *vb2_vmalloc_attach_dmabuf(struct device *dev, struct dma_buf *dbuf, unsigned long size, enum dma_data_direction dma_dir) { struct vb2_vmalloc_buf *buf; |