dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support

Add DMA_BUF_IOCTL_SYNC_PARTIAL support for user to sync dma-buf with
offset and len.

Change-Id: I03d2d2e10e48d32aa83c31abade57e0931e1be49
Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
This commit is contained in:
Jianqun Xu
2021-11-13 12:51:57 +08:00
committed by Tao Huang
parent 5057b5e32d
commit 1aef8d5550
2 changed files with 50 additions and 0 deletions

View File

@@ -392,6 +392,7 @@ static long dma_buf_ioctl(struct file *file,
{
struct dma_buf *dmabuf;
struct dma_buf_sync sync;
struct dma_buf_sync_partial sync_p;
enum dma_data_direction direction;
int ret;
@@ -430,6 +431,47 @@ static long dma_buf_ioctl(struct file *file,
case DMA_BUF_SET_NAME_B:
return dma_buf_set_name(dmabuf, (const char __user *)arg);
case DMA_BUF_IOCTL_SYNC_PARTIAL:
if (copy_from_user(&sync_p, (void __user *) arg, sizeof(sync_p)))
return -EFAULT;
if (sync_p.len == 0)
return 0;
if ((sync_p.offset % cache_line_size()) || (sync_p.len % cache_line_size()))
return -EINVAL;
if (sync_p.len > dmabuf->size || sync_p.offset > dmabuf->size - sync_p.len)
return -EINVAL;
if (sync_p.flags & ~DMA_BUF_SYNC_VALID_FLAGS_MASK)
return -EINVAL;
switch (sync_p.flags & DMA_BUF_SYNC_RW) {
case DMA_BUF_SYNC_READ:
direction = DMA_FROM_DEVICE;
break;
case DMA_BUF_SYNC_WRITE:
direction = DMA_TO_DEVICE;
break;
case DMA_BUF_SYNC_RW:
direction = DMA_BIDIRECTIONAL;
break;
default:
return -EINVAL;
}
if (sync_p.flags & DMA_BUF_SYNC_END)
ret = dma_buf_end_cpu_access_partial(dmabuf, direction,
sync_p.offset,
sync_p.len);
else
ret = dma_buf_begin_cpu_access_partial(dmabuf, direction,
sync_p.offset,
sync_p.len);
return ret;
default:
return -ENOTTY;
}

View File

@@ -47,4 +47,12 @@ struct dma_buf_sync {
#define DMA_BUF_SET_NAME_A _IOW(DMA_BUF_BASE, 1, u32)
#define DMA_BUF_SET_NAME_B _IOW(DMA_BUF_BASE, 1, u64)
struct dma_buf_sync_partial {
__u64 flags;
__u32 offset;
__u32 len;
};
#define DMA_BUF_IOCTL_SYNC_PARTIAL _IOW(DMA_BUF_BASE, 2, struct dma_buf_sync_partial)
#endif