diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2013-03-01 13:44:20 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-03-21 12:17:51 -0400 |
commit | b6ba2057f7823352bbc44ee846faa03b36e8b6ac (patch) | |
tree | 130c5bafcd2e497c45d8a1e5e9e764dc88bff00c | |
parent | 808d24d6c0b5c30c8f804b251caf476ea63954ef (diff) |
[media] videobuf2: add gfp_flags
Some drivers have special memory requirements for their buffers, usually
related to DMA (e.g. GFP_DMA or __GFP_DMA32). Make it possible to specify
additional GFP flags for those buffers by adding a gfp_flags field to
vb2_queue.
Note that this field will be replaced in the future with a different
mechanism, but that is still work in progress and we need this feature
now so we won't be able to convert drivers with such requirements to vb2.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Federico Vaga <federico.vaga@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-core.c | 2 | ||||
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-dma-contig.c | 5 | ||||
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-dma-sg.c | 5 | ||||
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-vmalloc.c | 4 | ||||
-rw-r--r-- | include/media/videobuf2-core.h | 10 |
5 files changed, 17 insertions, 9 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index be0448161c60..70827feb87b4 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c | |||
@@ -57,7 +57,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) | |||
57 | /* Allocate memory for all planes in this buffer */ | 57 | /* Allocate memory for all planes in this buffer */ |
58 | for (plane = 0; plane < vb->num_planes; ++plane) { | 58 | for (plane = 0; plane < vb->num_planes; ++plane) { |
59 | mem_priv = call_memop(q, alloc, q->alloc_ctx[plane], | 59 | mem_priv = call_memop(q, alloc, q->alloc_ctx[plane], |
60 | q->plane_sizes[plane]); | 60 | q->plane_sizes[plane], q->gfp_flags); |
61 | if (IS_ERR_OR_NULL(mem_priv)) | 61 | if (IS_ERR_OR_NULL(mem_priv)) |
62 | goto free; | 62 | goto free; |
63 | 63 | ||
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index 10beaee7f0ae..ae35d255a430 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c | |||
@@ -152,7 +152,7 @@ static void vb2_dc_put(void *buf_priv) | |||
152 | kfree(buf); | 152 | kfree(buf); |
153 | } | 153 | } |
154 | 154 | ||
155 | static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) | 155 | static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags) |
156 | { | 156 | { |
157 | struct vb2_dc_conf *conf = alloc_ctx; | 157 | struct vb2_dc_conf *conf = alloc_ctx; |
158 | struct device *dev = conf->dev; | 158 | struct device *dev = conf->dev; |
@@ -165,7 +165,8 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) | |||
165 | /* align image size to PAGE_SIZE */ | 165 | /* align image size to PAGE_SIZE */ |
166 | size = PAGE_ALIGN(size); | 166 | size = PAGE_ALIGN(size); |
167 | 167 | ||
168 | buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, GFP_KERNEL); | 168 | buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr, |
169 | GFP_KERNEL | gfp_flags); | ||
169 | if (!buf->vaddr) { | 170 | if (!buf->vaddr) { |
170 | dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size); | 171 | dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size); |
171 | kfree(buf); | 172 | kfree(buf); |
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c index 25c3b360e1ad..952776fafe2c 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c | |||
@@ -33,7 +33,7 @@ struct vb2_dma_sg_buf { | |||
33 | 33 | ||
34 | static void vb2_dma_sg_put(void *buf_priv); | 34 | static void vb2_dma_sg_put(void *buf_priv); |
35 | 35 | ||
36 | static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size) | 36 | static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags) |
37 | { | 37 | { |
38 | struct vb2_dma_sg_buf *buf; | 38 | struct vb2_dma_sg_buf *buf; |
39 | int i; | 39 | int i; |
@@ -60,7 +60,8 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned long size) | |||
60 | goto fail_pages_array_alloc; | 60 | goto fail_pages_array_alloc; |
61 | 61 | ||
62 | for (i = 0; i < buf->sg_desc.num_pages; ++i) { | 62 | for (i = 0; i < buf->sg_desc.num_pages; ++i) { |
63 | buf->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN); | 63 | buf->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO | |
64 | __GFP_NOWARN | gfp_flags); | ||
64 | if (NULL == buf->pages[i]) | 65 | if (NULL == buf->pages[i]) |
65 | goto fail_pages_alloc; | 66 | goto fail_pages_alloc; |
66 | sg_set_page(&buf->sg_desc.sglist[i], | 67 | sg_set_page(&buf->sg_desc.sglist[i], |
diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c index a47fd4f589a1..313d9771b2bc 100644 --- a/drivers/media/v4l2-core/videobuf2-vmalloc.c +++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c | |||
@@ -35,11 +35,11 @@ struct vb2_vmalloc_buf { | |||
35 | 35 | ||
36 | static void vb2_vmalloc_put(void *buf_priv); | 36 | static void vb2_vmalloc_put(void *buf_priv); |
37 | 37 | ||
38 | static void *vb2_vmalloc_alloc(void *alloc_ctx, unsigned long size) | 38 | static void *vb2_vmalloc_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags) |
39 | { | 39 | { |
40 | struct vb2_vmalloc_buf *buf; | 40 | struct vb2_vmalloc_buf *buf; |
41 | 41 | ||
42 | buf = kzalloc(sizeof(*buf), GFP_KERNEL); | 42 | buf = kzalloc(sizeof(*buf), GFP_KERNEL | gfp_flags); |
43 | if (!buf) | 43 | if (!buf) |
44 | return NULL; | 44 | return NULL; |
45 | 45 | ||
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index a2d427450780..d88a098d1aff 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h | |||
@@ -27,7 +27,9 @@ struct vb2_fileio_data; | |||
27 | * return NULL on failure or a pointer to allocator private, | 27 | * return NULL on failure or a pointer to allocator private, |
28 | * per-buffer data on success; the returned private structure | 28 | * per-buffer data on success; the returned private structure |
29 | * will then be passed as buf_priv argument to other ops in this | 29 | * will then be passed as buf_priv argument to other ops in this |
30 | * structure | 30 | * structure. Additional gfp_flags to use when allocating the |
31 | * are also passed to this operation. These flags are from the | ||
32 | * gfp_flags field of vb2_queue. | ||
31 | * @put: inform the allocator that the buffer will no longer be used; | 33 | * @put: inform the allocator that the buffer will no longer be used; |
32 | * usually will result in the allocator freeing the buffer (if | 34 | * usually will result in the allocator freeing the buffer (if |
33 | * no other users of this buffer are present); the buf_priv | 35 | * no other users of this buffer are present); the buf_priv |
@@ -79,7 +81,7 @@ struct vb2_fileio_data; | |||
79 | * unmap_dmabuf. | 81 | * unmap_dmabuf. |
80 | */ | 82 | */ |
81 | struct vb2_mem_ops { | 83 | struct vb2_mem_ops { |
82 | void *(*alloc)(void *alloc_ctx, unsigned long size); | 84 | void *(*alloc)(void *alloc_ctx, unsigned long size, gfp_t gfp_flags); |
83 | void (*put)(void *buf_priv); | 85 | void (*put)(void *buf_priv); |
84 | struct dma_buf *(*get_dmabuf)(void *buf_priv); | 86 | struct dma_buf *(*get_dmabuf)(void *buf_priv); |
85 | 87 | ||
@@ -302,6 +304,9 @@ struct v4l2_fh; | |||
302 | * @buf_struct_size: size of the driver-specific buffer structure; | 304 | * @buf_struct_size: size of the driver-specific buffer structure; |
303 | * "0" indicates the driver doesn't want to use a custom buffer | 305 | * "0" indicates the driver doesn't want to use a custom buffer |
304 | * structure type, so sizeof(struct vb2_buffer) will is used | 306 | * structure type, so sizeof(struct vb2_buffer) will is used |
307 | * @gfp_flags: additional gfp flags used when allocating the buffers. | ||
308 | * Typically this is 0, but it may be e.g. GFP_DMA or __GFP_DMA32 | ||
309 | * to force the buffer allocation to a specific memory zone. | ||
305 | * | 310 | * |
306 | * @memory: current memory type used | 311 | * @memory: current memory type used |
307 | * @bufs: videobuf buffer structures | 312 | * @bufs: videobuf buffer structures |
@@ -327,6 +332,7 @@ struct vb2_queue { | |||
327 | void *drv_priv; | 332 | void *drv_priv; |
328 | unsigned int buf_struct_size; | 333 | unsigned int buf_struct_size; |
329 | u32 timestamp_type; | 334 | u32 timestamp_type; |
335 | gfp_t gfp_flags; | ||
330 | 336 | ||
331 | /* private: internal use only */ | 337 | /* private: internal use only */ |
332 | enum v4l2_memory memory; | 338 | enum v4l2_memory memory; |