[media] vivid: support for contiguous DMA buffers

It allows to simulate the behavior of hardware with such limitations or
to connect vivid to real hardware with such limitations.

Add the "allocators" module parameter option to let vivid use the
dma-contig instead of vmalloc.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Vincent Abriou <vincent.abriou@st.com>
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Tested-by: Javier Martinez Canillas <javier@osg.samsung.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
This commit is contained in:
Vincent ABRIOU 2016-09-12 05:47:27 -03:00 committed by Mauro Carvalho Chehab
parent 93d4a26c3d
commit 8ecc54138a
3 changed files with 37 additions and 5 deletions

View File

@ -263,6 +263,14 @@ all configurable using the following module options:
removed. Unless overridden by ccs_cap_mode and/or ccs_out_mode the removed. Unless overridden by ccs_cap_mode and/or ccs_out_mode the
will default to enabling crop, compose and scaling. will default to enabling crop, compose and scaling.
- allocators:
memory allocator selection, default is 0. It specifies the way buffers
will be allocated.
- 0: vmalloc
- 1: dma-contig
Taken together, all these module options allow you to precisely customize Taken together, all these module options allow you to precisely customize
the driver behavior and test your application with all sorts of permutations. the driver behavior and test your application with all sorts of permutations.
It is also very suitable to emulate hardware that is not yet available, e.g. It is also very suitable to emulate hardware that is not yet available, e.g.

View File

@ -1,6 +1,7 @@
config VIDEO_VIVID config VIDEO_VIVID
tristate "Virtual Video Test Driver" tristate "Virtual Video Test Driver"
depends on VIDEO_DEV && VIDEO_V4L2 && !SPARC32 && !SPARC64 && FB depends on VIDEO_DEV && VIDEO_V4L2 && !SPARC32 && !SPARC64 && FB
depends on HAS_DMA
select FONT_SUPPORT select FONT_SUPPORT
select FONT_8x16 select FONT_8x16
select FB_CFB_FILLRECT select FB_CFB_FILLRECT
@ -8,6 +9,7 @@ config VIDEO_VIVID
select FB_CFB_IMAGEBLIT select FB_CFB_IMAGEBLIT
select MEDIA_CEC_EDID select MEDIA_CEC_EDID
select VIDEOBUF2_VMALLOC select VIDEOBUF2_VMALLOC
select VIDEOBUF2_DMA_CONTIG
select VIDEO_V4L2_TPG select VIDEO_V4L2_TPG
default n default n
---help--- ---help---

View File

@ -30,6 +30,7 @@
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <linux/v4l2-dv-timings.h> #include <linux/v4l2-dv-timings.h>
#include <media/videobuf2-vmalloc.h> #include <media/videobuf2-vmalloc.h>
#include <media/videobuf2-dma-contig.h>
#include <media/v4l2-dv-timings.h> #include <media/v4l2-dv-timings.h>
#include <media/v4l2-ioctl.h> #include <media/v4l2-ioctl.h>
#include <media/v4l2-fh.h> #include <media/v4l2-fh.h>
@ -151,6 +152,12 @@ static bool no_error_inj;
module_param(no_error_inj, bool, 0444); module_param(no_error_inj, bool, 0444);
MODULE_PARM_DESC(no_error_inj, " if set disable the error injecting controls"); MODULE_PARM_DESC(no_error_inj, " if set disable the error injecting controls");
static unsigned int allocators[VIVID_MAX_DEVS] = { [0 ... (VIVID_MAX_DEVS - 1)] = 0 };
module_param_array(allocators, uint, NULL, 0444);
MODULE_PARM_DESC(allocators, " memory allocator selection, default is 0.\n"
"\t\t 0 == vmalloc\n"
"\t\t 1 == dma-contig");
static struct vivid_dev *vivid_devs[VIVID_MAX_DEVS]; static struct vivid_dev *vivid_devs[VIVID_MAX_DEVS];
const struct v4l2_rect vivid_min_rect = { const struct v4l2_rect vivid_min_rect = {
@ -636,6 +643,10 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
{ {
static const struct v4l2_dv_timings def_dv_timings = static const struct v4l2_dv_timings def_dv_timings =
V4L2_DV_BT_CEA_1280X720P60; V4L2_DV_BT_CEA_1280X720P60;
static const struct vb2_mem_ops * const vivid_mem_ops[2] = {
&vb2_vmalloc_memops,
&vb2_dma_contig_memops,
};
unsigned in_type_counter[4] = { 0, 0, 0, 0 }; unsigned in_type_counter[4] = { 0, 0, 0, 0 };
unsigned out_type_counter[4] = { 0, 0, 0, 0 }; unsigned out_type_counter[4] = { 0, 0, 0, 0 };
int ccs_cap = ccs_cap_mode[inst]; int ccs_cap = ccs_cap_mode[inst];
@ -646,6 +657,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
struct video_device *vfd; struct video_device *vfd;
struct vb2_queue *q; struct vb2_queue *q;
unsigned node_type = node_types[inst]; unsigned node_type = node_types[inst];
unsigned int allocator = allocators[inst];
v4l2_std_id tvnorms_cap = 0, tvnorms_out = 0; v4l2_std_id tvnorms_cap = 0, tvnorms_out = 0;
int ret; int ret;
int i; int i;
@ -1039,6 +1051,11 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
goto unreg_dev; goto unreg_dev;
} }
if (allocator == 1)
dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
else if (allocator >= ARRAY_SIZE(vivid_mem_ops))
allocator = 0;
/* start creating the vb2 queues */ /* start creating the vb2 queues */
if (dev->has_vid_cap) { if (dev->has_vid_cap) {
/* initialize vid_cap queue */ /* initialize vid_cap queue */
@ -1049,10 +1066,11 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
q->drv_priv = dev; q->drv_priv = dev;
q->buf_struct_size = sizeof(struct vivid_buffer); q->buf_struct_size = sizeof(struct vivid_buffer);
q->ops = &vivid_vid_cap_qops; q->ops = &vivid_vid_cap_qops;
q->mem_ops = &vb2_vmalloc_memops; q->mem_ops = vivid_mem_ops[allocator];
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->min_buffers_needed = 2; q->min_buffers_needed = 2;
q->lock = &dev->mutex; q->lock = &dev->mutex;
q->dev = dev->v4l2_dev.dev;
ret = vb2_queue_init(q); ret = vb2_queue_init(q);
if (ret) if (ret)
@ -1068,10 +1086,11 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
q->drv_priv = dev; q->drv_priv = dev;
q->buf_struct_size = sizeof(struct vivid_buffer); q->buf_struct_size = sizeof(struct vivid_buffer);
q->ops = &vivid_vid_out_qops; q->ops = &vivid_vid_out_qops;
q->mem_ops = &vb2_vmalloc_memops; q->mem_ops = vivid_mem_ops[allocator];
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->min_buffers_needed = 2; q->min_buffers_needed = 2;
q->lock = &dev->mutex; q->lock = &dev->mutex;
q->dev = dev->v4l2_dev.dev;
ret = vb2_queue_init(q); ret = vb2_queue_init(q);
if (ret) if (ret)
@ -1087,10 +1106,11 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
q->drv_priv = dev; q->drv_priv = dev;
q->buf_struct_size = sizeof(struct vivid_buffer); q->buf_struct_size = sizeof(struct vivid_buffer);
q->ops = &vivid_vbi_cap_qops; q->ops = &vivid_vbi_cap_qops;
q->mem_ops = &vb2_vmalloc_memops; q->mem_ops = vivid_mem_ops[allocator];
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->min_buffers_needed = 2; q->min_buffers_needed = 2;
q->lock = &dev->mutex; q->lock = &dev->mutex;
q->dev = dev->v4l2_dev.dev;
ret = vb2_queue_init(q); ret = vb2_queue_init(q);
if (ret) if (ret)
@ -1106,10 +1126,11 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
q->drv_priv = dev; q->drv_priv = dev;
q->buf_struct_size = sizeof(struct vivid_buffer); q->buf_struct_size = sizeof(struct vivid_buffer);
q->ops = &vivid_vbi_out_qops; q->ops = &vivid_vbi_out_qops;
q->mem_ops = &vb2_vmalloc_memops; q->mem_ops = vivid_mem_ops[allocator];
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->min_buffers_needed = 2; q->min_buffers_needed = 2;
q->lock = &dev->mutex; q->lock = &dev->mutex;
q->dev = dev->v4l2_dev.dev;
ret = vb2_queue_init(q); ret = vb2_queue_init(q);
if (ret) if (ret)
@ -1124,10 +1145,11 @@ static int vivid_create_instance(struct platform_device *pdev, int inst)
q->drv_priv = dev; q->drv_priv = dev;
q->buf_struct_size = sizeof(struct vivid_buffer); q->buf_struct_size = sizeof(struct vivid_buffer);
q->ops = &vivid_sdr_cap_qops; q->ops = &vivid_sdr_cap_qops;
q->mem_ops = &vb2_vmalloc_memops; q->mem_ops = vivid_mem_ops[allocator];
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->min_buffers_needed = 8; q->min_buffers_needed = 8;
q->lock = &dev->mutex; q->lock = &dev->mutex;
q->dev = dev->v4l2_dev.dev;
ret = vb2_queue_init(q); ret = vb2_queue_init(q);
if (ret) if (ret)