From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752236AbcAFHFQ (ORCPT ); Wed, 6 Jan 2016 02:05:16 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:34524 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751989AbcAFHFN (ORCPT ); Wed, 6 Jan 2016 02:05:13 -0500 X-AuditID: cbfee68d-f79646d000001355-81-568cbca6ac13 From: Rohit kumar To: gregkh@linuxfoundation.org, arve@android.com, riandrews@android.com, labbott@redhat.com, dan.carpenter@oracle.com, gioh.kim@lge.com, sumit.semwal@linaro.org, mitchelh@codeaurora.org, paul.gortmaker@windriver.com, linux@rasmusvillemoes.dk, shawn.lin@rock-chips.com, sriram@marirs.net.in, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, pintu.k@samsung.com, rohit.kr@samsung.com, vishnu.ps@samsung.com Cc: sreenathd@samsung.com, pintu_agarwal@yahoo.com, me.rohit@live.com, cpgs@samsung.com Subject: [PATCHv2 1/1] staging/ion: Add support to get ion handle from dma buf Date: Wed, 06 Jan 2016 12:41:09 +0530 Message-id: <1452064269-18601-1-git-send-email-rohit.kr@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1451998982-15654-1-git-send-email-rohit.kr@samsung.com> References: <1451998982-15654-1-git-send-email-rohit.kr@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAy1Sa0hTYRj2O+d4dhSlw3T6tVRsUFnhymtfJNYPwyOFhIGgCLbWScXb2FSs IEwxbDfUhGB5icRSU1YHG6JL11E00kDwmrdQyxJTkS0tc9rm+vfwXN73gfelcOEYIaay8gpY ZZ4sR0J6Em2+kXdDX5i1yWfrLAFow/6FRCv8SbS694RA5uEdAVoutQFU1mgkUYv5N4ZGu2pJ tGSoJ9Hk/EXU3mAi0cS7QRzpt/sEaGttRoBWOTtA38vKCTT71eiONEtlBKrrt5Lo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7+B453hTMwND XUNLC3MlhbzE3FRbJRefAF23zBxgCCgplCXmlAKFAhKLi5X07TBNCA1x07WAaYzQ9Q0Jgusx MkADCWsYM1ZfP8Zc0KVU8ffdb6YGxokyXYycHBICJhI3e7+yQNhiEhfurWfrYuTiEBJYyigx /8IEKKeJSWLTkUlMIFVsAhoSBw59YQJJiAisZJbY8PEbO0iCWSBS4mHnZ2YQW1jAT+JRRw9Y nEVAVeLq1cVgNq+Ai8SeHWuBpnIArVOQmDPJBiTMKeAq8e7NI2aQsBBQybOVnBMYeRcwMqxi lEgtSC4oTkrPNcpLLdcrTswtLs1L10vOz93ECE4fz6R3MB7e5X6IUYCDUYmHV0CmJ0yINbGs uDL3EKMEB7OSCG9IMVCINyWxsiq1KD++qDQntfgQoynQWROZpUST84GpLa8k3tDYxNzU2NTS xMLEzFJJnHffpcgwIYH0xJLU7NTUgtQimD4mDk6pBsYNfgqe/4Mzmn/0sBdbBlRMVf7NVm42 a1r6tV1vT15ZNmftk65z2nP73+zlsY6ZvT7P+axrr63MNINYbn6+U+UFoqv/nPXYv6OUf55w 3b9LqmLnr65v+dDPbB50XTQ4VMJrk0/17BeTdy26deXttQ3nbberHU+Pbs3tObzg60xXfssb uZfTKqcrsRRnJBpqMRcVJwIA2mDhDzUDAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we can only import dma buf fd's to get ion_handle. Adding support to import dma buf handles to support kernel specific use cases. An example use case is in linux platforms such as Tizen, in which DRM-GEM is used for buffer management for graphics. It has gem_handle corresponding to a buffer and uses gem_name for sharing the buffer with other processes. However,it also uses dma_buf fd for 3d operations. For wayland, there are multiple calls for gem_handle to dma_buf fd conversion. So, we store dma_buf associated with buffer. But, there is no api for getting ion_handle from dma_buf. This patch exposes api to retrieve the ion handle from dma_buf for similar use cases. With this patch, we can integrate ION within DRM-GEM for buffer management and dma_buf sharing. Signed-off-by: Rohit kumar --- v2: Updated commit message with use case explanation, as suggested by Laura Abbott drivers/staging/android/ion/ion.c | 21 +++++++++++++++------ drivers/staging/android/ion/ion.h | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index e237e9f..5509716 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -1151,16 +1151,13 @@ int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle) } EXPORT_SYMBOL(ion_share_dma_buf_fd); -struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd) +struct ion_handle *ion_import_dma_buf(struct ion_client *client, + struct dma_buf *dmabuf) { - struct dma_buf *dmabuf; struct ion_buffer *buffer; struct ion_handle *handle; int ret; - dmabuf = dma_buf_get(fd); - if (IS_ERR(dmabuf)) - return ERR_CAST(dmabuf); /* if this memory came from ion */ if (dmabuf->ops != &dma_buf_ops) { @@ -1199,6 +1196,18 @@ end: } EXPORT_SYMBOL(ion_import_dma_buf); +struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd) +{ + struct dma_buf *dmabuf; + + dmabuf = dma_buf_get(fd); + if (IS_ERR(dmabuf)) + return ERR_CAST(dmabuf); + + return ion_import_dma_buf(client, dmabuf); +} +EXPORT_SYMBOL(ion_import_dma_buf_fd); + static int ion_sync_for_device(struct ion_client *client, int fd) { struct dma_buf *dmabuf; @@ -1306,7 +1315,7 @@ static long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { struct ion_handle *handle; - handle = ion_import_dma_buf(client, data.fd.fd); + handle = ion_import_dma_buf_fd(client, data.fd.fd); if (IS_ERR(handle)) ret = PTR_ERR(handle); else diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index b860c5f..a1331fc 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -192,14 +192,26 @@ struct dma_buf *ion_share_dma_buf(struct ion_client *client, int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle); /** - * ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle + * ion_import_dma_buf() - get ion_handle from dma-buf + * @client: the client + * @dmabuf: the dma-buf + * + * Get the ion_buffer associated with the dma-buf and return the ion_handle. + * If no ion_handle exists for this buffer, return newly created ion_handle. + * If dma-buf from another exporter is passed, return ERR_PTR(-EINVAL) + */ +struct ion_handle *ion_import_dma_buf(struct ion_client *client, + struct dma_buf *dmabuf); + +/** + * ion_import_dma_buf_fd() - given a dma-buf fd from the ion exporter get handle * @client: the client * @fd: the dma-buf fd * - * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf, - * import that fd and return a handle representing it. If a dma-buf from + * Given an dma-buf fd that was allocated through ion via ion_share_dma_buf_fd, + * import that fd and return a handle representing it. If a dma-buf from * another exporter is passed in this function will return ERR_PTR(-EINVAL) */ -struct ion_handle *ion_import_dma_buf(struct ion_client *client, int fd); +struct ion_handle *ion_import_dma_buf_fd(struct ion_client *client, int fd); #endif /* _LINUX_ION_H */ -- 1.7.9.5