Re: [RFCv6 PATCH 02/16] vb2: replace 'write' by 'dma_dir'

2014-11-16 Thread Pawel Osciak
On Mon, Nov 10, 2014 at 8:49 PM, Hans Verkuil  wrote:
> From: Hans Verkuil 
>
> The 'write' argument is very ambiguous. I first assumed that if it is 1,
> then we're doing video output but instead it meant the reverse.
>
> Since it is used to setup the dma_dir value anyway it is now replaced by
> the correct dma_dir value which is unambiguous.
>
> Signed-off-by: Hans Verkuil 

Acked-by: Pawel Osciak 

-- 
Best regards,
Pawel Osciak
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv6 PATCH 02/16] vb2: replace 'write' by 'dma_dir'

2014-11-10 Thread Hans Verkuil
From: Hans Verkuil 

The 'write' argument is very ambiguous. I first assumed that if it is 1,
then we're doing video output but instead it meant the reverse.

Since it is used to setup the dma_dir value anyway it is now replaced by
the correct dma_dir value which is unambiguous.

Signed-off-by: Hans Verkuil 
---
 drivers/media/v4l2-core/videobuf2-core.c   | 10 ---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 40 ++
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 13 +
 drivers/media/v4l2-core/videobuf2-vmalloc.c| 16 ++-
 include/media/videobuf2-core.h |  6 ++--
 5 files changed, 47 insertions(+), 38 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index f2e43de..573f6fb 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1358,7 +1358,8 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
void *mem_priv;
unsigned int plane;
int ret;
-   int write = !V4L2_TYPE_IS_OUTPUT(q->type);
+   enum dma_data_direction dma_dir =
+   V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
bool reacquired = vb->planes[0].mem_priv == NULL;
 
memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
@@ -1400,7 +1401,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
/* Acquire each plane's memory */
mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane],
  planes[plane].m.userptr,
- planes[plane].length, write);
+ planes[plane].length, dma_dir);
if (IS_ERR_OR_NULL(mem_priv)) {
dprintk(1, "failed acquiring userspace "
"memory for plane %d\n", plane);
@@ -1461,7 +1462,8 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
void *mem_priv;
unsigned int plane;
int ret;
-   int write = !V4L2_TYPE_IS_OUTPUT(q->type);
+   enum dma_data_direction dma_dir =
+   V4L2_TYPE_IS_OUTPUT(q->type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
bool reacquired = vb->planes[0].mem_priv == NULL;
 
memset(planes, 0, sizeof(planes[0]) * vb->num_planes);
@@ -1509,7 +1511,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
 
/* Acquire each plane's memory */
mem_priv = call_ptr_memop(vb, attach_dmabuf, 
q->alloc_ctx[plane],
-   dbuf, planes[plane].length, write);
+   dbuf, planes[plane].length, dma_dir);
if (IS_ERR(mem_priv)) {
dprintk(1, "failed to attach dmabuf\n");
ret = PTR_ERR(mem_priv);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 4a02ade..2bdffd3 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -229,7 +229,7 @@ static int vb2_dc_mmap(void *buf_priv, struct 
vm_area_struct *vma)
 
 struct vb2_dc_attachment {
struct sg_table sgt;
-   enum dma_data_direction dir;
+   enum dma_data_direction dma_dir;
 };
 
 static int vb2_dc_dmabuf_ops_attach(struct dma_buf *dbuf, struct device *dev,
@@ -264,7 +264,7 @@ static int vb2_dc_dmabuf_ops_attach(struct dma_buf *dbuf, 
struct device *dev,
wr = sg_next(wr);
}
 
-   attach->dir = DMA_NONE;
+   attach->dma_dir = DMA_NONE;
dbuf_attach->priv = attach;
 
return 0;
@@ -282,16 +282,16 @@ static void vb2_dc_dmabuf_ops_detach(struct dma_buf *dbuf,
sgt = &attach->sgt;
 
/* release the scatterlist cache */
-   if (attach->dir != DMA_NONE)
+   if (attach->dma_dir != DMA_NONE)
dma_unmap_sg(db_attach->dev, sgt->sgl, sgt->orig_nents,
-   attach->dir);
+   attach->dma_dir);
sg_free_table(sgt);
kfree(attach);
db_attach->priv = NULL;
 }
 
 static struct sg_table *vb2_dc_dmabuf_ops_map(
-   struct dma_buf_attachment *db_attach, enum dma_data_direction dir)
+   struct dma_buf_attachment *db_attach, enum dma_data_direction dma_dir)
 {
struct vb2_dc_attachment *attach = db_attach->priv;
/* stealing dmabuf mutex to serialize map/unmap operations */
@@ -303,27 +303,27 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
 
sgt = &attach->sgt;
/* return previously mapped sg table */
-   if (attach->dir == dir) {
+   if (attach->dma_dir == dma_dir) {
mutex_unlock(lock);
return sgt;
}
 
/* release any previous cache */
-   if (attach->dir != DMA_NONE) {
+