From patchwork Wed Dec 19 17:19:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Tao X-Patchwork-Id: 154246 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4708118ljp; Wed, 19 Dec 2018 01:16:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/UK+NiZt1Byd/WXD3kDUjmS6dhGyfJUrpYCbjjDZt2Ja6Yif3Quluf2yJWOpR4W3L+ijiCR X-Received: by 2002:a63:fe0a:: with SMTP id p10mr18528219pgh.265.1545210965951; Wed, 19 Dec 2018 01:16:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545210965; cv=none; d=google.com; s=arc-20160816; b=G6wRb8K6y84TNtMZ3b5MIHuWA+uSFJGB/3EqoE82nHKqxz66JtgguCeAEUnPXLydFn Q7eAM5o42h1e3/N+Kyn2k4uqjYuwNG0uVKliEcRkdpD00DpGtppCLG4aLKZjLafcaeR2 Xj9E4/ySstBRsp0oQwpg/HTIzckT6ME/eJClX2WVUKmQWxXUqONNxhvE46Yu6Erm+VrA 804rtU02wzHi98j34pJ+gYAhOJXsigcXwmGLb3k6Uh7cvOinBlMLDgTFvGXM8LuivA/F Ov12tee2sXYiCYHK0V3mop/+5zqjdOlLuhj+U4CYv4BsA3piBX7vKbJrwM2X3F0A6peo FNIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=099fMVNgFA28jDvIXF53rmpeKd2XtqzvC3KKahRHv0U=; b=l+dc8HAI0kXpi69Ok6K0JfvN2JbE3nHEHpRXA49moCNE0tj4TBZhIChON8ZWb8Y7X6 l6ZsAciTtrs/k3RTt+gppROg1BzLm/xyr2LGbAdnwK18rzdLUmYykh1s9vZYIEnXVOw0 7X0zjk7EsShZprb6AgxbpgKRIIKn0b7tin99XdPkE67nWzZrQn/66GD1sGQ3xvN9nd6V h0cxE5nweN7PjwZlYBxHYbwFM/FSdLp6QD+FWg3NOkyQjKeQ3BmsUBCfM1N9rBGc6P4m QowUSzKwpERQj3yhdTPYrY3hfGqlpkyp5PqYEgxLOW922TCek5hzkaNdun065N83x3NY l5hA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w75si16117198pfd.55.2018.12.19.01.16.05; Wed, 19 Dec 2018 01:16:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728199AbeLSJQE (ORCPT + 31 others); Wed, 19 Dec 2018 04:16:04 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:41071 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727159AbeLSJQE (ORCPT ); Wed, 19 Dec 2018 04:16:04 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A55518862400A; Wed, 19 Dec 2018 17:16:00 +0800 (CST) Received: from dessert.huawei.com (10.69.192.158) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Wed, 19 Dec 2018 17:15:53 +0800 From: Zeng Tao To: , CC: Zeng Tao , Greg Kroah-Hartman , =?utf-8?q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , , , , Subject: [PATCH] staging: android: ion: add buffer flag update ioctl Date: Thu, 20 Dec 2018 01:19:03 +0800 Message-ID: <1545239943-15414-1-git-send-email-prime.zeng@hisilicon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.69.192.158] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In some usecases, the buffer cached attribute is not determined at allocation time, it's determined just before the real cpu mapping. And from the memory view of point, a buffer should not have the cached attribute util is really mapped by the cpu. So in this patch, we introduced the new ioctl command to target the requirement. Signed-off-by: Zeng Tao --- drivers/staging/android/ion/ion-ioctl.c | 4 ++++ drivers/staging/android/ion/ion.c | 17 +++++++++++++++++ drivers/staging/android/ion/ion.h | 1 + drivers/staging/android/uapi/ion.h | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+) -- 2.7.4 diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index a8d3cc4..60bb702 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -12,6 +12,7 @@ union ion_ioctl_arg { struct ion_allocation_data allocation; + struct ion_buffer_flag_data update; struct ion_heap_query query; }; @@ -83,6 +84,9 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) break; } + case ION_IOC_BUFFER_UPDATE: + ret = ion_buffer_update(data.update.fd, data.update.flags); + break; case ION_IOC_HEAP_QUERY: ret = ion_query_heaps(&data.query); break; diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 9907332..f1404dc 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -436,6 +436,23 @@ int ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags) return fd; } +int ion_buffer_update(unsigned int fd, unsigned int flags) +{ + struct dma_buf *dmabuf; + struct ion_buffer *buffer; + + dmabuf = dma_buf_get(fd); + + if (!dmabuf) + return -EINVAL; + + buffer = dmabuf->priv; + buffer->flags = flags; + dma_buf_put(dmabuf); + + return 0; +} + int ion_query_heaps(struct ion_heap_query *query) { struct ion_device *dev = internal_dev; diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index c006fc1..99bf9ab 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -199,6 +199,7 @@ int ion_heap_pages_zero(struct page *page, size_t size, pgprot_t pgprot); int ion_alloc(size_t len, unsigned int heap_id_mask, unsigned int flags); +int ion_buffer_update(unsigned int fd, unsigned int flags); /** * ion_heap_init_shrinker diff --git a/drivers/staging/android/uapi/ion.h b/drivers/staging/android/uapi/ion.h index 5d70098..99753fc 100644 --- a/drivers/staging/android/uapi/ion.h +++ b/drivers/staging/android/uapi/ion.h @@ -74,6 +74,20 @@ struct ion_allocation_data { __u32 unused; }; +/** + * struct ion_buffer_flag_data - metadata passed from userspace for update + * buffer flags + * @fd: file descriptor of the buffer + * @flags: flags passed to the buffer + * + * Provided by userspace as an argument to the ioctl + */ + +struct ion_buffer_flag_data { + __u32 fd; + __u32 flags; +} + #define MAX_HEAP_NAME 32 /** @@ -116,6 +130,14 @@ struct ion_heap_query { struct ion_allocation_data) /** + * DOC: ION_IOC_BUFFER_UPDATE - update the specified ion buffer flags + * + * Takes an ion_buffer_flag_data structure and returns the result of the + * buffer flag update operation. + */ +#define ION_IOC_BUFFER_UPDATE _IOWR(ION_IOC_MAGIC, 1, \ + struct ion_buffer_flag_data) +/** * DOC: ION_IOC_HEAP_QUERY - information about available heaps * * Takes an ion_heap_query structure and populates information about