Skip to content

Commit 20be7ab

Browse files
Hans Verkuilmchehab
authored andcommitted
[media] vb2: add a dev field to use for the default allocation context
The allocation context is nothing more than a per-plane device pointer to use when allocating buffers. So just provide a dev pointer in vb2_queue for that purpose and drivers can skip allocating/releasing/filling in the allocation context unless they require different per-plane device pointers as used by some Samsung SoCs. Signed-off-by: Hans Verkuil <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Cc: Sakari Ailus <[email protected]> Cc: Florian Echtler <[email protected]> Cc: Federico Vaga <[email protected]> Cc: "Lad, Prabhakar" <[email protected]> Cc: Scott Jiang <[email protected]> Acked-by: Philipp Zabel <[email protected]> Cc: Fabien Dessenne <[email protected]> Acked-by: Benoit Parrot <[email protected]> Cc: Mikhail Ulyanov <[email protected]> Cc: Guennadi Liakhovetski <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Ludovic Desroches <[email protected]> Cc: Sergei Shtylyov <[email protected]> Cc: Kyungmin Park <[email protected]> Cc: Sylwester Nawrocki <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent d16e832 commit 20be7ab

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
206206
for (plane = 0; plane < vb->num_planes; ++plane) {
207207
unsigned long size = PAGE_ALIGN(vb->planes[plane].length);
208208

209-
mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane],
209+
mem_priv = call_ptr_memop(vb, alloc,
210+
q->alloc_ctx[plane] ? : &q->dev,
210211
q->dma_attrs, size, dma_dir, q->gfp_flags);
211212
if (IS_ERR_OR_NULL(mem_priv))
212213
goto free;
@@ -1131,9 +1132,10 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const void *pb)
11311132
vb->planes[plane].data_offset = 0;
11321133

11331134
/* Acquire each plane's memory */
1134-
mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane],
1135-
planes[plane].m.userptr,
1136-
planes[plane].length, dma_dir);
1135+
mem_priv = call_ptr_memop(vb, get_userptr,
1136+
q->alloc_ctx[plane] ? : &q->dev,
1137+
planes[plane].m.userptr,
1138+
planes[plane].length, dma_dir);
11371139
if (IS_ERR_OR_NULL(mem_priv)) {
11381140
dprintk(1, "failed acquiring userspace "
11391141
"memory for plane %d\n", plane);
@@ -1256,8 +1258,8 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const void *pb)
12561258

12571259
/* Acquire each plane's memory */
12581260
mem_priv = call_ptr_memop(vb, attach_dmabuf,
1259-
q->alloc_ctx[plane], dbuf, planes[plane].length,
1260-
dma_dir);
1261+
q->alloc_ctx[plane] ? : &q->dev,
1262+
dbuf, planes[plane].length, dma_dir);
12611263
if (IS_ERR(mem_priv)) {
12621264
dprintk(1, "failed to attach dmabuf\n");
12631265
ret = PTR_ERR(mem_priv);

include/media/videobuf2-core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ struct vb2_buf_ops {
400400
* caller. For example, for V4L2, it should match
401401
* the V4L2_BUF_TYPE_* in include/uapi/linux/videodev2.h
402402
* @io_modes: supported io methods (see vb2_io_modes enum)
403+
* @dev: device to use for the default allocation context if the driver
404+
* doesn't fill in the @alloc_ctx array.
403405
* @dma_attrs: DMA attributes to use for the DMA. May be NULL.
404406
* @fileio_read_once: report EOF after reading the first buffer
405407
* @fileio_write_immediately: queue buffer after each write() call
@@ -467,6 +469,7 @@ struct vb2_buf_ops {
467469
struct vb2_queue {
468470
unsigned int type;
469471
unsigned int io_modes;
472+
struct device *dev;
470473
const struct dma_attrs *dma_attrs;
471474
unsigned fileio_read_once:1;
472475
unsigned fileio_write_immediately:1;

0 commit comments

Comments
 (0)