From patchwork Sat Nov 13 06:22:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianqun Xu X-Patchwork-Id: 12617607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF6E9C4332F for ; Sat, 13 Nov 2021 06:22:32 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0BCD960F22 for ; Sat, 13 Nov 2021 06:22:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0BCD960F22 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=rock-chips.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5142A6EDE5; Sat, 13 Nov 2021 06:22:31 +0000 (UTC) Received: from lucky1.263xmail.com (lucky1.263xmail.com [211.157.147.135]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0B2D96EDE4 for ; Sat, 13 Nov 2021 06:22:29 +0000 (UTC) Received: from localhost (unknown [192.168.167.130]) by lucky1.263xmail.com (Postfix) with ESMTP id C7C38B3BB5; Sat, 13 Nov 2021 14:22:24 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (postfix) whith ESMTP id P7913T140599548167936S1636784543589160_; Sat, 13 Nov 2021 14:22:24 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: jay.xu@rock-chips.com X-SENDER: xjq@rock-chips.com X-LOGIN-NAME: jay.xu@rock-chips.com X-FST-TO: sumit.semwal@linaro.org X-RCPT-COUNT: 11 X-LOCAL-RCPT-COUNT: 1 X-SENDER-IP: 58.22.7.114 X-ATTACHMENT-NUM: 0 X-UNIQUE-TAG: X-System-Flag: 0 From: Jianqun Xu To: sumit.semwal@linaro.org, christian.koenig@amd.com Subject: [PATCH] dma-buf: add DMA_BUF_IOCTL_SYNC_PARTIAL support Date: Sat, 13 Nov 2021 14:22:22 +0800 Message-Id: <20211113062222.3743909-1-jay.xu@rock-chips.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pekka.paalanen@collabora.com, daniel.vetter@ffwll.ch, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-rockchip@lists.infradead.org, jason@jlekstrand.net, Jianqun Xu , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- 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