public inbox for linux-rockchip@lists.infradead.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Jianqun Xu <jay.xu@rock-chips.com>, sumit.semwal@linaro.org
Cc: pekka.paalanen@collabora.com, daniel.vetter@ffwll.ch,
	jason@jlekstrand.net, linux-media@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
	linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org
Subject: Re: [PATCH] dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support
Date: Mon, 15 Nov 2021 12:42:13 +0100	[thread overview]
Message-ID: <1da5cdf0-ccb8-3740-cf96-794c4d5b2eb4@amd.com> (raw)
In-Reply-To: <20211113062222.3743909-1-jay.xu@rock-chips.com>

Am 13.11.21 um 07:22 schrieb Jianqun Xu:
> Add DMA_BUF_IOCTL_SYNC_PARTIAL support for user to sync dma-buf with
> offset and len.

You have not given an use case for this so it is a bit hard to review. 
And from the existing use cases I don't see why this should be necessary.

Even worse from the existing backend implementation I don't even see how 
drivers should be able to fulfill this semantics.

Please explain further,
Christian.

>
> Change-Id: I03d2d2e10e48d32aa83c31abade57e0931e1be49
> Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
> ---
>   drivers/dma-buf/dma-buf.c    | 42 ++++++++++++++++++++++++++++++++++++
>   include/uapi/linux/dma-buf.h |  8 +++++++
>   2 files changed, 50 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index d9948d58b3f4..78f37f7c3462 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -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;
>   	}
> diff --git a/include/uapi/linux/dma-buf.h b/include/uapi/linux/dma-buf.h
> index 7f30393b92c3..6236c644624d 100644
> --- a/include/uapi/linux/dma-buf.h
> +++ b/include/uapi/linux/dma-buf.h
> @@ -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


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

  reply	other threads:[~2021-11-15 11:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-13  6:22 [PATCH] dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support Jianqun Xu
2021-11-15 11:42 ` Christian König [this message]
2024-04-07  7:50   ` Rong Qianfeng
2024-04-08  7:58     ` Christian König
2024-04-09  7:32       ` Rong Qianfeng
2024-04-09 15:34         ` Christian König
2024-04-10  7:09           ` Rong Qianfeng
2024-04-09 16:37         ` T.J. Mercier
2024-04-10 14:22           ` Christian König
2024-04-10 15:07             ` T.J. Mercier
2024-04-11  8:43               ` Rong Qianfeng
2024-04-11 10:08               ` Christian König
2024-04-11  8:21           ` Rong Qianfeng
2024-04-11 16:52             ` T.J. Mercier
2024-04-12  7:46               ` Rong Qianfeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1da5cdf0-ccb8-3740-cf96-794c4d5b2eb4@amd.com \
    --to=christian.koenig@amd.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jason@jlekstrand.net \
    --cc=jay.xu@rock-chips.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=pekka.paalanen@collabora.com \
    --cc=sumit.semwal@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox