Skip to content

Commit d16e832

Browse files
Hans Verkuilmchehab
authored andcommitted
[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 <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Cc: Sakari Ailus <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent f61d500 commit d16e832

File tree

6 files changed

+19
-25
lines changed

6 files changed

+19
-25
lines changed

drivers/media/v4l2-core/videobuf2-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
207207
unsigned long size = PAGE_ALIGN(vb->planes[plane].length);
208208

209209
mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
210-
size, dma_dir, q->gfp_flags);
210+
q->dma_attrs, size, dma_dir, q->gfp_flags);
211211
if (IS_ERR_OR_NULL(mem_priv))
212212
goto free;
213213

drivers/media/v4l2-core/videobuf2-dma-contig.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
struct vb2_dc_conf {
2525
struct device *dev;
26-
struct dma_attrs attrs;
2726
};
2827

2928
struct vb2_dc_buf {
@@ -140,8 +139,9 @@ static void vb2_dc_put(void *buf_priv)
140139
kfree(buf);
141140
}
142141

143-
static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size,
144-
enum dma_data_direction dma_dir, gfp_t gfp_flags)
142+
static void *vb2_dc_alloc(void *alloc_ctx, const struct dma_attrs *attrs,
143+
unsigned long size, enum dma_data_direction dma_dir,
144+
gfp_t gfp_flags)
145145
{
146146
struct vb2_dc_conf *conf = alloc_ctx;
147147
struct device *dev = conf->dev;
@@ -151,7 +151,8 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size,
151151
if (!buf)
152152
return ERR_PTR(-ENOMEM);
153153

154-
buf->attrs = conf->attrs;
154+
if (attrs)
155+
buf->attrs = *attrs;
155156
buf->cookie = dma_alloc_attrs(dev, size, &buf->dma_addr,
156157
GFP_KERNEL | gfp_flags, &buf->attrs);
157158
if (!buf->cookie) {
@@ -729,8 +730,7 @@ const struct vb2_mem_ops vb2_dma_contig_memops = {
729730
};
730731
EXPORT_SYMBOL_GPL(vb2_dma_contig_memops);
731732

732-
void *vb2_dma_contig_init_ctx_attrs(struct device *dev,
733-
struct dma_attrs *attrs)
733+
void *vb2_dma_contig_init_ctx(struct device *dev)
734734
{
735735
struct vb2_dc_conf *conf;
736736

@@ -739,12 +739,10 @@ void *vb2_dma_contig_init_ctx_attrs(struct device *dev,
739739
return ERR_PTR(-ENOMEM);
740740

741741
conf->dev = dev;
742-
if (attrs)
743-
conf->attrs = *attrs;
744742

745743
return conf;
746744
}
747-
EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx_attrs);
745+
EXPORT_SYMBOL_GPL(vb2_dma_contig_init_ctx);
748746

749747
void vb2_dma_contig_cleanup_ctx(void *alloc_ctx)
750748
{

drivers/media/v4l2-core/videobuf2-dma-sg.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ static int vb2_dma_sg_alloc_compacted(struct vb2_dma_sg_buf *buf,
9999
return 0;
100100
}
101101

102-
static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size,
103-
enum dma_data_direction dma_dir, gfp_t gfp_flags)
102+
static void *vb2_dma_sg_alloc(void *alloc_ctx, const struct dma_attrs *dma_attrs,
103+
unsigned long size, enum dma_data_direction dma_dir,
104+
gfp_t gfp_flags)
104105
{
105106
struct vb2_dma_sg_conf *conf = alloc_ctx;
106107
struct vb2_dma_sg_buf *buf;

drivers/media/v4l2-core/videobuf2-vmalloc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ struct vb2_vmalloc_buf {
3333

3434
static void vb2_vmalloc_put(void *buf_priv);
3535

36-
static void *vb2_vmalloc_alloc(void *alloc_ctx, unsigned long size,
37-
enum dma_data_direction dma_dir, gfp_t gfp_flags)
36+
static void *vb2_vmalloc_alloc(void *alloc_ctx, const struct dma_attrs *attrs,
37+
unsigned long size, enum dma_data_direction dma_dir,
38+
gfp_t gfp_flags)
3839
{
3940
struct vb2_vmalloc_buf *buf;
4041

include/media/videobuf2-core.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ enum vb2_memory {
2727
VB2_MEMORY_DMABUF = 4,
2828
};
2929

30-
struct vb2_alloc_ctx;
3130
struct vb2_fileio_data;
3231
struct vb2_threadio_data;
3332

@@ -93,8 +92,8 @@ struct vb2_threadio_data;
9392
* unmap_dmabuf.
9493
*/
9594
struct vb2_mem_ops {
96-
void *(*alloc)(void *alloc_ctx, unsigned long size,
97-
enum dma_data_direction dma_dir,
95+
void *(*alloc)(void *alloc_ctx, const struct dma_attrs *attrs,
96+
unsigned long size, enum dma_data_direction dma_dir,
9897
gfp_t gfp_flags);
9998
void (*put)(void *buf_priv);
10099
struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags);
@@ -401,6 +400,7 @@ struct vb2_buf_ops {
401400
* caller. For example, for V4L2, it should match
402401
* the V4L2_BUF_TYPE_* in include/uapi/linux/videodev2.h
403402
* @io_modes: supported io methods (see vb2_io_modes enum)
403+
* @dma_attrs: DMA attributes to use for the DMA. May be NULL.
404404
* @fileio_read_once: report EOF after reading the first buffer
405405
* @fileio_write_immediately: queue buffer after each write() call
406406
* @allow_zero_bytesused: allow bytesused == 0 to be passed to the driver
@@ -467,6 +467,7 @@ struct vb2_buf_ops {
467467
struct vb2_queue {
468468
unsigned int type;
469469
unsigned int io_modes;
470+
const struct dma_attrs *dma_attrs;
470471
unsigned fileio_read_once:1;
471472
unsigned fileio_write_immediately:1;
472473
unsigned allow_zero_bytesused:1;

include/media/videobuf2-dma-contig.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no)
2626
return *addr;
2727
}
2828

29-
void *vb2_dma_contig_init_ctx_attrs(struct device *dev,
30-
struct dma_attrs *attrs);
31-
32-
static inline void *vb2_dma_contig_init_ctx(struct device *dev)
33-
{
34-
return vb2_dma_contig_init_ctx_attrs(dev, NULL);
35-
}
36-
29+
void *vb2_dma_contig_init_ctx(struct device *dev);
3730
void vb2_dma_contig_cleanup_ctx(void *alloc_ctx);
3831
int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size);
3932
void vb2_dma_contig_clear_max_seg_size(struct device *dev);

0 commit comments

Comments
 (0)