[media] vb2: move dma_attrs to vb2_queue

Make the dma attributes struct part of vb2_queue. This greatly simplifies
the remainder of the patch series since the dma_contig alloc context is
now (as before) just a struct device pointer.

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>
This commit is contained in:
Hans Verkuil 2016-04-15 09:15:05 -03:00 committed by Mauro Carvalho Chehab
parent f61d500820
commit d16e832da2
6 changed files with 19 additions and 25 deletions

View File

@ -207,7 +207,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
unsigned long size = PAGE_ALIGN(vb->planes[plane].length); unsigned long size = PAGE_ALIGN(vb->planes[plane].length);
mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane], mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
size, dma_dir, q->gfp_flags); q->dma_attrs, size, dma_dir, q->gfp_flags);
if (IS_ERR_OR_NULL(mem_priv)) if (IS_ERR_OR_NULL(mem_priv))
goto free; goto free;

View File

@ -23,7 +23,6 @@
struct vb2_dc_conf { struct vb2_dc_conf {
struct device *dev; struct device *dev;
struct dma_attrs attrs;
}; };
struct vb2_dc_buf { struct vb2_dc_buf {
@ -140,8 +139,9 @@ static void vb2_dc_put(void *buf_priv)
kfree(buf); kfree(buf);
} }
static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size, static void *vb2_dc_alloc(void *alloc_ctx, const struct dma_attrs *attrs,
enum dma_data_direction dma_dir, gfp_t gfp_flags) unsigned long size, enum dma_data_direction dma_dir,
gfp_t gfp_flags)
{ {
struct vb2_dc_conf *conf = alloc_ctx; struct vb2_dc_conf *conf = alloc_ctx;
struct device *dev = conf->dev; struct device *dev = conf->dev;
@ -151,7 +151,8 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size,
if (!buf) if (!buf)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
buf->attrs = conf->attrs; if (attrs)
buf->attrs = *attrs;
buf->cookie = dma_alloc_attrs(dev, size, &buf->dma_addr, buf->cookie = dma_alloc_attrs(dev, size, &buf->dma_addr,
GFP_KERNEL | gfp_flags, &buf->attrs); GFP_KERNEL | gfp_flags, &buf->attrs);
if (!buf->cookie) { if (!buf->cookie) {
@ -729,8 +730,7 @@ const struct vb2_mem_ops vb2_dma_contig_memops = {
}; };
EXPORT_SYMBOL_GPL(vb2_dma_contig_memops); EXPORT_SYMBOL_GPL(vb2_dma_contig_memops);
void *vb2_dma_contig_init_ctx_attrs(struct device *dev, void *vb2_dma_contig_init_ctx(struct device *dev)
struct dma_attrs *attrs)
{ {
struct vb2_dc_conf *conf; struct vb2_dc_conf *conf;
@ -739,12 +739,10 @@ void *vb2_dma_contig_init_ctx_attrs(struct device *dev,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
conf->dev = dev; conf->dev = dev;
if (attrs)
conf->attrs = *attrs;
return conf; return conf;
} }
EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx_attrs); EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx);
void vb2_dma_contig_cleanup_ctx(void *alloc_ctx) void vb2_dma_contig_cleanup_ctx(void *alloc_ctx)
{ {

View File

@ -99,8 +99,9 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,
return 0; return 0;
} }
static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, static void *vb2_dma_sg_alloc(void *alloc_ctx, const struct dma_attrs *dma_attrs,
enum dma_data_direction dma_dir, gfp_t gfp_flags) 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_conf *conf = alloc_ctx;
struct vb2_dma_sg_buf *buf; struct vb2_dma_sg_buf *buf;

View File

@ -33,8 +33,9 @@ struct vb2_vmalloc_buf {
static void vb2_vmalloc_put(void *buf_priv); static void vb2_vmalloc_put(void *buf_priv);
static void *vb2_vmalloc_alloc(void *alloc_ctx, unsigned long size, static void *vb2_vmalloc_alloc(void *alloc_ctx, const struct dma_attrs *attrs,
enum dma_data_direction dma_dir, gfp_t gfp_flags) unsigned long size, enum dma_data_direction dma_dir,
gfp_t gfp_flags)
{ {
struct vb2_vmalloc_buf *buf; struct vb2_vmalloc_buf *buf;

View File

@ -27,7 +27,6 @@ enum vb2_memory {
VB2_MEMORY_DMABUF = 4, VB2_MEMORY_DMABUF = 4,
}; };
struct vb2_alloc_ctx;
struct vb2_fileio_data; struct vb2_fileio_data;
struct vb2_threadio_data; struct vb2_threadio_data;
@ -93,8 +92,8 @@ struct vb2_threadio_data;
* unmap_dmabuf. * unmap_dmabuf.
*/ */
struct vb2_mem_ops { struct vb2_mem_ops {
void *(*alloc)(void *alloc_ctx, unsigned long size, void *(*alloc)(void *alloc_ctx, const struct dma_attrs *attrs,
enum dma_data_direction dma_dir, unsigned long size, enum dma_data_direction dma_dir,
gfp_t gfp_flags); gfp_t gfp_flags);
void (*put)(void *buf_priv); void (*put)(void *buf_priv);
struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags); struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags);
@ -401,6 +400,7 @@ struct vb2_buf_ops {
* caller. For example, for V4L2, it should match * caller. For example, for V4L2, it should match
* the V4L2_BUF_TYPE_* in include/uapi/linux/videodev2.h * the V4L2_BUF_TYPE_* in include/uapi/linux/videodev2.h
* @io_modes: supported io methods (see vb2_io_modes enum) * @io_modes: supported io methods (see vb2_io_modes enum)
* @dma_attrs: DMA attributes to use for the DMA. May be NULL.
* @fileio_read_once: report EOF after reading the first buffer * @fileio_read_once: report EOF after reading the first buffer
* @fileio_write_immediately: queue buffer after each write() call * @fileio_write_immediately: queue buffer after each write() call
* @allow_zero_bytesused: allow bytesused == 0 to be passed to the driver * @allow_zero_bytesused: allow bytesused == 0 to be passed to the driver
@ -467,6 +467,7 @@ struct vb2_buf_ops {
struct vb2_queue { struct vb2_queue {
unsigned int type; unsigned int type;
unsigned int io_modes; unsigned int io_modes;
const struct dma_attrs *dma_attrs;
unsigned fileio_read_once:1; unsigned fileio_read_once:1;
unsigned fileio_write_immediately:1; unsigned fileio_write_immediately:1;
unsigned allow_zero_bytesused:1; unsigned allow_zero_bytesused:1;

View File

@ -26,14 +26,7 @@ vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no)
return *addr; return *addr;
} }
void *vb2_dma_contig_init_ctx_attrs(struct device *dev, void *vb2_dma_contig_init_ctx(struct device *dev);
struct dma_attrs *attrs);
static inline void *vb2_dma_contig_init_ctx(struct device *dev)
{
return vb2_dma_contig_init_ctx_attrs(dev, NULL);
}
void vb2_dma_contig_cleanup_ctx(void *alloc_ctx); void vb2_dma_contig_cleanup_ctx(void *alloc_ctx);
int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size); int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size);
void vb2_dma_contig_clear_max_seg_size(struct device *dev); void vb2_dma_contig_clear_max_seg_size(struct device *dev);